Search in sources :

Example 1 with ClassLoaderXmlEntityResolver

use of nl.nn.adapterframework.xml.ClassLoaderXmlEntityResolver in project iaf by ibissource.

the class MyErrorHandler method preparse.

private synchronized PreparseResult preparse(String schemasId, List<Schema> schemas) throws ConfigurationException {
    SymbolTable symbolTable = getSymbolTable();
    XMLGrammarPool grammarPool = new XMLGrammarPoolImpl();
    Set<String> namespaceSet = new HashSet<String>();
    XMLGrammarPreparser preparser = new XMLGrammarPreparser(symbolTable);
    preparser.setEntityResolver(new ClassLoaderXmlEntityResolver(this));
    preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);
    preparser.setProperty(GRAMMAR_POOL, grammarPool);
    preparser.setFeature(NAMESPACES_FEATURE_ID, true);
    preparser.setFeature(VALIDATION_FEATURE_ID, true);
    preparser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true);
    preparser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, isFullSchemaChecking());
    try {
        preparser.setProperty(XML_SCHEMA_VERSION_PROPERTY, isXmlSchema1_0() ? Constants.W3C_XML_SCHEMA10EX_NS_URI : Constants.W3C_XML_SCHEMA11_NS_URI);
    } catch (NoSuchFieldError e) {
        String msg = "Cannot set property [" + XML_SCHEMA_VERSION_PROPERTY + "], requested xmlSchemaVersion [" + getXmlSchemaVersion() + "] xercesVersion [" + org.apache.xerces.impl.Version.getVersion() + "]";
        if (isXmlSchema1_0()) {
            log.warn(msg + ", assuming XML-Schema version 1.0 will be supported", e);
        } else {
            throw new ConfigurationException(msg, e);
        }
    }
    MyErrorHandler errorHandler = new MyErrorHandler(this);
    errorHandler.warn = warn;
    preparser.setErrorHandler(errorHandler);
    for (Schema schema : schemas) {
        Grammar grammar = preparse(preparser, schemasId, schema);
        registerNamespaces(grammar, namespaceSet);
    }
    grammarPool.lockPool();
    PreparseResult preparseResult = new PreparseResult();
    preparseResult.setSchemasId(schemasId);
    preparseResult.setSymbolTable(symbolTable);
    preparseResult.setGrammarPool(grammarPool);
    preparseResult.setNamespaceSet(namespaceSet);
    return preparseResult;
}
Also used : XMLGrammarPool(org.apache.xerces.xni.grammars.XMLGrammarPool) SymbolTable(org.apache.xerces.util.SymbolTable) ShadowedSymbolTable(org.apache.xerces.util.ShadowedSymbolTable) Grammar(org.apache.xerces.xni.grammars.Grammar) SchemaGrammar(org.apache.xerces.impl.xs.SchemaGrammar) XSGrammar(org.apache.xerces.xni.grammars.XSGrammar) XMLGrammarPreparser(org.apache.xerces.parsers.XMLGrammarPreparser) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XMLGrammarPoolImpl(org.apache.xerces.util.XMLGrammarPoolImpl) HashSet(java.util.HashSet) ClassLoaderXmlEntityResolver(nl.nn.adapterframework.xml.ClassLoaderXmlEntityResolver)

Aggregations

HashSet (java.util.HashSet)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 ClassLoaderXmlEntityResolver (nl.nn.adapterframework.xml.ClassLoaderXmlEntityResolver)1 SchemaGrammar (org.apache.xerces.impl.xs.SchemaGrammar)1 XMLGrammarPreparser (org.apache.xerces.parsers.XMLGrammarPreparser)1 ShadowedSymbolTable (org.apache.xerces.util.ShadowedSymbolTable)1 SymbolTable (org.apache.xerces.util.SymbolTable)1 XMLGrammarPoolImpl (org.apache.xerces.util.XMLGrammarPoolImpl)1 Grammar (org.apache.xerces.xni.grammars.Grammar)1 XMLGrammarPool (org.apache.xerces.xni.grammars.XMLGrammarPool)1 XSGrammar (org.apache.xerces.xni.grammars.XSGrammar)1