public static boolean check(InputSource[] schemas,
ErrorReceiver errorHandler,
final EntityResolver entityResolver,
boolean disableXmlSecurity) {
ErrorReceiverFilter errorFilter = new ErrorReceiverFilter(errorHandler);
boolean hadErrors = false;
SchemaFactory sf = XmlFactory.createSchemaFactory(W3C_XML_SCHEMA_NS_URI, disableXmlSecurity);
XmlFactory.allowExternalAccess(sf, "all", disableXmlSecurity);
sf.setErrorHandler(errorFilter);
if( entityResolver != null ) {
sf.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
try {
// XSOM passes the namespace URI to the publicID parameter.
// we do the same here .
InputSource is = entityResolver.resolveEntity(namespaceURI, systemId);
if(is==null) return null;
return new LSInputSAXWrapper(is);
} catch (SAXException e) {
// TODO: is this sufficient?
return null;
} catch (IOException e) {
// TODO: is this sufficient?
return null;
}
}
});
}
try {
XmlFactory.allowExternalDTDAccess(sf, "all", disableXmlSecurity);
sf.newSchema(getSchemaSource(schemas, entityResolver));
} catch (SAXException e) {
// TODO: we haven't thrown exceptions from here before. should we just trap them and return false?
hadErrors = true;
} catch( OutOfMemoryError e) {
errorHandler.warning(null,Messages.format(Messages.WARN_UNABLE_TO_CHECK_CORRECTNESS));
}
return !(hadErrors || errorFilter.hadError());
}