Resource xsdResource) {
Assert.notNull(xsdResource, "xsdResource cannot be null");
if (!xsdResource.exists()) {
throw new ExecutionException("Cannot validate document as xsdResource '" + xsdResource + "' does not exist");
} else {
if (logger.isDebugEnabled()) {
logger.debug("Validating using schema resource " + xsdResource.getDescription());
}
}
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
try {
InputStream inputStream = xsdResource.getInputStream();
Source source = new StreamSource(inputStream);
Schema schema = factory.newSchema(source);
Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));
}
catch (SAXParseException e) {
throw new ExecutionException("Error on " + e.getLineNumber() + ", column " + e.getColumnNumber() + " in " + description + ": " + e.getMessage(), e);
}
catch (SAXException e) {
throw new ExecutionException("Error parsing " + description + ": " + e.getMessage(), e);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}