Search in sources :

Example 1 with CatalogResolver

use of org.apache.xml.resolver.tools.CatalogResolver in project midpoint by Evolveum.

the class SchemaRegistryImpl method initResolver.

private void initResolver() throws IOException {
    CatalogManager catalogManager = new CatalogManager();
    catalogManager.setUseStaticCatalog(true);
    catalogManager.setIgnoreMissingProperties(true);
    catalogManager.setVerbosity(1);
    catalogManager.setPreferPublic(true);
    CatalogResolver catalogResolver = new CatalogResolver(catalogManager);
    Catalog catalog = catalogResolver.getCatalog();
    if (catalogFiles != null && catalogFiles.length > 0) {
        for (File catalogFile : catalogFiles) {
            LOGGER.trace("Using catalog file {}", catalogFile);
            catalog.parseCatalog(catalogFile.getPath());
        }
    } else if (catalogResourceName != null) {
        LOGGER.trace("Using catalog from resource: {}", catalogResourceName);
        Enumeration<URL> catalogs = Thread.currentThread().getContextClassLoader().getResources(catalogResourceName);
        while (catalogs.hasMoreElements()) {
            URL catalogResourceUrl = catalogs.nextElement();
            LOGGER.trace("Parsing catalog from URL: {}", catalogResourceUrl);
            catalog.parseCatalog(catalogResourceUrl);
        }
    } else {
        throw new IllegalStateException("Catalog is not defined");
    }
    builtinSchemaResolver = catalogResolver;
}
Also used : Enumeration(java.util.Enumeration) CatalogResolver(org.apache.xml.resolver.tools.CatalogResolver) File(java.io.File) CatalogManager(org.apache.xml.resolver.CatalogManager) Catalog(org.apache.xml.resolver.Catalog) URL(java.net.URL)

Example 2 with CatalogResolver

use of org.apache.xml.resolver.tools.CatalogResolver in project camel by apache.

the class ValidatorWithResourceResolverRouteTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    // we have to do it here, because we need the context created first
    CatalogManager.getStaticManager().setIgnoreMissingProperties(true);
    CatalogResolver catalogResolver = new CatalogResolver(true);
    URL catalogUrl = ResourceHelper.resolveMandatoryResourceAsUrl(context.getClassResolver(), "org/apache/camel/component/validator/catalog.cat");
    catalogResolver.getCatalog().parseCatalog(catalogUrl);
    LSResourceResolver resourceResolver = new CatalogLSResourceResolver(catalogResolver);
    JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry();
    registry.bind("resourceResolver", resourceResolver);
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").doTry().to("validator:org/apache/camel/component/validator/report.xsd?resourceResolver=#resourceResolver").to("mock:valid").doCatch(ValidationException.class).to("mock:invalid").doFinally().to("mock:finally").end();
        }
    };
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) RouteBuilder(org.apache.camel.builder.RouteBuilder) LSResourceResolver(org.w3c.dom.ls.LSResourceResolver) CatalogLSResourceResolver(org.apache.camel.processor.validation.CatalogLSResourceResolver) CatalogLSResourceResolver(org.apache.camel.processor.validation.CatalogLSResourceResolver) CatalogResolver(org.apache.xml.resolver.tools.CatalogResolver) URL(java.net.URL)

Aggregations

URL (java.net.URL)2 CatalogResolver (org.apache.xml.resolver.tools.CatalogResolver)2 File (java.io.File)1 Enumeration (java.util.Enumeration)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 JndiRegistry (org.apache.camel.impl.JndiRegistry)1 CatalogLSResourceResolver (org.apache.camel.processor.validation.CatalogLSResourceResolver)1 Catalog (org.apache.xml.resolver.Catalog)1 CatalogManager (org.apache.xml.resolver.CatalogManager)1 LSResourceResolver (org.w3c.dom.ls.LSResourceResolver)1