Java Code Examples for org.apache.ws.commons.schema.XmlSchemaCollection#setSchemaResolver()

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaCollection#setSchemaResolver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private XmlSchema parseXmlSchema(final InputStream is, final String baseXsdPath) {
    try {
        XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
        schemaCollection.setSchemaResolver(new URIResolver() {
            @Override
            public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
                if (resourceLoader != null) {
                    Resource resource = resourceLoader.getResource(baseXsdPath + "/" + schemaLocation);
                    if (resource.exists()) {
                        try {
                            return new InputSource(resource.getInputStream());
                        } catch (IOException e) {
                            throw new RuntimeException("Exception occurred", e);
                        }
                    }
                }
                return new InputSource(Thread.currentThread().getContextClassLoader()
                        .getResourceAsStream(baseXsdPath + "/" + schemaLocation));
            }
        });
        return schemaCollection.read(new InputSource(is), null);
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    } finally {
        try {
            is.close();
        } catch (IOException ioException) {
            LOG.error("ioExecption in closing input file ", ioException);
        }
    }
}
 
Example 2
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.DoNotThrowExceptionInFinally")   // seems necessary to report issue while closing input stream
private XmlSchema parseXmlSchema(final InputStream is) {
    try {
        XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
        schemaCollection.setSchemaResolver(new URIResolver() {
            @Override
            public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
                if (resourceLoader != null) {
                    Resource resource = resourceLoader.getResource(getXsdPath() + "/" + schemaLocation);
                    if (resource.exists()) {
                        try {
                            return new InputSource(resource.getInputStream());
                        } catch (IOException e) {
                            throw new RuntimeException("Exception occurred", e);
                        }
                    }
                }
                return new InputSource(Thread.currentThread().getContextClassLoader()
                        .getResourceAsStream(getXsdPath() + "/" + schemaLocation));
            }
        });
        return schemaCollection.read(new InputSource(is), null);
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    } finally {
        try {
            is.close();
        } catch (IOException ioException) {
            throw new RuntimeException(ioException);
        }
    }
}
 
Example 3
Source File: SmooksGenerator.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.DoNotThrowExceptionInFinally")    // smooks support soon to be removed
private XmlSchema parseXmlSchema(final InputStream is, final String baseXsdPath) {
    try {
        XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
        // schemaCollection.setBaseUri(baseUri);
        schemaCollection.setSchemaResolver(new URIResolver() {
            @Override
            public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
                if (resourceLoader != null) {
                    Resource resource = resourceLoader.getResource(baseXsdPath + "/" + schemaLocation);
                    if (resource.exists()) {
                        try {
                            return new InputSource(resource.getInputStream());
                        } catch (IOException e) {
                            throw new RuntimeException("Exception occurred", e);
                        }
                    }
                }
                return new InputSource(Thread.currentThread().getContextClassLoader()
                        .getResourceAsStream(baseXsdPath + "/" + schemaLocation));
            }
        });
        return schemaCollection.read(new InputSource(is), null);
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    } finally {
        try {
            is.close();
        } catch (IOException ioException) {
            throw new RuntimeException(ioException);
        }
    }
}
 
Example 4
Source File: XsdReader.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
private static final XmlSchema readSchema(final InputStream istream, final URIResolver schemaResolver) {
    final XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
    schemaCollection.setSchemaResolver(schemaResolver);
    return schemaCollection.read(new InputSource(istream), null);
}