Search in sources :

Example 1 with LSInput

use of org.w3c.dom.ls.LSInput in project qi4j-sdk by Qi4j.

the class QuikitResolver method resolveResource.

public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
    String resourceName = local.getProperty(systemId);
    if (resourceName == null) {
        System.out.println("type: " + type);
        System.out.println("namespaceURI: " + namespaceURI);
        System.out.println("publicId: " + publicId);
        System.out.println("systemId: " + systemId);
        System.out.println("baseURI: " + baseURI);
        return null;
    }
    InputStream resource = getClass().getClassLoader().getResourceAsStream(resourceName);
    LSInput input;
    try {
        input = getLSInput();
    } catch (Exception e) {
        throw new UnsupportedOperationException("Internal problem. Please report to qi4j-dev forum at Google Groups.", e);
    }
    input.setBaseURI(baseURI);
    input.setByteStream(resource);
    input.setPublicId(publicId);
    input.setSystemId(systemId);
    return input;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) LSInput(org.w3c.dom.ls.LSInput) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException)

Example 2 with LSInput

use of org.w3c.dom.ls.LSInput in project languagetool by languagetool-org.

the class PatternRuleXmlCreator method getDocument.

private Document getDocument(InputStream is) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
    LSParser parser = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
    // we need to ignore whitespace here so the nodeToString() method will be able to indent it properly:
    parser.setFilter(new IgnoreWhitespaceFilter());
    LSInput domInput = impl.createLSInput();
    domInput.setByteStream(is);
    return parser.parse(domInput);
}
Also used : DOMImplementationLS(org.w3c.dom.ls.DOMImplementationLS) LSInput(org.w3c.dom.ls.LSInput) DOMImplementationRegistry(org.w3c.dom.bootstrap.DOMImplementationRegistry) LSParser(org.w3c.dom.ls.LSParser)

Example 3 with LSInput

use of org.w3c.dom.ls.LSInput in project aries by apache.

the class SimpleNamespaceHandlerSet method getSchema.

public Schema getSchema() throws SAXException, IOException {
    if (schema == null) {
        final List<StreamSource> schemaSources = new ArrayList<StreamSource>();
        final List<InputStream> streams = new ArrayList<InputStream>();
        try {
            InputStream is = getClass().getResourceAsStream("/org/apache/aries/blueprint/blueprint.xsd");
            streams.add(is);
            schemaSources.add(new StreamSource(is));
            for (URI uri : namespaces.keySet()) {
                is = namespaces.get(uri).openStream();
                streams.add(is);
                schemaSources.add(new StreamSource(is));
            }
            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            schemaFactory.setResourceResolver(new LSResourceResolver() {

                public LSInput resolveResource(String type, String namespace, String publicId, String systemId, String baseURI) {
                    try {
                        URL namespaceURL = namespaces.get(URI.create(namespace));
                        if (systemId != null && namespaceURL != null) {
                            URI systemIdUri = namespaceURL.toURI();
                            if (!URI.create(systemId).isAbsolute()) {
                                systemIdUri = systemIdUri.resolve(systemId);
                            }
                            if (!systemIdUri.isAbsolute() && "jar".equals(namespaceURL.getProtocol())) {
                                String urlString = namespaceURL.toString();
                                int jarFragmentIndex = urlString.lastIndexOf('!');
                                if (jarFragmentIndex > 0 && jarFragmentIndex < urlString.length() - 1) {
                                    String jarUrlOnly = urlString.substring(0, jarFragmentIndex);
                                    String oldFragment = urlString.substring(jarFragmentIndex + 1);
                                    String newFragment = URI.create(oldFragment).resolve(systemId).toString();
                                    String newJarUri = jarUrlOnly + '!' + newFragment;
                                    systemIdUri = URI.create(newJarUri);
                                }
                            }
                            InputStream resourceStream = systemIdUri.toURL().openStream();
                            return new LSInputImpl(publicId, systemId, resourceStream);
                        }
                    } catch (Exception ex) {
                    // ignore
                    }
                    return null;
                }
            });
            schema = schemaFactory.newSchema(schemaSources.toArray(new Source[schemaSources.size()]));
        } finally {
            for (InputStream is : streams) {
                is.close();
            }
        }
    }
    return schema;
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) ArrayList(java.util.ArrayList) URI(java.net.URI) URL(java.net.URL) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) LSResourceResolver(org.w3c.dom.ls.LSResourceResolver) LSInput(org.w3c.dom.ls.LSInput)

Example 4 with LSInput

use of org.w3c.dom.ls.LSInput in project midpoint by Evolveum.

the class XmlEntityResolverImpl method resolveResource.

/* (non-Javadoc)
	 * @see org.w3c.dom.ls.LSResourceResolver#resolveResource(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
    LOGGER.trace("--- Resolving resource of type {}, namespaceURI: {}, publicID: {}, systemID: {}, base URI: {}", type, namespaceURI, publicId, systemId, baseURI);
    InputSource inputSource = resolveResourceFromRegisteredSchemas(publicId, systemId);
    if (inputSource == null) {
        inputSource = resolveResourceUsingBuiltinResolver(type, namespaceURI, publicId, systemId, baseURI);
    }
    if (inputSource == null) {
        LOGGER.error("Unable to resolve resource of type {}, namespaceURI: {}, publicID: {}, systemID: {}, baseURI: {}", new Object[] { type, namespaceURI, publicId, systemId, baseURI });
        return null;
    }
    LOGGER.trace("==> Resolved resource of type {}, namespaceURI: {}, publicID: {}, systemID: {}, baseURI: {} : {}", new Object[] { type, namespaceURI, publicId, systemId, baseURI, inputSource });
    return new Input(publicId, systemId, inputSource.getByteStream());
}
Also used : InputSource(org.xml.sax.InputSource) LSInput(org.w3c.dom.ls.LSInput)

Aggregations

LSInput (org.w3c.dom.ls.LSInput)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 SAXException (org.xml.sax.SAXException)2 BufferedInputStream (java.io.BufferedInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 URI (java.net.URI)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 StreamSource (javax.xml.transform.stream.StreamSource)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 DOMImplementationRegistry (org.w3c.dom.bootstrap.DOMImplementationRegistry)1 DOMImplementationLS (org.w3c.dom.ls.DOMImplementationLS)1 LSParser (org.w3c.dom.ls.LSParser)1 LSResourceResolver (org.w3c.dom.ls.LSResourceResolver)1 InputSource (org.xml.sax.InputSource)1