@Override public SAXParseException[] validate(Source source, ValidationErrorHandler errorHandler) throws IOException { if (errorHandler == null) { errorHandler = new DefaultValidationErrorHandler(); } Validator validator = schema.newValidator(); try { validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); } catch (SAXNotRecognizedException | SAXNotSupportedException e) { if (log.isWarnEnabled()) { log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by " + validator.getClass().getCanonicalName()); } } try { validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); } catch (SAXNotRecognizedException | SAXNotSupportedException e) { if (log.isWarnEnabled()) { log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by " + validator.getClass().getCanonicalName()); } } validator.setErrorHandler(errorHandler); try { validator.validate(source); return errorHandler.getErrors(); } catch (SAXException ex) { throw new XmlValidationException("Could not validate source: " + ex.getMessage(), ex); } } }
@Override public SAXParseException[] validate(Source source, ValidationErrorHandler errorHandler) throws IOException { if (errorHandler == null) { errorHandler = new DefaultValidationErrorHandler(); } Validator validator = schema.newValidator(); try { validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); } catch (SAXNotRecognizedException | SAXNotSupportedException e) { if (log.isWarnEnabled()) { log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by " + validator.getClass().getCanonicalName()); } } try { validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); } catch (SAXNotRecognizedException | SAXNotSupportedException e) { if (log.isWarnEnabled()) { log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by " + validator.getClass().getCanonicalName()); } } validator.setErrorHandler(errorHandler); try { validator.validate(source); return errorHandler.getErrors(); } catch (SAXException ex) { throw new XmlValidationException("Could not validate source: " + ex.getMessage(), ex); } } }