Search in sources :

Example 1 with TagFileInfo

use of javax.servlet.jsp.tagext.TagFileInfo in project sling by apache.

the class ImplicitTagLibraryInfo method getTagFile.

/**
     * Checks to see if the given tag name maps to a tag file path,
     * and if so, parses the corresponding tag file.
     *
     * @return The TagFileInfo corresponding to the given tag name, or null if
     * the given tag name is not implemented as a tag file
     */
public TagFileInfo getTagFile(String shortName) {
    TagFileInfo tagFile = super.getTagFile(shortName);
    if (tagFile == null) {
        String path = (String) tagFileMap.get(shortName);
        if (path == null) {
            return null;
        }
        TagInfo tagInfo = null;
        try {
            tagInfo = TagFileProcessor.parseTagFileDirectives(pc, shortName, path, this);
        } catch (JasperException je) {
            throw new RuntimeException(je.toString(), je);
        }
        tagFile = new TagFileInfo(shortName, path, tagInfo);
        vec.addElement(tagFile);
        this.tagFiles = new TagFileInfo[vec.size()];
        vec.copyInto(this.tagFiles);
    }
    return tagFile;
}
Also used : TagFileInfo(javax.servlet.jsp.tagext.TagFileInfo) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) TagInfo(javax.servlet.jsp.tagext.TagInfo)

Example 2 with TagFileInfo

use of javax.servlet.jsp.tagext.TagFileInfo in project sling by apache.

the class TagLibraryInfoImpl method parseTLD.

/*
     * @param ctxt The JSP compilation context @param uri The TLD's uri @param
     * in The TLD's input stream @param jarFileUrl The JAR file containing the
     * TLD, or null if the tag library is not packaged in a JAR
     */
private void parseTLD(JspCompilationContext ctxt, String uri, InputStream in, URL jarFileUrl) throws JasperException {
    Vector tagVector = new Vector();
    Vector tagFileVector = new Vector();
    Hashtable functionTable = new Hashtable();
    // Create an iterator over the child elements of our <taglib> element
    ParserUtils pu = new ParserUtils();
    TreeNode tld = pu.parseXMLDocument(uri, in);
    // Check to see if the <taglib> root element contains a 'version'
    // attribute, which was added in JSP 2.0 to replace the <jsp-version>
    // subelement
    this.jspversion = tld.findAttribute("version");
    // Process each child element of our <taglib> element
    Iterator list = tld.findChildren();
    while (list.hasNext()) {
        TreeNode element = (TreeNode) list.next();
        String tname = element.getName();
        if (// JSP 1.1
        "tlibversion".equals(tname) || "tlib-version".equals(tname)) {
            // JSP 1.2
            this.tlibversion = element.getBody();
        } else if ("jspversion".equals(tname) || "jsp-version".equals(tname)) {
            this.jspversion = element.getBody();
        } else if ("shortname".equals(tname) || "short-name".equals(tname))
            this.shortname = element.getBody();
        else if ("uri".equals(tname))
            this.urn = element.getBody();
        else if ("info".equals(tname) || "description".equals(tname))
            this.info = element.getBody();
        else if ("validator".equals(tname))
            this.tagLibraryValidator = createValidator(element);
        else if ("tag".equals(tname))
            tagVector.addElement(createTagInfo(element, jspversion));
        else if ("tag-file".equals(tname)) {
            TagFileInfo tagFileInfo = createTagFileInfo(element, uri, jarFileUrl);
            tagFileVector.addElement(tagFileInfo);
        } else if ("function".equals(tname)) {
            // JSP2.0
            FunctionInfo funcInfo = createFunctionInfo(element);
            String funcName = funcInfo.getName();
            if (functionTable.containsKey(funcName)) {
                err.jspError("jsp.error.tld.fn.duplicate.name", funcName, uri);
            }
            functionTable.put(funcName, funcInfo);
        } else if (// Ignored elements
        "display-name".equals(tname) || "small-icon".equals(tname) || "large-icon".equals(tname) || "listener".equals(tname)) {
            ;
        } else if ("taglib-extension".equals(tname)) {
        // Recognized but ignored
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.taglib", tname));
            }
        }
    }
    if (tlibversion == null) {
        err.jspError("jsp.error.tld.mandatory.element.missing", "tlib-version");
    }
    if (jspversion == null) {
        err.jspError("jsp.error.tld.mandatory.element.missing", "jsp-version");
    }
    this.tags = new TagInfo[tagVector.size()];
    tagVector.copyInto(this.tags);
    this.tagFiles = new TagFileInfo[tagFileVector.size()];
    tagFileVector.copyInto(this.tagFiles);
    this.functions = new FunctionInfo[functionTable.size()];
    int i = 0;
    Enumeration enumeration = functionTable.elements();
    while (enumeration.hasMoreElements()) {
        this.functions[i++] = (FunctionInfo) enumeration.nextElement();
    }
}
Also used : TagFileInfo(javax.servlet.jsp.tagext.TagFileInfo) Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable) TreeNode(org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode) Iterator(java.util.Iterator) FunctionInfo(javax.servlet.jsp.tagext.FunctionInfo) ParserUtils(org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils) Vector(java.util.Vector)

Example 3 with TagFileInfo

use of javax.servlet.jsp.tagext.TagFileInfo in project tomcat70 by apache.

the class JspDocumentParser method parseCustomAction.

/*
     * Checks if the XML element with the given tag name is a custom action,
     * and returns the corresponding Node object.
     */
private Node parseCustomAction(String qName, String localName, String uri, Attributes nonTaglibAttrs, Attributes nonTaglibXmlnsAttrs, Attributes taglibAttrs, Mark start, Node parent) throws SAXException {
    // Check if this is a user-defined (custom) tag
    TagLibraryInfo tagLibInfo = pageInfo.getTaglib(uri);
    if (tagLibInfo == null) {
        return null;
    }
    TagInfo tagInfo = tagLibInfo.getTag(localName);
    TagFileInfo tagFileInfo = tagLibInfo.getTagFile(localName);
    if (tagInfo == null && tagFileInfo == null) {
        throw new SAXParseException(Localizer.getMessage("jsp.error.xml.bad_tag", localName, uri), locator);
    }
    Class<?> tagHandlerClass = null;
    if (tagInfo != null) {
        String handlerClassName = tagInfo.getTagClassName();
        try {
            tagHandlerClass = ctxt.getClassLoader().loadClass(handlerClassName);
        } catch (Exception e) {
            throw new SAXParseException(Localizer.getMessage("jsp.error.loadclass.taghandler", handlerClassName, qName), locator, e);
        }
    }
    String prefix = getPrefix(qName);
    Node.CustomTag ret = null;
    if (tagInfo != null) {
        ret = new Node.CustomTag(qName, prefix, localName, uri, nonTaglibAttrs, nonTaglibXmlnsAttrs, taglibAttrs, start, parent, tagInfo, tagHandlerClass);
    } else {
        ret = new Node.CustomTag(qName, prefix, localName, uri, nonTaglibAttrs, nonTaglibXmlnsAttrs, taglibAttrs, start, parent, tagFileInfo);
    }
    return ret;
}
Also used : TagFileInfo(javax.servlet.jsp.tagext.TagFileInfo) SAXParseException(org.xml.sax.SAXParseException) TagInfo(javax.servlet.jsp.tagext.TagInfo) TagLibraryInfo(javax.servlet.jsp.tagext.TagLibraryInfo) JasperException(org.apache.jasper.JasperException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Example 4 with TagFileInfo

use of javax.servlet.jsp.tagext.TagFileInfo in project tomcat70 by apache.

the class TagLibraryInfoImpl method parseTLD.

/*
     * @param ctxt The JSP compilation context @param uri The TLD's uri @param
     * in The TLD's input stream @param jarFileUrl The JAR file containing the
     * TLD, or null if the tag library is not packaged in a JAR
     */
private void parseTLD(String uri, InputStream in, JarResource jarResource) throws JasperException {
    Vector<TagInfo> tagVector = new Vector<TagInfo>();
    Vector<TagFileInfo> tagFileVector = new Vector<TagFileInfo>();
    Hashtable<String, FunctionInfo> functionTable = new Hashtable<String, FunctionInfo>();
    ServletContext servletContext = ctxt.getServletContext();
    boolean validate = Boolean.parseBoolean(servletContext.getInitParameter(Constants.XML_VALIDATION_TLD_INIT_PARAM));
    String blockExternalString = servletContext.getInitParameter(Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
    boolean blockExternal;
    if (blockExternalString == null) {
        blockExternal = true;
    } else {
        blockExternal = Boolean.parseBoolean(blockExternalString);
    }
    // Create an iterator over the child elements of our <taglib> element
    ParserUtils pu = new ParserUtils(validate, blockExternal);
    TreeNode tld = pu.parseXMLDocument(uri, in);
    // Check to see if the <taglib> root element contains a 'version'
    // attribute, which was added in JSP 2.0 to replace the <jsp-version>
    // subelement
    this.jspversion = tld.findAttribute("version");
    // Process each child element of our <taglib> element
    Iterator<TreeNode> list = tld.findChildren();
    while (list.hasNext()) {
        TreeNode element = list.next();
        String tname = element.getName();
        if (// JSP 1.1
        "tlibversion".equals(tname) || "tlib-version".equals(tname)) {
            // JSP 1.2
            this.tlibversion = element.getBody();
        } else if ("jspversion".equals(tname) || "jsp-version".equals(tname)) {
            this.jspversion = element.getBody();
        } else if ("shortname".equals(tname) || "short-name".equals(tname))
            this.shortname = element.getBody();
        else if ("uri".equals(tname))
            this.urn = element.getBody();
        else if ("info".equals(tname) || "description".equals(tname))
            this.info = element.getBody();
        else if ("validator".equals(tname))
            this.tagLibraryValidator = createValidator(element);
        else if ("tag".equals(tname))
            tagVector.addElement(createTagInfo(element, jspversion));
        else if ("tag-file".equals(tname)) {
            TagFileInfo tagFileInfo = createTagFileInfo(element, jarResource);
            tagFileVector.addElement(tagFileInfo);
        } else if ("function".equals(tname)) {
            // JSP2.0
            FunctionInfo funcInfo = createFunctionInfo(element);
            String funcName = funcInfo.getName();
            if (functionTable.containsKey(funcName)) {
                err.jspError("jsp.error.tld.fn.duplicate.name", funcName, uri);
            }
            functionTable.put(funcName, funcInfo);
        } else if ("display-name".equals(tname) || "small-icon".equals(tname) || "large-icon".equals(tname) || "listener".equals(tname)) {
        // Ignored elements
        } else if ("taglib-extension".equals(tname)) {
        // Recognized but ignored
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.taglib", tname));
            }
        }
    }
    if (tlibversion == null) {
        err.jspError("jsp.error.tld.mandatory.element.missing", "tlib-version", uri);
    }
    if (jspversion == null) {
        err.jspError("jsp.error.tld.mandatory.element.missing", "jsp-version", uri);
    }
    this.tags = new TagInfo[tagVector.size()];
    tagVector.copyInto(this.tags);
    this.tagFiles = new TagFileInfo[tagFileVector.size()];
    tagFileVector.copyInto(this.tagFiles);
    this.functions = new FunctionInfo[functionTable.size()];
    int i = 0;
    Enumeration<FunctionInfo> enumeration = functionTable.elements();
    while (enumeration.hasMoreElements()) {
        this.functions[i++] = enumeration.nextElement();
    }
}
Also used : TagFileInfo(javax.servlet.jsp.tagext.TagFileInfo) Hashtable(java.util.Hashtable) FunctionInfo(javax.servlet.jsp.tagext.FunctionInfo) TreeNode(org.apache.jasper.xmlparser.TreeNode) TagInfo(javax.servlet.jsp.tagext.TagInfo) ServletContext(javax.servlet.ServletContext) ParserUtils(org.apache.jasper.xmlparser.ParserUtils) Vector(java.util.Vector)

Example 5 with TagFileInfo

use of javax.servlet.jsp.tagext.TagFileInfo in project tomcat70 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 corresponding to tag file directives
     */
private TagFileInfo createTagFileInfo(TreeNode elem, JarResource jarResource) throws JasperException {
    String name = null;
    String path = null;
    Iterator<TreeNode> list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode child = 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 == null) {
        // path is required
        err.jspError("jsp.error.tagfile.missingPath");
    } else if (path.startsWith("/META-INF/tags")) {
        // Tag file packaged in JAR
        // See https://bz.apache.org/bugzilla/show_bug.cgi?id=46471
        // This needs to be removed once all the broken code that depends on
        // it has been removed
        ctxt.setTagFileJarResource(path, jarResource);
    } else if (!path.startsWith("/WEB-INF/tags")) {
        err.jspError("jsp.error.tagfile.illegalPath", path);
    }
    TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives(parserController, name, path, jarResource, this);
    return new TagFileInfo(name, path, tagInfo);
}
Also used : TagFileInfo(javax.servlet.jsp.tagext.TagFileInfo) TreeNode(org.apache.jasper.xmlparser.TreeNode) TagInfo(javax.servlet.jsp.tagext.TagInfo)

Aggregations

TagFileInfo (javax.servlet.jsp.tagext.TagFileInfo)12 TagInfo (javax.servlet.jsp.tagext.TagInfo)9 FileNotFoundException (java.io.FileNotFoundException)4 TagLibraryInfo (javax.servlet.jsp.tagext.TagLibraryInfo)4 JasperException (org.apache.jasper.JasperException)3 JasperException (org.apache.sling.scripting.jsp.jasper.JasperException)3 Attributes (org.xml.sax.Attributes)3 IOException (java.io.IOException)2 Hashtable (java.util.Hashtable)2 Iterator (java.util.Iterator)2 Vector (java.util.Vector)2 ServletContext (javax.servlet.ServletContext)2 FunctionInfo (javax.servlet.jsp.tagext.FunctionInfo)2 TreeNode (org.apache.jasper.xmlparser.TreeNode)2 TreeNode (org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode)2 SAXException (org.xml.sax.SAXException)2 SAXParseException (org.xml.sax.SAXParseException)2 File (java.io.File)1 Enumeration (java.util.Enumeration)1 Context (org.apache.catalina.Context)1