Search in sources :

Example 6 with ParserUtils

use of org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils in project sling by apache.

the class JspCTldLocationsCache method processWebDotXml.

/*
     * Populates taglib map described in web.xml.
     */
private void processWebDotXml() throws Exception {
    InputStream is = null;
    try {
        // Acquire input stream to web application deployment descriptor
        String altDDName = (String) ctxt.getAttribute(Constants.ALT_DD_ATTR);
        URL uri = null;
        if (altDDName != null) {
            try {
                uri = new URL(FILE_PROTOCOL + altDDName.replace('\\', '/'));
            } catch (MalformedURLException e) {
                if (log.isWarnEnabled()) {
                    log.warn(Localizer.getMessage("jsp.error.internal.filenotfound", altDDName));
                }
            }
        } else {
            uri = ctxt.getResource(WEB_XML);
            if (uri == null && log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.error.internal.filenotfound", WEB_XML));
            }
        }
        if (uri == null) {
            return;
        }
        is = uri.openStream();
        InputSource ip = new InputSource(is);
        ip.setSystemId(uri.toExternalForm());
        // Parse the web application deployment descriptor
        TreeNode webtld;
        // altDDName is the absolute path of the DD
        if (altDDName != null) {
            webtld = new ParserUtils().parseXMLDocument(altDDName, ip);
        } else {
            webtld = new ParserUtils().parseXMLDocument(WEB_XML, ip);
        }
        // Allow taglib to be an element of the root or jsp-config (JSP2.0)
        TreeNode jspConfig = webtld.findChild("jsp-config");
        if (jspConfig != null) {
            webtld = jspConfig;
        }
        Iterator taglibs = webtld.findChildren("taglib");
        while (taglibs.hasNext()) {
            // Parse the next <taglib> element
            TreeNode taglib = (TreeNode) taglibs.next();
            String tagUri = null;
            String tagLoc = null;
            TreeNode child = taglib.findChild("taglib-uri");
            if (child != null)
                tagUri = child.getBody();
            child = taglib.findChild("taglib-location");
            if (child != null)
                tagLoc = child.getBody();
            // Save this location if appropriate
            if (tagLoc == null)
                continue;
            if (uriType(tagLoc) == NOROOT_REL_URI)
                tagLoc = "/WEB-INF/" + tagLoc;
            String tagLoc2 = null;
            if (tagLoc.endsWith(JAR_FILE_SUFFIX)) {
                tagLoc = ctxt.getResource(tagLoc).toString();
                tagLoc2 = "META-INF/taglib.tld";
            }
            mappings.put(tagUri, new String[] { tagLoc, tagLoc2 });
        }
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Throwable t) {
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) TreeNode(org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode) Iterator(java.util.Iterator) ParserUtils(org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils) URL(java.net.URL)

Example 7 with ParserUtils

use of org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils in project sling by apache.

the class JspCTldLocationsCache method getUriFromTld.

/*
     * Returns the value of the uri element of the given TLD, or null if the
     * given TLD does not contain any such element.
     */
private String getUriFromTld(String resourcePath, InputStream in) throws JasperException {
    // Parse the tag library descriptor at the specified resource path
    TreeNode tld = new ParserUtils().parseXMLDocument(resourcePath, in);
    TreeNode uri = tld.findChild("uri");
    if (uri != null) {
        String body = uri.getBody();
        if (body != null)
            return body;
    }
    return null;
}
Also used : TreeNode(org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode) ParserUtils(org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils)

Example 8 with ParserUtils

use of org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils in project sling by apache.

the class OriginalTldLocationsCache method processWebDotXml.

/*
     * Populates taglib map described in web.xml.
     */
private void processWebDotXml() throws Exception {
    InputStream is = null;
    try {
        // Acquire input stream to web application deployment descriptor
        String altDDName = (String) ctxt.getAttribute(Constants.ALT_DD_ATTR);
        URL uri = null;
        if (altDDName != null) {
            try {
                uri = new URL(FILE_PROTOCOL + altDDName.replace('\\', '/'));
            } catch (MalformedURLException e) {
                if (log.isWarnEnabled()) {
                    log.warn(Localizer.getMessage("jsp.error.internal.filenotfound", altDDName));
                }
            }
        } else {
            uri = ctxt.getResource(WEB_XML);
            if (uri == null && log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.error.internal.filenotfound", WEB_XML));
            }
        }
        if (uri == null) {
            return;
        }
        is = uri.openStream();
        InputSource ip = new InputSource(is);
        ip.setSystemId(uri.toExternalForm());
        // Parse the web application deployment descriptor
        TreeNode webtld = null;
        // altDDName is the absolute path of the DD
        if (altDDName != null) {
            webtld = new ParserUtils().parseXMLDocument(altDDName, ip);
        } else {
            webtld = new ParserUtils().parseXMLDocument(WEB_XML, ip);
        }
        // Allow taglib to be an element of the root or jsp-config (JSP2.0)
        TreeNode jspConfig = webtld.findChild("jsp-config");
        if (jspConfig != null) {
            webtld = jspConfig;
        }
        Iterator taglibs = webtld.findChildren("taglib");
        while (taglibs.hasNext()) {
            // Parse the next <taglib> element
            TreeNode taglib = (TreeNode) taglibs.next();
            String tagUri = null;
            String tagLoc = null;
            TreeNode child = taglib.findChild("taglib-uri");
            if (child != null)
                tagUri = child.getBody();
            child = taglib.findChild("taglib-location");
            if (child != null)
                tagLoc = child.getBody();
            // Save this location if appropriate
            if (tagLoc == null)
                continue;
            if (uriType(tagLoc) == NOROOT_REL_URI)
                tagLoc = "/WEB-INF/" + tagLoc;
            String tagLoc2 = null;
            if (tagLoc.endsWith(JAR_FILE_SUFFIX)) {
                tagLoc = ctxt.getResource(tagLoc).toString();
                tagLoc2 = "META-INF/taglib.tld";
            }
            mappings.put(tagUri, new String[] { tagLoc, tagLoc2 });
        }
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Throwable t) {
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) TreeNode(org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode) Iterator(java.util.Iterator) ParserUtils(org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils) URL(java.net.URL)

Aggregations

ParserUtils (org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils)8 TreeNode (org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode)8 InputStream (java.io.InputStream)5 Iterator (java.util.Iterator)5 URL (java.net.URL)3 JasperException (org.apache.sling.scripting.jsp.jasper.JasperException)3 InputSource (org.xml.sax.InputSource)3 MalformedURLException (java.net.MalformedURLException)2 Vector (java.util.Vector)2 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 FunctionInfo (javax.servlet.jsp.tagext.FunctionInfo)1 TagFileInfo (javax.servlet.jsp.tagext.TagFileInfo)1 TagPlugin (org.apache.sling.scripting.jsp.jasper.compiler.tagplugin.TagPlugin)1