Search in sources :

Example 1 with EmbeddedInputStream

use of org.exist.protocolhandler.embedded.EmbeddedInputStream in project exist by eXist-db.

the class AnyUriResolver method resolveEntity.

@Override
public XMLInputSource resolveEntity(XMLResourceIdentifier xri) throws XNIException, IOException {
    if (xri.getExpandedSystemId() == null && xri.getLiteralSystemId() == null && xri.getNamespace() == null && xri.getPublicId() == null) {
        // quick fail
        return null;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Resolving XMLResourceIdentifier: {}", getXriDetails(xri));
    }
    String resourcePath = null;
    String baseSystemId = null;
    if (firstTime) {
        // First time use constructor supplied path
        resourcePath = docPath;
        baseSystemId = parentURI;
        xri.setExpandedSystemId(docPath);
        firstTime = false;
    } else {
        resourcePath = xri.getExpandedSystemId();
    }
    xri.setBaseSystemId(docPath);
    LOG.debug("resourcePath='{}'", resourcePath);
    // prevent NPE
    if (resourcePath == null) {
        return null;
    }
    InputStream is = null;
    if (resourcePath.startsWith("xmldb:")) {
        final XmldbURL xmldbURL = new XmldbURL(resourcePath);
        if (xmldbURL.isEmbedded()) {
            is = new EmbeddedInputStream(xmldbURL);
        } else {
            is = new XmlrpcInputStream(threadGroup, xmldbURL);
        }
    } else {
        is = new URL(resourcePath).openStream();
    }
    final XMLInputSource xis = new XMLInputSource(xri.getPublicId(), resourcePath, baseSystemId, is, "UTF-8");
    if (LOG.isDebugEnabled()) {
        LOG.debug("XMLInputSource: {}", getXisDetails(xis));
    }
    return xis;
}
Also used : XmldbURL(org.exist.protocolhandler.xmldb.XmldbURL) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) EmbeddedInputStream(org.exist.protocolhandler.embedded.EmbeddedInputStream) XmlrpcInputStream(org.exist.protocolhandler.xmlrpc.XmlrpcInputStream) InputStream(java.io.InputStream) EmbeddedInputStream(org.exist.protocolhandler.embedded.EmbeddedInputStream) XmlrpcInputStream(org.exist.protocolhandler.xmlrpc.XmlrpcInputStream) URL(java.net.URL) XmldbURL(org.exist.protocolhandler.xmldb.XmldbURL)

Example 2 with EmbeddedInputStream

use of org.exist.protocolhandler.embedded.EmbeddedInputStream in project exist by eXist-db.

the class ExistResolver method resolveInputSource.

/* ============== */
/* Helper methods */
/* ============== */
private InputSource resolveInputSource(BrokerPool bPool, String path) throws IOException {
    LOG.debug("Resolving {}", path);
    final InputSource inputsource = new InputSource();
    if (path != null) {
        if (path.startsWith(LOCALURI) || path.startsWith(SHORTLOCALURI)) {
            final XmldbURL url = new XmldbURL(path);
            final EmbeddedInputStream eis = new EmbeddedInputStream(bPool, url);
            inputsource.setByteStream(eis);
            inputsource.setSystemId(path);
        } else {
            final InputStream is = new URL(path).openStream();
            inputsource.setByteStream(is);
            inputsource.setSystemId(path);
        }
    }
    return inputsource;
}
Also used : InputSource(org.xml.sax.InputSource) XmldbURL(org.exist.protocolhandler.xmldb.XmldbURL) EmbeddedInputStream(org.exist.protocolhandler.embedded.EmbeddedInputStream) InputStream(java.io.InputStream) EmbeddedInputStream(org.exist.protocolhandler.embedded.EmbeddedInputStream) URL(java.net.URL) XmldbURL(org.exist.protocolhandler.xmldb.XmldbURL)

Example 3 with EmbeddedInputStream

use of org.exist.protocolhandler.embedded.EmbeddedInputStream in project exist by eXist-db.

the class ExistResolver method resolveStreamSource.

private StreamSource resolveStreamSource(BrokerPool bPool, String path) throws TransformerException {
    LOG.debug("Resolving {}", path);
    final StreamSource streamsource = new StreamSource();
    try {
        if (path != null) {
            if (path.startsWith(LOCALURI) || path.startsWith(SHORTLOCALURI)) {
                final XmldbURL url = new XmldbURL(path);
                final EmbeddedInputStream eis = new EmbeddedInputStream(bPool, url);
                streamsource.setInputStream(eis);
                streamsource.setSystemId(path);
            } else {
                final InputStream is = new URL(path).openStream();
                streamsource.setInputStream(is);
                streamsource.setSystemId(path);
            }
        }
    } catch (final IOException ex) {
        throw new TransformerException(ex);
    }
    return streamsource;
}
Also used : XmldbURL(org.exist.protocolhandler.xmldb.XmldbURL) EmbeddedInputStream(org.exist.protocolhandler.embedded.EmbeddedInputStream) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) EmbeddedInputStream(org.exist.protocolhandler.embedded.EmbeddedInputStream) IOException(java.io.IOException) URL(java.net.URL) XmldbURL(org.exist.protocolhandler.xmldb.XmldbURL) TransformerException(javax.xml.transform.TransformerException)

Example 4 with EmbeddedInputStream

use of org.exist.protocolhandler.embedded.EmbeddedInputStream in project exist by eXist-db.

the class EmbeddedURLConnection method getInputStream.

@Override
public InputStream getInputStream() throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug(url);
    }
    final XmldbURL xmldbURL = new XmldbURL(url);
    final InputStream inputstream;
    if (xmldbURL.isEmbedded()) {
        inputstream = new EmbeddedInputStream(xmldbURL);
    } else {
        inputstream = new XmlrpcInputStream(threadGroup, xmldbURL);
    }
    return inputstream;
}
Also used : XmldbURL(org.exist.protocolhandler.xmldb.XmldbURL) EmbeddedInputStream(org.exist.protocolhandler.embedded.EmbeddedInputStream) XmlrpcInputStream(org.exist.protocolhandler.xmlrpc.XmlrpcInputStream) InputStream(java.io.InputStream) EmbeddedInputStream(org.exist.protocolhandler.embedded.EmbeddedInputStream) XmlrpcInputStream(org.exist.protocolhandler.xmlrpc.XmlrpcInputStream)

Aggregations

InputStream (java.io.InputStream)4 EmbeddedInputStream (org.exist.protocolhandler.embedded.EmbeddedInputStream)4 XmldbURL (org.exist.protocolhandler.xmldb.XmldbURL)4 URL (java.net.URL)3 XmlrpcInputStream (org.exist.protocolhandler.xmlrpc.XmlrpcInputStream)2 IOException (java.io.IOException)1 TransformerException (javax.xml.transform.TransformerException)1 StreamSource (javax.xml.transform.stream.StreamSource)1 XMLInputSource (org.apache.xerces.xni.parser.XMLInputSource)1 InputSource (org.xml.sax.InputSource)1