Search in sources :

Example 1 with TagInfo

use of javax.servlet.jsp.tagext.TagInfo 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 TagInfo

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

the class TagLibraryInfoImpl method createTagInfo.

private TagInfo createTagInfo(TreeNode elem, String jspVersion) throws JasperException {
    String tagName = null;
    String tagClassName = null;
    String teiClassName = null;
    /*
         * Default body content for JSP 1.2 tag handlers (<body-content> has
         * become mandatory in JSP 2.0, because the default would be invalid for
         * simple tag handlers)
         */
    String bodycontent = "JSP";
    String info = null;
    String displayName = null;
    String smallIcon = null;
    String largeIcon = null;
    boolean dynamicAttributes = false;
    Vector attributeVector = new Vector();
    Vector variableVector = new Vector();
    Iterator list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode element = (TreeNode) list.next();
        String tname = element.getName();
        if ("name".equals(tname)) {
            tagName = element.getBody();
        } else if ("tagclass".equals(tname) || "tag-class".equals(tname)) {
            tagClassName = element.getBody();
        } else if ("teiclass".equals(tname) || "tei-class".equals(tname)) {
            teiClassName = element.getBody();
        } else if ("bodycontent".equals(tname) || "body-content".equals(tname)) {
            bodycontent = element.getBody();
        } else if ("display-name".equals(tname)) {
            displayName = element.getBody();
        } else if ("small-icon".equals(tname)) {
            smallIcon = element.getBody();
        } else if ("large-icon".equals(tname)) {
            largeIcon = element.getBody();
        } else if ("icon".equals(tname)) {
            TreeNode icon = element.findChild("small-icon");
            if (icon != null) {
                smallIcon = icon.getBody();
            }
            icon = element.findChild("large-icon");
            if (icon != null) {
                largeIcon = icon.getBody();
            }
        } else if ("info".equals(tname) || "description".equals(tname)) {
            info = element.getBody();
        } else if ("variable".equals(tname)) {
            variableVector.addElement(createVariable(element));
        } else if ("attribute".equals(tname)) {
            attributeVector.addElement(createAttribute(element, jspVersion));
        } else if ("dynamic-attributes".equals(tname)) {
            dynamicAttributes = JspUtil.booleanValue(element.getBody());
        } else if ("example".equals(tname)) {
        // Ignored elements
        } else if ("tag-extension".equals(tname)) {
        // Ignored
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.tag", tname));
            }
        }
    }
    TagExtraInfo tei = null;
    if (teiClassName != null && !teiClassName.equals("")) {
        try {
            Class teiClass = ctxt.getClassLoader().loadClass(teiClassName);
            tei = (TagExtraInfo) teiClass.newInstance();
        } catch (Exception e) {
            err.jspError("jsp.error.teiclass.instantiation", teiClassName, e);
        }
    }
    TagAttributeInfo[] tagAttributeInfo = new TagAttributeInfo[attributeVector.size()];
    attributeVector.copyInto(tagAttributeInfo);
    TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector.size()];
    variableVector.copyInto(tagVariableInfos);
    TagInfo taginfo = new TagInfo(tagName, tagClassName, bodycontent, info, this, tei, tagAttributeInfo, displayName, smallIcon, largeIcon, tagVariableInfos, dynamicAttributes);
    return taginfo;
}
Also used : TagAttributeInfo(javax.servlet.jsp.tagext.TagAttributeInfo) TagVariableInfo(javax.servlet.jsp.tagext.TagVariableInfo) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) TreeNode(org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode) TagExtraInfo(javax.servlet.jsp.tagext.TagExtraInfo) TagInfo(javax.servlet.jsp.tagext.TagInfo) Iterator(java.util.Iterator) Vector(java.util.Vector)

Example 3 with TagInfo

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

the class Parser method getAttributeBodyType.

/**
     * Determine the body type of <jsp:attribute> from the enclosing node
     */
private String getAttributeBodyType(Node n, String name) {
    if (n instanceof Node.CustomTag) {
        TagInfo tagInfo = ((Node.CustomTag) n).getTagInfo();
        TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
        for (int i = 0; i < tldAttrs.length; i++) {
            if (name.equals(tldAttrs[i].getName())) {
                if (tldAttrs[i].isFragment()) {
                    return TagInfo.BODY_CONTENT_SCRIPTLESS;
                }
                if (tldAttrs[i].canBeRequestTime()) {
                    return TagInfo.BODY_CONTENT_JSP;
                }
            }
        }
        if (tagInfo.hasDynamicAttributes()) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.IncludeAction) {
        if ("page".equals(name)) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.ForwardAction) {
        if ("page".equals(name)) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.SetProperty) {
        if ("value".equals(name)) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.UseBean) {
        if ("beanName".equals(name)) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.PlugIn) {
        if ("width".equals(name) || "height".equals(name)) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.ParamAction) {
        if ("value".equals(name)) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.JspElement) {
        return TagInfo.BODY_CONTENT_JSP;
    }
    return JAVAX_BODY_CONTENT_TEMPLATE_TEXT;
}
Also used : TagAttributeInfo(javax.servlet.jsp.tagext.TagAttributeInfo) TagInfo(javax.servlet.jsp.tagext.TagInfo)

Example 4 with TagInfo

use of javax.servlet.jsp.tagext.TagInfo 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 5 with TagInfo

use of javax.servlet.jsp.tagext.TagInfo 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)

Aggregations

TagInfo (javax.servlet.jsp.tagext.TagInfo)16 TagFileInfo (javax.servlet.jsp.tagext.TagFileInfo)9 FileNotFoundException (java.io.FileNotFoundException)7 TagAttributeInfo (javax.servlet.jsp.tagext.TagAttributeInfo)5 TagLibraryInfo (javax.servlet.jsp.tagext.TagLibraryInfo)5 JasperException (org.apache.sling.scripting.jsp.jasper.JasperException)5 IOException (java.io.IOException)4 JasperException (org.apache.jasper.JasperException)4 Iterator (java.util.Iterator)3 Vector (java.util.Vector)3 TagExtraInfo (javax.servlet.jsp.tagext.TagExtraInfo)3 TreeNode (org.apache.jasper.xmlparser.TreeNode)3 Hashtable (java.util.Hashtable)2 TagVariableInfo (javax.servlet.jsp.tagext.TagVariableInfo)2 TreeNode (org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode)2 Attributes (org.xml.sax.Attributes)2 SAXException (org.xml.sax.SAXException)2 SAXParseException (org.xml.sax.SAXParseException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1