use of javax.xml.validation.ValidatorHandler in project iaf by ibissource.
the class XmlTo method translate.
public static void translate(String xml, URL schemaURL, DocumentContainer documentContainer) throws SAXException, IOException {
// create the ValidatorHandler
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(schemaURL);
ValidatorHandler validatorHandler = schema.newValidatorHandler();
// create the parser, setup the chain
XMLReader parser = new SAXParser();
XmlAligner aligner = new XmlAligner(validatorHandler);
XmlTo<DocumentContainer> xml2object = new XmlTo<DocumentContainer>(aligner, documentContainer);
parser.setContentHandler(validatorHandler);
aligner.setContentHandler(xml2object);
// start translating
InputSource is = new InputSource(new StringReader(xml));
parser.parse(is);
}
use of javax.xml.validation.ValidatorHandler in project iaf by ibissource.
the class MyErrorHandler method getValidatorHandler.
public ValidatorHandler getValidatorHandler(IPipeLineSession session, ValidationContext context) throws ConfigurationException, PipeRunException {
ValidatorHandler validatorHandler = null;
try {
XMLSchemaFactory schemaFactory = new XMLSchemaFactory();
javax.xml.validation.Schema schemaObject = schemaFactory.newSchema(((XercesValidationContext) context).getGrammarPool());
validatorHandler = schemaObject.newValidatorHandler();
} catch (SAXException e) {
throw new ConfigurationException(logPrefix + "Cannot create schema", e);
}
try {
// validatorHandler.setFeature(NAMESPACES_FEATURE_ID, true);
validatorHandler.setFeature(VALIDATION_FEATURE_ID, true);
validatorHandler.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true);
validatorHandler.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, isFullSchemaChecking());
validatorHandler.setErrorHandler(context.getErrorHandler());
} catch (SAXNotRecognizedException e) {
throw new ConfigurationException(logPrefix + "ValidatorHandler does not recognize necessary feature", e);
} catch (SAXNotSupportedException e) {
throw new ConfigurationException(logPrefix + "ValidatorHandler does not support necessary feature", e);
}
return validatorHandler;
}
Aggregations