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
*/
}
}
- 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);
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) {
@Override
public DOMSource process(DOMSource aDocument) throws XMLException {
- validate(aDocument);
+ validate(aDocument);
return aDocument;
}