Search in sources :

Example 6 with ValidatorHandler

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);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) DocumentContainer(nl.nn.adapterframework.align.content.DocumentContainer) InputSource(org.xml.sax.InputSource) ValidatorHandler(javax.xml.validation.ValidatorHandler) Schema(javax.xml.validation.Schema) StringReader(java.io.StringReader) SAXParser(org.apache.xerces.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader)

Example 7 with ValidatorHandler

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;
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) ValidatorHandler(javax.xml.validation.ValidatorHandler) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XMLSchemaFactory(nl.nn.adapterframework.validation.xerces_2_11.XMLSchemaFactory) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) SAXException(org.xml.sax.SAXException)

Aggregations

ValidatorHandler (javax.xml.validation.ValidatorHandler)7 Source (javax.xml.transform.Source)5 Schema (javax.xml.validation.Schema)5 LinkedList (java.util.LinkedList)4 SchemaFactory (javax.xml.validation.SchemaFactory)4 XMLSchemaLoader (org.apache.xerces.impl.xs.XMLSchemaLoader)4 XSModel (org.apache.xerces.xs.XSModel)4 SAXException (org.xml.sax.SAXException)4 StringWriter (java.io.StringWriter)3 Transformer (javax.xml.transform.Transformer)3 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3 TransformerFactory (javax.xml.transform.TransformerFactory)3 StreamResult (javax.xml.transform.stream.StreamResult)3 StringReader (java.io.StringReader)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 URL (java.net.URL)1 JsonString (javax.json.JsonString)1 JsonStructure (javax.json.JsonStructure)1 Json2Xml (nl.nn.adapterframework.align.Json2Xml)1