Merge "Handle missing and invalid numeric values in XmlUtils."
This commit is contained in:
@ -800,16 +800,8 @@ public class XmlUtils
|
|||||||
}
|
}
|
||||||
throw new XmlPullParserException(
|
throw new XmlPullParserException(
|
||||||
"Unexpected end of document in <string>");
|
"Unexpected end of document in <string>");
|
||||||
} else if (tagName.equals("int")) {
|
} else if ((res = readThisPrimitiveValueXml(parser, tagName)) != null) {
|
||||||
res = Integer.parseInt(parser.getAttributeValue(null, "value"));
|
// all work already done by readThisPrimitiveValueXml
|
||||||
} else if (tagName.equals("long")) {
|
|
||||||
res = Long.valueOf(parser.getAttributeValue(null, "value"));
|
|
||||||
} else if (tagName.equals("float")) {
|
|
||||||
res = new Float(parser.getAttributeValue(null, "value"));
|
|
||||||
} else if (tagName.equals("double")) {
|
|
||||||
res = new Double(parser.getAttributeValue(null, "value"));
|
|
||||||
} else if (tagName.equals("boolean")) {
|
|
||||||
res = Boolean.valueOf(parser.getAttributeValue(null, "value"));
|
|
||||||
} else if (tagName.equals("int-array")) {
|
} else if (tagName.equals("int-array")) {
|
||||||
parser.next();
|
parser.next();
|
||||||
res = readThisIntArrayXml(parser, "int-array", name);
|
res = readThisIntArrayXml(parser, "int-array", name);
|
||||||
@ -862,6 +854,31 @@ public class XmlUtils
|
|||||||
"Unexpected end of document in <" + tagName + ">");
|
"Unexpected end of document in <" + tagName + ">");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Object readThisPrimitiveValueXml(XmlPullParser parser, String tagName)
|
||||||
|
throws XmlPullParserException, java.io.IOException
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (tagName.equals("int")) {
|
||||||
|
return Integer.parseInt(parser.getAttributeValue(null, "value"));
|
||||||
|
} else if (tagName.equals("long")) {
|
||||||
|
return Long.valueOf(parser.getAttributeValue(null, "value"));
|
||||||
|
} else if (tagName.equals("float")) {
|
||||||
|
return new Float(parser.getAttributeValue(null, "value"));
|
||||||
|
} else if (tagName.equals("double")) {
|
||||||
|
return new Double(parser.getAttributeValue(null, "value"));
|
||||||
|
} else if (tagName.equals("boolean")) {
|
||||||
|
return Boolean.valueOf(parser.getAttributeValue(null, "value"));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
throw new XmlPullParserException("Need value attribute in <" + tagName + ">");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new XmlPullParserException(
|
||||||
|
"Not a number in value attribute in <" + tagName + ">");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static final void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException
|
public static final void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException
|
||||||
{
|
{
|
||||||
int type;
|
int type;
|
||||||
|
Reference in New Issue
Block a user