* @return true if there was no error, false if there were errors.
*/
public static boolean check(InputSource[] schemas,
ErrorReceiver errorHandler, final EntityResolver entityResolver) {
ErrorReceiverFilter errorFilter = new ErrorReceiverFilter(errorHandler);
boolean hadErrors = false;
SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
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 {
sf.newSchema(getSchemaSource(schemas));
} 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());
}