Search in sources :

Example 11 with TreeNode

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

the class TagLibraryInfoImpl method createVariable.

TagVariableInfo createVariable(TreeNode elem) {
    String nameGiven = null;
    String nameFromAttribute = null;
    String className = "java.lang.String";
    boolean declare = true;
    int scope = VariableInfo.NESTED;
    Iterator list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode element = (TreeNode) list.next();
        String tname = element.getName();
        if ("name-given".equals(tname))
            nameGiven = element.getBody();
        else if ("name-from-attribute".equals(tname))
            nameFromAttribute = element.getBody();
        else if ("variable-class".equals(tname))
            className = element.getBody();
        else if ("declare".equals(tname)) {
            String s = element.getBody();
            if (s != null)
                declare = JspUtil.booleanValue(s);
        } else if ("scope".equals(tname)) {
            String s = element.getBody();
            if (s != null) {
                if ("NESTED".equals(s)) {
                    scope = VariableInfo.NESTED;
                } else if ("AT_BEGIN".equals(s)) {
                    scope = VariableInfo.AT_BEGIN;
                } else if ("AT_END".equals(s)) {
                    scope = VariableInfo.AT_END;
                }
            }
        } else if (// Ignored elements
        "description".equals(tname) || false) {
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.variable", tname));
            }
        }
    }
    return new TagVariableInfo(nameGiven, nameFromAttribute, className, declare, scope);
}
Also used : TreeNode(org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode) Iterator(java.util.Iterator) TagVariableInfo(javax.servlet.jsp.tagext.TagVariableInfo)

Example 12 with TreeNode

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

the class TagLibraryInfoImpl method createTagFileInfo.

/*
     * Parses the tag file directives of the given TagFile and turns them into a
     * TagInfo.
     *
     * @param elem The <tag-file> element in the TLD @param uri The location of
     * the TLD, in case the tag file is specified relative to it @param jarFile
     * The JAR file, in case the tag file is packaged in a JAR
     *
     * @return TagInfo correspoding to tag file directives
     */
private TagFileInfo createTagFileInfo(TreeNode elem, String uri, URL jarFileUrl) throws JasperException {
    String name = null;
    String path = null;
    Iterator list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode child = (TreeNode) list.next();
        String tname = child.getName();
        if ("name".equals(tname)) {
            name = child.getBody();
        } else if ("path".equals(tname)) {
            path = child.getBody();
        } else if ("example".equals(tname)) {
        // Ignore <example> element: Bugzilla 33538
        } else if ("tag-extension".equals(tname)) {
        // Ignore <tag-extension> element: Bugzilla 33538
        } else if ("icon".equals(tname) || "display-name".equals(tname) || "description".equals(tname)) {
        // Ignore these elements: Bugzilla 38015
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.tagfile", tname));
            }
        }
    }
    if (path.startsWith("/META-INF/tags")) {
        // Tag file packaged in JAR
        ctxt.setTagFileJarUrl(path, jarFileUrl);
    } else if (!path.startsWith("/WEB-INF/tags")) {
        err.jspError("jsp.error.tagfile.illegalPath", path);
    }
    TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives(parserController, name, path, this);
    return new TagFileInfo(name, path, tagInfo);
}
Also used : TagFileInfo(javax.servlet.jsp.tagext.TagFileInfo) TreeNode(org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode) TagInfo(javax.servlet.jsp.tagext.TagInfo) Iterator(java.util.Iterator)

Example 13 with TreeNode

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

the class TagLibraryInfoImpl method createInitParam.

String[] createInitParam(TreeNode elem) {
    String[] initParam = new String[2];
    Iterator list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode element = (TreeNode) list.next();
        String tname = element.getName();
        if ("param-name".equals(tname)) {
            initParam[0] = element.getBody();
        } else if ("param-value".equals(tname)) {
            initParam[1] = element.getBody();
        } else if ("description".equals(tname)) {
            // Do nothing
            ;
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.initParam", tname));
            }
        }
    }
    return initParam;
}
Also used : TreeNode(org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode) Iterator(java.util.Iterator)

Example 14 with TreeNode

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

the class TagLibraryInfoImpl method createValidator.

private TagLibraryValidator createValidator(TreeNode elem) throws JasperException {
    String validatorClass = null;
    Map initParams = new Hashtable();
    Iterator list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode element = (TreeNode) list.next();
        String tname = element.getName();
        if ("validator-class".equals(tname))
            validatorClass = element.getBody();
        else if ("init-param".equals(tname)) {
            String[] initParam = createInitParam(element);
            initParams.put(initParam[0], initParam[1]);
        } else if (// Ignored elements
        "description".equals(tname) || false) {
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.validator", tname));
            }
        }
    }
    TagLibraryValidator tlv = null;
    if (validatorClass != null && !validatorClass.equals("")) {
        try {
            Class tlvClass = ctxt.getClassLoader().loadClass(validatorClass);
            tlv = (TagLibraryValidator) tlvClass.newInstance();
        } catch (Exception e) {
            err.jspError("jsp.error.tlvclass.instantiation", validatorClass, e);
        }
    }
    if (tlv != null) {
        tlv.setInitParameters(initParams);
    }
    return tlv;
}
Also used : Hashtable(java.util.Hashtable) TreeNode(org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode) Iterator(java.util.Iterator) TagLibraryValidator(javax.servlet.jsp.tagext.TagLibraryValidator) Map(java.util.Map) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 15 with TreeNode

use of org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode 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

TreeNode (org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode)15 Iterator (java.util.Iterator)12 ParserUtils (org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils)8 InputStream (java.io.InputStream)5 JasperException (org.apache.sling.scripting.jsp.jasper.JasperException)5 URL (java.net.URL)3 Vector (java.util.Vector)3 InputSource (org.xml.sax.InputSource)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 Hashtable (java.util.Hashtable)2 FunctionInfo (javax.servlet.jsp.tagext.FunctionInfo)2 TagAttributeInfo (javax.servlet.jsp.tagext.TagAttributeInfo)2 TagFileInfo (javax.servlet.jsp.tagext.TagFileInfo)2 TagInfo (javax.servlet.jsp.tagext.TagInfo)2 TagVariableInfo (javax.servlet.jsp.tagext.TagVariableInfo)2 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1