Search in sources :

Example 1 with MCRLazyStreamSource

use of org.mycore.common.xsl.MCRLazyStreamSource in project mycore by MyCoRe-Org.

the class MCRURIResolver method resolve.

/**
 * URI Resolver that resolves XSL document() or xsl:include calls.
 *
 * @see javax.xml.transform.URIResolver
 */
public Source resolve(String href, String base) throws TransformerException {
    if (LOGGER.isDebugEnabled()) {
        if (base != null) {
            LOGGER.debug("Including {} from {}", href, base);
            addDebugInfo(href, base);
        } else {
            LOGGER.debug("Including {}", href);
            addDebugInfo(href, null);
        }
    }
    if (!href.contains(":")) {
        return tryResolveXSL(href, base);
    }
    String scheme = getScheme(href, base);
    URIResolver uriResolver = SUPPORTED_SCHEMES.get(scheme);
    if (uriResolver != null) {
        return uriResolver.resolve(href, base);
    } else {
        // try to handle as URL, use default resolver for file:// and
        try {
            InputSource entity = MCREntityResolver.instance().resolveEntity(null, href);
            if (entity != null) {
                LOGGER.debug("Resolved via EntityResolver: {}", entity.getSystemId());
                return new MCRLazyStreamSource(entity::getByteStream, entity.getSystemId());
            }
        } catch (SAXException | IOException e) {
            LOGGER.debug("Error while resolving uri: {}", href);
        }
        // http://
        if (href.endsWith("/") && scheme.equals("file")) {
            // cannot stream directories
            return null;
        }
        StreamSource streamSource = new StreamSource();
        streamSource.setSystemId(href);
        return streamSource;
    }
}
Also used : InputSource(org.xml.sax.InputSource) StreamSource(javax.xml.transform.stream.StreamSource) MCRLazyStreamSource(org.mycore.common.xsl.MCRLazyStreamSource) URIResolver(javax.xml.transform.URIResolver) IOException(java.io.IOException) MCRLazyStreamSource(org.mycore.common.xsl.MCRLazyStreamSource) SAXException(org.xml.sax.SAXException)

Aggregations

IOException (java.io.IOException)1 URIResolver (javax.xml.transform.URIResolver)1 StreamSource (javax.xml.transform.stream.StreamSource)1 MCRLazyStreamSource (org.mycore.common.xsl.MCRLazyStreamSource)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1