Add ParserUtils.parseXmlBoolean(String)

This commit is contained in:
Florian Schmaus 2018-11-29 08:55:10 +01:00
parent b675f49b3d
commit 7ea7f9e2e9
1 changed files with 22 additions and 1 deletions

View File

@ -129,6 +129,27 @@ public class ParserUtils {
return Resourcepart.from(resourcepartString);
}
/**
* Prase a string to a boolean value as per "xs:boolean". Valid input strings are "true", "1" for true, and "false", "0" for false.
*
* @param booleanString the input string.
* @return the boolean representation of the input string
* @throws IllegalArgumentException if the input string is not valid.
* @since 4.3.2
*/
public static boolean parseXmlBoolean(String booleanString) {
switch (booleanString) {
case "true":
case "1":
return true;
case "false":
case "0":
return false;
default:
throw new IllegalArgumentException(booleanString + " is not a valid boolean string");
}
}
/**
* Get the boolean value of an argument.
*
@ -141,7 +162,7 @@ public class ParserUtils {
if (valueString == null)
return null;
valueString = valueString.toLowerCase(Locale.US);
return valueString.equals("true") || valueString.equals("1");
return parseXmlBoolean(valueString);
}
public static boolean getBooleanAttribute(XmlPullParser parser, String name,