Implement issue #704 and enable multi-schema validation

This commit is contained in:
Hans Aikema
2017-09-17 15:30:48 +02:00
parent ae50b01318
commit 67aa59c4b8
11 changed files with 658 additions and 84 deletions

View File

@@ -61,7 +61,7 @@ public final class XmlUtils {
/**
* Constructs a validating secure SAX Parser.
*
* @param schemaStream the schema to validate the XML against
* @param schemaStream One or more inputStreams with the schema(s) that the parser should be able to validate the XML against, one InputStream per schema
* @return a SAX Parser
* @throws ParserConfigurationException is thrown if there is a parser
* configuration exception
@@ -71,7 +71,7 @@ public final class XmlUtils {
* feature
* @throws SAXException is thrown if there is a SAXException
*/
public static SAXParser buildSecureSaxParser(InputStream schemaStream) throws ParserConfigurationException,
public static SAXParser buildSecureSaxParser(InputStream... schemaStream) throws ParserConfigurationException,
SAXNotRecognizedException, SAXNotSupportedException, SAXException {
final SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
@@ -87,6 +87,32 @@ public final class XmlUtils {
return saxParser;
}
/**
* Converts an attribute value representing an xsd:boolean value to a boolean using
* the rules as stated in the XML specification
*
* @param lexicalXSDBoolean The string-value of the boolean
* @return the boolean value represented by {@code lexicalXSDBoolean}
* @throws IllegalArgumentException When {@code lexicalXSDBoolean} does
* fit the lexical space of the XSD boolean datatype
*/
public static boolean parseBoolean(String lexicalXSDBoolean) {
final boolean result;
switch (lexicalXSDBoolean) {
case "true":
case "1":
result = true;
break;
case "false":
case "0":
result = false;
break;
default:
throw new IllegalArgumentException("'"+lexicalXSDBoolean+"' is not a valid xs:boolean value");
}
return result;
}
/**
* Constructs a secure SAX Parser.
*