InputSource is = getSchemaInputSource(baseURI, location);
Document document = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder parser = factory.newDocumentBuilder();
document = parser.parse(is);
} catch (ParserConfigurationException ex) {
throw new ConfigurationException(new Message("PARSER_CONFIGURATION_ERROR_EXC",
LOG, location), ex);
} catch (SAXException ex) {
throw new ConfigurationException(new Message("PARSE_ERROR_EXC", LOG), ex);
} catch (IOException ex) {
throw new ConfigurationException(new Message("FILE_OPEN_ERROR_EXC", LOG, location), ex);
}
deserialize(document);
Source src = new DOMSource(document);
src.setSystemId(is.getSystemId());
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final LSResourceResolver oldResolver = factory.getResourceResolver();
LSResourceResolver resolver = new LSResourceResolver() {
public LSInput resolveResource(String type, String nsURI,
String publicId, String systemId, String baseURI) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("resolving resource type: " + type + "\n"
+ " namespaceURI:" + nsURI + "\n"
+ " publicId:" + publicId + "\n"
+ " systemId:" + systemId + "\n"
+ " baseURI:" + baseURI);
}
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(type)) {
LSInput lsi = new SchemaInput(type, nsURI, publicId, systemId, baseURI);
String resourceName = systemId;
InputSource src = getSchemaInputSource(baseURI, resourceName);
lsi.setByteStream(src.getByteStream());
lsi.setSystemId(src.getSystemId());
return lsi;
}
return oldResolver == null ? null
: oldResolver.resolveResource(type, nsURI, publicId, systemId, baseURI);
}
};
factory.setResourceResolver(resolver);
try {
schema = factory.newSchema(src);
} catch (SAXException ex) {
throw new ConfigurationException(new Message("SCHEMA_CREATION_ERROR_EXC", LOG, location), ex);
}
document = null;