X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxml%2FXMLSchema.java;h=4127a106eae6deb7744b7f5311b90150f74c9328;hb=3205980513232d44b49681aced7cd7f124a4d1a0;hp=956de70116556a3559a6855e19e2011d122edfe9;hpb=f5eb4cf69aae34ac7d9fe2384cfc02b643a96c6f;p=utils diff --git a/support/general/src/main/java/org/wamblee/xml/XMLSchema.java b/support/general/src/main/java/org/wamblee/xml/XMLSchema.java index 956de701..4127a106 100644 --- a/support/general/src/main/java/org/wamblee/xml/XMLSchema.java +++ b/support/general/src/main/java/org/wamblee/xml/XMLSchema.java @@ -29,11 +29,12 @@ import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import org.w3c.dom.Document; +import org.w3c.dom.ls.LSInput; import org.w3c.dom.ls.LSResourceResolver; import org.xml.sax.SAXException; /** - * Represents an XML Schema. + * Represents an XML Schema. * * @author Erik Brakkee */ @@ -52,12 +53,20 @@ public class XMLSchema implements XMLProcessor { } } - public XMLSchema(String aSystemId, InputStream aIs, LSResourceResolver aResolver) throws XMLException { - initialize(aSystemId, aIs, aResolver); + public XMLSchema(String aSystemId, LSResourceResolver aResolver) + throws XMLException { + LSInput input = aResolver.resolveResource(null, null, null, aSystemId, + null); + if (input == null) { + throw new XMLException("Schema classpath resource '" + aSystemId + + "' not found"); + } + InputStream is = input.getByteStream(); + initialize(aSystemId, is, aResolver); } - private void initialize(String aSystemId, InputStream aIs, LSResourceResolver aResolver) - throws XMLException { + private void initialize(String aSystemId, InputStream aIs, + LSResourceResolver aResolver) throws XMLException { try { SchemaFactory factory = SchemaFactory .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); @@ -77,11 +86,12 @@ public class XMLSchema implements XMLProcessor { return new XMLSchema(aUri); } - public static XMLSchema schema(String aSystemId, InputStream aIs, LSResourceResolver aResolver) throws XMLException { - return new XMLSchema(aSystemId, aIs, aResolver); + public static XMLSchema schema(String aSystemId, + LSResourceResolver aResolver) throws XMLException { + return new XMLSchema(aSystemId, aResolver); } - - private void validateImpl(DOMSource aDoc) throws XMLException { + + private void validateImpl(DOMSource aDoc) throws XMLException { try { validator.validate(aDoc); } catch (SAXException e) { @@ -101,7 +111,7 @@ public class XMLSchema implements XMLProcessor { @Override public DOMSource process(DOMSource aDocument) throws XMLException { - validate(aDocument); + validate(aDocument); return aDocument; }