Java Code Examples for javax.servlet.jsp.tagext.TagInfo#hasDynamicAttributes()

The following examples show how to use javax.servlet.jsp.tagext.TagInfo#hasDynamicAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Validator.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@SuppressWarnings("null") // tagInfo can't be null after initial test
@Override
public void visit(Node.CustomTag n) throws JasperException {

    TagInfo tagInfo = n.getTagInfo();
    if (tagInfo == null) {
        err.jspError(n, "jsp.error.missing.tagInfo", n.getQName());
    }

    /*
     * The bodycontent of a SimpleTag cannot be JSP.
     */
    if (n.implementsSimpleTag()
            && tagInfo.getBodyContent().equalsIgnoreCase(
                    TagInfo.BODY_CONTENT_JSP)) {
        err.jspError(n, "jsp.error.simpletag.badbodycontent", tagInfo
                .getTagClassName());
    }

    /*
     * If the tag handler declares in the TLD that it supports dynamic
     * attributes, it also must implement the DynamicAttributes
     * interface.
     */
    if (tagInfo.hasDynamicAttributes()
            && !n.implementsDynamicAttributes()) {
        err.jspError(n, "jsp.error.dynamic.attributes.not.implemented",
                n.getQName());
    }

    /*
     * Make sure all required attributes are present, either as
     * attributes or named attributes (<jsp:attribute>). Also make sure
     * that the same attribute is not specified in both attributes or
     * named attributes.
     */
    TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
    String customActionUri = n.getURI();
    Attributes attrs = n.getAttributes();
    int attrsSize = (attrs == null) ? 0 : attrs.getLength();
    for (int i = 0; i < tldAttrs.length; i++) {
        String attr = null;
        if (attrs != null) {
            attr = attrs.getValue(tldAttrs[i].getName());
            if (attr == null) {
                attr = attrs.getValue(customActionUri, tldAttrs[i]
                        .getName());
            }
        }
        Node.NamedAttribute na = n.getNamedAttributeNode(tldAttrs[i]
                .getName());

        if (tldAttrs[i].isRequired() && attr == null && na == null) {
            err.jspError(n, "jsp.error.missing_attribute", tldAttrs[i]
                    .getName(), n.getLocalName());
        }
        if (attr != null && na != null) {
            err.jspError(n, "jsp.error.duplicate.name.jspattribute",
                    tldAttrs[i].getName());
        }
    }

    Node.Nodes naNodes = n.getNamedAttributeNodes();
    int jspAttrsSize = naNodes.size() + attrsSize;
    Node.JspAttribute[] jspAttrs = null;
    if (jspAttrsSize > 0) {
        jspAttrs = new Node.JspAttribute[jspAttrsSize];
    }
    Hashtable<String, Object> tagDataAttrs = new Hashtable<>(attrsSize);

    checkXmlAttributes(n, jspAttrs, tagDataAttrs);
    checkNamedAttributes(n, jspAttrs, attrsSize, tagDataAttrs);

    TagData tagData = new TagData(tagDataAttrs);

    // JSP.C1: It is a (translation time) error for an action that
    // has one or more variable subelements to have a TagExtraInfo
    // class that returns a non-null object.
    TagExtraInfo tei = tagInfo.getTagExtraInfo();
    if (tei != null && tei.getVariableInfo(tagData) != null
            && tei.getVariableInfo(tagData).length > 0
            && tagInfo.getTagVariableInfos().length > 0) {
        err.jspError("jsp.error.non_null_tei_and_var_subelems", n
                .getQName());
    }

    n.setTagData(tagData);
    n.setJspAttributes(jspAttrs);

    visitBody(n);
}
 
Example 2
Source File: Validator.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private void checkNamedAttributes(Node.CustomTag n,
        Node.JspAttribute[] jspAttrs, int start,
        Hashtable<String, Object> tagDataAttrs)
        throws JasperException {

    TagInfo tagInfo = n.getTagInfo();
    TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
    Node.Nodes naNodes = n.getNamedAttributeNodes();

    for (int i = 0; i < naNodes.size(); i++) {
        Node.NamedAttribute na = (Node.NamedAttribute) naNodes
                .getNode(i);
        boolean found = false;
        for (int j = 0; j < tldAttrs.length; j++) {
            /*
             * See above comment about namespace matches. For named
             * attributes, we use the prefix instead of URI as the match
             * criterion, because in the case of a JSP document, we'd
             * have to keep track of which namespaces are in scope when
             * parsing a named attribute, in order to determine the URI
             * that the prefix of the named attribute's name matches to.
             */
            String attrPrefix = na.getPrefix();
            if (na.getLocalName().equals(tldAttrs[j].getName())
                    && (attrPrefix == null || attrPrefix.length() == 0 || attrPrefix
                            .equals(n.getPrefix()))) {
                jspAttrs[start + i] = new Node.JspAttribute(na,
                        tldAttrs[j], false);
                NamedAttributeVisitor nav = null;
                if (na.getBody() != null) {
                    nav = new NamedAttributeVisitor();
                    na.getBody().visit(nav);
                }
                if (nav != null && nav.hasDynamicContent()) {
                    tagDataAttrs.put(na.getName(),
                            TagData.REQUEST_TIME_VALUE);
                } else {
                    tagDataAttrs.put(na.getName(), na.getText());
                }
                found = true;
                break;
            }
        }
        if (!found) {
            if (tagInfo.hasDynamicAttributes()) {
                jspAttrs[start + i] = new Node.JspAttribute(na, null,
                        true);
            } else {
                err.jspError(n, "jsp.error.bad_attribute",
                        na.getName(), n.getLocalName());
            }
        }
    }
}
 
Example 3
Source File: Parser.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: Generator.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Generates declarations for tag handler attributes, and defines the getter
 * and setter methods for each.
 */
private void generateTagHandlerAttributes(TagInfo tagInfo) {

    if (tagInfo.hasDynamicAttributes()) {
        out.printil("private java.util.HashMap _jspx_dynamic_attrs = new java.util.HashMap();");
    }

    // Declare attributes
    TagAttributeInfo[] attrInfos = tagInfo.getAttributes();
    for (int i = 0; i < attrInfos.length; i++) {
        out.printin("private ");
        if (attrInfos[i].isFragment()) {
            out.print("javax.servlet.jsp.tagext.JspFragment ");
        } else {
            out.print(JspUtil.toJavaSourceType(attrInfos[i].getTypeName()));
            out.print(" ");
        }
        out.print(JspUtil.makeJavaIdentifierForAttribute(
                attrInfos[i].getName()));
        out.println(";");
    }
    out.println();

    // Define attribute getter and setter methods
    for (int i = 0; i < attrInfos.length; i++) {
        String javaName =
            JspUtil.makeJavaIdentifierForAttribute(attrInfos[i].getName());

        // getter method
        out.printin("public ");
        if (attrInfos[i].isFragment()) {
            out.print("javax.servlet.jsp.tagext.JspFragment ");
        } else {
            out.print(JspUtil.toJavaSourceType(attrInfos[i].getTypeName()));
            out.print(" ");
        }
        out.print(toGetterMethod(attrInfos[i].getName()));
        out.println(" {");
        out.pushIndent();
        out.printin("return this.");
        out.print(javaName);
        out.println(";");
        out.popIndent();
        out.printil("}");
        out.println();

        // setter method
        out.printin("public void ");
        out.print(toSetterMethodName(attrInfos[i].getName()));
        if (attrInfos[i].isFragment()) {
            out.print("(javax.servlet.jsp.tagext.JspFragment ");
        } else {
            out.print("(");
            out.print(JspUtil.toJavaSourceType(attrInfos[i].getTypeName()));
            out.print(" ");
        }
        out.print(javaName);
        out.println(") {");
        out.pushIndent();
        out.printin("this.");
        out.print(javaName);
        out.print(" = ");
        out.print(javaName);
        out.println(";");
        if (ctxt.isTagFile()) {
            // Tag files should also set jspContext attributes
            out.printin("jspContext.setAttribute(\"");
            out.print(attrInfos[i].getName());
            out.print("\", ");
            out.print(javaName);
            out.println(");");
        }
        out.popIndent();
        out.printil("}");
        out.println();
    }
}
 
Example 5
Source File: Validator.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(Node.CustomTag n) throws JasperException {

    TagInfo tagInfo = n.getTagInfo();
    if (tagInfo == null) {
        err.jspError(n, "jsp.error.missing.tagInfo", n.getQName());
    }

    /*
     * The bodycontent of a SimpleTag cannot be JSP.
     */
    if (n.implementsSimpleTag()
            && tagInfo.getBodyContent().equalsIgnoreCase(
                    TagInfo.BODY_CONTENT_JSP)) {
        err.jspError(n, "jsp.error.simpletag.badbodycontent", tagInfo
                .getTagClassName());
    }

    /*
     * If the tag handler declares in the TLD that it supports dynamic
     * attributes, it also must implement the DynamicAttributes
     * interface.
     */
    if (tagInfo.hasDynamicAttributes()
            && !n.implementsDynamicAttributes()) {
        err.jspError(n, "jsp.error.dynamic.attributes.not.implemented",
                n.getQName());
    }

    /*
     * Make sure all required attributes are present, either as
     * attributes or named attributes (<jsp:attribute>). Also make sure
     * that the same attribute is not specified in both attributes or
     * named attributes.
     */
    TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
    String customActionUri = n.getURI();
    Attributes attrs = n.getAttributes();
    int attrsSize = (attrs == null) ? 0 : attrs.getLength();
    for (int i = 0; i < tldAttrs.length; i++) {
        String attr = null;
        if (attrs != null) {
            attr = attrs.getValue(tldAttrs[i].getName());
            if (attr == null) {
                attr = attrs.getValue(customActionUri, tldAttrs[i]
                        .getName());
            }
        }
        Node.NamedAttribute na = n.getNamedAttributeNode(tldAttrs[i]
                .getName());

        if (tldAttrs[i].isRequired() && attr == null && na == null) {
            err.jspError(n, "jsp.error.missing_attribute", tldAttrs[i]
                    .getName(), n.getLocalName());
        }
        if (attr != null && na != null) {
            err.jspError(n, "jsp.error.duplicate.name.jspattribute",
                    tldAttrs[i].getName());
        }
    }

    Node.Nodes naNodes = n.getNamedAttributeNodes();
    int jspAttrsSize = naNodes.size() + attrsSize;
    Node.JspAttribute[] jspAttrs = null;
    if (jspAttrsSize > 0) {
        jspAttrs = new Node.JspAttribute[jspAttrsSize];
    }
    Hashtable<String, Object> tagDataAttrs = new Hashtable<String, Object>(attrsSize);

    checkXmlAttributes(n, jspAttrs, tagDataAttrs);
    checkNamedAttributes(n, jspAttrs, attrsSize, tagDataAttrs);

    TagData tagData = new TagData(tagDataAttrs);

    // JSP.C1: It is a (translation time) error for an action that
    // has one or more variable subelements to have a TagExtraInfo
    // class that returns a non-null object.
    TagExtraInfo tei = tagInfo.getTagExtraInfo();
    if (tei != null && tei.getVariableInfo(tagData) != null
            && tei.getVariableInfo(tagData).length > 0
            && tagInfo.getTagVariableInfos().length > 0) {
        err.jspError("jsp.error.non_null_tei_and_var_subelems", n
                .getQName());
    }

    n.setTagData(tagData);
    n.setJspAttributes(jspAttrs);

    visitBody(n);
}
 
Example 6
Source File: Validator.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
private void checkNamedAttributes(Node.CustomTag n,
        Node.JspAttribute[] jspAttrs, int start,
        Hashtable<String, Object> tagDataAttrs)
        throws JasperException {

    TagInfo tagInfo = n.getTagInfo();
    if (tagInfo == null) {
        err.jspError(n, "jsp.error.missing.tagInfo", n.getQName());
    }
    TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
    Node.Nodes naNodes = n.getNamedAttributeNodes();

    for (int i = 0; i < naNodes.size(); i++) {
        Node.NamedAttribute na = (Node.NamedAttribute) naNodes
                .getNode(i);
        boolean found = false;
        for (int j = 0; j < tldAttrs.length; j++) {
            /*
             * See above comment about namespace matches. For named
             * attributes, we use the prefix instead of URI as the match
             * criterion, because in the case of a JSP document, we'd
             * have to keep track of which namespaces are in scope when
             * parsing a named attribute, in order to determine the URI
             * that the prefix of the named attribute's name matches to.
             */
            String attrPrefix = na.getPrefix();
            if (na.getLocalName().equals(tldAttrs[j].getName())
                    && (attrPrefix == null || attrPrefix.length() == 0 || attrPrefix
                            .equals(n.getPrefix()))) {
                jspAttrs[start + i] = new Node.JspAttribute(na,
                        tldAttrs[j], false);
                NamedAttributeVisitor nav = null;
                if (na.getBody() != null) {
                    nav = new NamedAttributeVisitor();
                    na.getBody().visit(nav);
                }
                if (nav != null && nav.hasDynamicContent()) {
                    tagDataAttrs.put(na.getName(),
                            TagData.REQUEST_TIME_VALUE);
                } else {
                    tagDataAttrs.put(na.getName(), na.getText());
                }
                found = true;
                break;
            }
        }
        if (!found) {
            if (tagInfo.hasDynamicAttributes()) {
                jspAttrs[start + i] = new Node.JspAttribute(na, null,
                        true);
            } else {
                err.jspError(n, "jsp.error.bad_attribute",
                        na.getName(), n.getLocalName());
            }
        }
    }
}
 
Example 7
Source File: Parser.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source File: Generator.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Generates declarations for tag handler attributes, and defines the getter
 * and setter methods for each.
 */
private void generateTagHandlerAttributes(TagInfo tagInfo) {

    if (tagInfo.hasDynamicAttributes()) {
        out.printil("private java.util.HashMap _jspx_dynamic_attrs = new java.util.HashMap();");
    }

    // Declare attributes
    TagAttributeInfo[] attrInfos = tagInfo.getAttributes();
    for (int i = 0; i < attrInfos.length; i++) {
        out.printin("private ");
        if (attrInfos[i].isFragment()) {
            out.print("javax.servlet.jsp.tagext.JspFragment ");
        } else {
            out.print(JspUtil.toJavaSourceType(attrInfos[i].getTypeName()));
            out.print(" ");
        }
        out.print(JspUtil.makeJavaIdentifierForAttribute(
                attrInfos[i].getName()));
        out.println(";");
    }
    out.println();

    // Define attribute getter and setter methods
    for (int i = 0; i < attrInfos.length; i++) {
        String javaName =
            JspUtil.makeJavaIdentifierForAttribute(attrInfos[i].getName());

        // getter method
        out.printin("public ");
        if (attrInfos[i].isFragment()) {
            out.print("javax.servlet.jsp.tagext.JspFragment ");
        } else {
            out.print(JspUtil.toJavaSourceType(attrInfos[i].getTypeName()));
            out.print(" ");
        }
        out.print(toGetterMethod(attrInfos[i].getName()));
        out.println(" {");
        out.pushIndent();
        out.printin("return this.");
        out.print(javaName);
        out.println(";");
        out.popIndent();
        out.printil("}");
        out.println();

        // setter method
        out.printin("public void ");
        out.print(toSetterMethodName(attrInfos[i].getName()));
        if (attrInfos[i].isFragment()) {
            out.print("(javax.servlet.jsp.tagext.JspFragment ");
        } else {
            out.print("(");
            out.print(JspUtil.toJavaSourceType(attrInfos[i].getTypeName()));
            out.print(" ");
        }
        out.print(javaName);
        out.println(") {");
        out.pushIndent();
        out.printin("this.");
        out.print(javaName);
        out.print(" = ");
        out.print(javaName);
        out.println(";");
        if (ctxt.isTagFile()) {
            // Tag files should also set jspContext attributes
            out.printin("jspContext.setAttribute(\"");
            out.print(attrInfos[i].getName());
            out.print("\", ");
            out.print(javaName);
            out.println(");");
        }
        out.popIndent();
        out.printil("}");
        out.println();
    }
}
 
Example 9
Source File: Validator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(Node.CustomTag n) throws JasperException {

    TagInfo tagInfo = n.getTagInfo();
    if (tagInfo == null) {
        err.jspError(n, "jsp.error.missing.tagInfo", n.getQName());
    }

    /*
     * The bodycontent of a SimpleTag cannot be JSP.
     */
    if (n.implementsSimpleTag()
            && tagInfo.getBodyContent().equalsIgnoreCase(
                    TagInfo.BODY_CONTENT_JSP)) {
        err.jspError(n, "jsp.error.simpletag.badbodycontent", tagInfo
                .getTagClassName());
    }

    /*
     * If the tag handler declares in the TLD that it supports dynamic
     * attributes, it also must implement the DynamicAttributes
     * interface.
     */
    if (tagInfo.hasDynamicAttributes()
            && !n.implementsDynamicAttributes()) {
        err.jspError(n, "jsp.error.dynamic.attributes.not.implemented",
                n.getQName());
    }

    /*
     * Make sure all required attributes are present, either as
     * attributes or named attributes (<jsp:attribute>). Also make sure
     * that the same attribute is not specified in both attributes or
     * named attributes.
     */
    TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
    String customActionUri = n.getURI();
    Attributes attrs = n.getAttributes();
    int attrsSize = (attrs == null) ? 0 : attrs.getLength();
    for (int i = 0; i < tldAttrs.length; i++) {
        String attr = null;
        if (attrs != null) {
            attr = attrs.getValue(tldAttrs[i].getName());
            if (attr == null) {
                attr = attrs.getValue(customActionUri, tldAttrs[i]
                        .getName());
            }
        }
        Node.NamedAttribute na = n.getNamedAttributeNode(tldAttrs[i]
                .getName());

        if (tldAttrs[i].isRequired() && attr == null && na == null) {
            err.jspError(n, "jsp.error.missing_attribute", tldAttrs[i]
                    .getName(), n.getLocalName());
        }
        if (attr != null && na != null) {
            err.jspError(n, "jsp.error.duplicate.name.jspattribute",
                    tldAttrs[i].getName());
        }
    }

    Node.Nodes naNodes = n.getNamedAttributeNodes();
    int jspAttrsSize = naNodes.size() + attrsSize;
    Node.JspAttribute[] jspAttrs = null;
    if (jspAttrsSize > 0) {
        jspAttrs = new Node.JspAttribute[jspAttrsSize];
    }
    Hashtable<String, Object> tagDataAttrs = new Hashtable<String, Object>(attrsSize);

    checkXmlAttributes(n, jspAttrs, tagDataAttrs);
    checkNamedAttributes(n, jspAttrs, attrsSize, tagDataAttrs);

    TagData tagData = new TagData(tagDataAttrs);

    // JSP.C1: It is a (translation time) error for an action that
    // has one or more variable subelements to have a TagExtraInfo
    // class that returns a non-null object.
    TagExtraInfo tei = tagInfo.getTagExtraInfo();
    if (tei != null && tei.getVariableInfo(tagData) != null
            && tei.getVariableInfo(tagData).length > 0
            && tagInfo.getTagVariableInfos().length > 0) {
        err.jspError("jsp.error.non_null_tei_and_var_subelems", n
                .getQName());
    }

    n.setTagData(tagData);
    n.setJspAttributes(jspAttrs);

    visitBody(n);
}
 
Example 10
Source File: Validator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private void checkNamedAttributes(Node.CustomTag n,
        Node.JspAttribute[] jspAttrs, int start,
        Hashtable<String, Object> tagDataAttrs)
        throws JasperException {

    TagInfo tagInfo = n.getTagInfo();
    if (tagInfo == null) {
        err.jspError(n, "jsp.error.missing.tagInfo", n.getQName());
    }
    TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
    Node.Nodes naNodes = n.getNamedAttributeNodes();

    for (int i = 0; i < naNodes.size(); i++) {
        Node.NamedAttribute na = (Node.NamedAttribute) naNodes
                .getNode(i);
        boolean found = false;
        for (int j = 0; j < tldAttrs.length; j++) {
            /*
             * See above comment about namespace matches. For named
             * attributes, we use the prefix instead of URI as the match
             * criterion, because in the case of a JSP document, we'd
             * have to keep track of which namespaces are in scope when
             * parsing a named attribute, in order to determine the URI
             * that the prefix of the named attribute's name matches to.
             */
            String attrPrefix = na.getPrefix();
            if (na.getLocalName().equals(tldAttrs[j].getName())
                    && (attrPrefix == null || attrPrefix.length() == 0 || attrPrefix
                            .equals(n.getPrefix()))) {
                jspAttrs[start + i] = new Node.JspAttribute(na,
                        tldAttrs[j], false);
                NamedAttributeVisitor nav = null;
                if (na.getBody() != null) {
                    nav = new NamedAttributeVisitor();
                    na.getBody().visit(nav);
                }
                if (nav != null && nav.hasDynamicContent()) {
                    tagDataAttrs.put(na.getName(),
                            TagData.REQUEST_TIME_VALUE);
                } else {
                    tagDataAttrs.put(na.getName(), na.getText());
                }
                found = true;
                break;
            }
        }
        if (!found) {
            if (tagInfo.hasDynamicAttributes()) {
                jspAttrs[start + i] = new Node.JspAttribute(na, null,
                        true);
            } else {
                err.jspError(n, "jsp.error.bad_attribute",
                        na.getName(), n.getLocalName());
            }
        }
    }
}
 
Example 11
Source File: Parser.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: Generator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Generates declarations for tag handler attributes, and defines the getter
 * and setter methods for each.
 */
private void generateTagHandlerAttributes(TagInfo tagInfo) {

    if (tagInfo.hasDynamicAttributes()) {
        out.printil("private java.util.HashMap _jspx_dynamic_attrs = new java.util.HashMap();");
    }

    // Declare attributes
    TagAttributeInfo[] attrInfos = tagInfo.getAttributes();
    for (int i = 0; i < attrInfos.length; i++) {
        out.printin("private ");
        if (attrInfos[i].isFragment()) {
            out.print("javax.servlet.jsp.tagext.JspFragment ");
        } else {
            out.print(JspUtil.toJavaSourceType(attrInfos[i].getTypeName()));
            out.print(" ");
        }
        out.print(JspUtil.makeJavaIdentifierForAttribute(
                attrInfos[i].getName()));
        out.println(";");
    }
    out.println();

    // Define attribute getter and setter methods
    for (int i = 0; i < attrInfos.length; i++) {
        String javaName =
            JspUtil.makeJavaIdentifierForAttribute(attrInfos[i].getName());

        // getter method
        out.printin("public ");
        if (attrInfos[i].isFragment()) {
            out.print("javax.servlet.jsp.tagext.JspFragment ");
        } else {
            out.print(JspUtil.toJavaSourceType(attrInfos[i].getTypeName()));
            out.print(" ");
        }
        out.print(toGetterMethod(attrInfos[i].getName()));
        out.println(" {");
        out.pushIndent();
        out.printin("return this.");
        out.print(javaName);
        out.println(";");
        out.popIndent();
        out.printil("}");
        out.println();

        // setter method
        out.printin("public void ");
        out.print(toSetterMethodName(attrInfos[i].getName()));
        if (attrInfos[i].isFragment()) {
            out.print("(javax.servlet.jsp.tagext.JspFragment ");
        } else {
            out.print("(");
            out.print(JspUtil.toJavaSourceType(attrInfos[i].getTypeName()));
            out.print(" ");
        }
        out.print(javaName);
        out.println(") {");
        out.pushIndent();
        out.printin("this.");
        out.print(javaName);
        out.print(" = ");
        out.print(javaName);
        out.println(";");
        if (ctxt.isTagFile()) {
            // Tag files should also set jspContext attributes
            out.printin("jspContext.setAttribute(\"");
            out.print(attrInfos[i].getName());
            out.print("\", ");
            out.print(javaName);
            out.println(");");
        }
        out.popIndent();
        out.printil("}");
        out.println();
    }
}
 
Example 13
Source File: Validator.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public void visit(Node.CustomTag n) throws JasperException {

	    TagInfo tagInfo = n.getTagInfo();
	    if (tagInfo == null) {
		err.jspError(n, "jsp.error.missing.tagInfo", n.getQName());
	    }

	    /*
	     * The bodycontent of a SimpleTag cannot be JSP.
	     */
	    if (n.implementsSimpleTag() &&
                tagInfo.getBodyContent().equals(TagInfo.BODY_CONTENT_JSP)) {
                err.jspError(n, "jsp.error.simpletag.badbodycontent",
                             tagInfo.getTagClassName());
	    }

	    /*
	     * If the tag handler declares in the TLD that it supports dynamic
	     * attributes, it also must implement the DynamicAttributes
	     * interface.
	     */
	    if (tagInfo.hasDynamicAttributes()
		    && !n.implementsDynamicAttributes()) {
		err.jspError(n, "jsp.error.dynamic.attributes.not.implemented",
			     n.getQName());
	    }

	    /*
	     * Make sure all required attributes are present, either as
             * attributes or named attributes (<jsp:attribute>).
 	     * Also make sure that the same attribute is not specified in
	     * both attributes or named attributes.
	     */
	    TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
	    String customActionUri = n.getURI();
	    Attributes attrs = n.getAttributes();
	    int attrsSize = (attrs == null) ? 0 : attrs.getLength();
	    for (int i=0; i<tldAttrs.length; i++) {
		String attr = null;
		if (attrs != null) {
		    attr = attrs.getValue(tldAttrs[i].getName());
		    if (attr == null) {
			attr = attrs.getValue(customActionUri,
					      tldAttrs[i].getName());
		    }
		}
		Node.NamedAttribute na =
			n.getNamedAttributeNode(tldAttrs[i].getName());
		
		if (tldAttrs[i].isRequired() && attr == null && na == null) {
		    err.jspError(n, "jsp.error.missing_attribute",
				 tldAttrs[i].getName(), n.getLocalName());
		}
		if (attr != null && na != null) {
		    err.jspError(n, "jsp.error.duplicate.name.jspattribute",
			tldAttrs[i].getName());
		}
	    }

            Node.Nodes naNodes = n.getNamedAttributeNodes();
	    int jspAttrsSize = naNodes.size() + attrsSize;
	    Node.JspAttribute[] jspAttrs = null;
	    if (jspAttrsSize > 0) {
		jspAttrs = new Node.JspAttribute[jspAttrsSize];
	    }
	    Hashtable<String, Object> tagDataAttrs =
                    new Hashtable<String, Object>(attrsSize);

	    checkXmlAttributes(n, jspAttrs, tagDataAttrs);
            checkNamedAttributes(n, jspAttrs, attrsSize, tagDataAttrs);

	    TagData tagData = new TagData(tagDataAttrs);

	    // JSP.C1: It is a (translation time) error for an action that
	    // has one or more variable subelements to have a TagExtraInfo
	    // class that returns a non-null object.
	    TagExtraInfo tei = tagInfo.getTagExtraInfo();
	    if (tei != null
		    && tei.getVariableInfo(tagData) != null
		    && tei.getVariableInfo(tagData).length > 0
		    && tagInfo.getTagVariableInfos().length > 0) {
		err.jspError("jsp.error.non_null_tei_and_var_subelems",
			     n.getQName());
	    }

	    n.setTagData(tagData);
	    n.setJspAttributes(jspAttrs);

	    visitBody(n);
	}
 
Example 14
Source File: Validator.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
private void checkNamedAttributes(Node.CustomTag n,
				  Node.JspAttribute[] jspAttrs,
				  int start,
				  Hashtable<String,Object> tagDataAttrs)
        throws JasperException {

    TagInfo tagInfo = n.getTagInfo();
    if (tagInfo == null) {
	err.jspError(n, "jsp.error.missing.tagInfo", n.getQName());
    }
    TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
           Node.Nodes naNodes = n.getNamedAttributeNodes();

    for (int i=0; i<naNodes.size(); i++) {
               Node.NamedAttribute na = (Node.NamedAttribute)
	    naNodes.getNode(i);
	boolean found = false;
	for (int j=0; j<tldAttrs.length; j++) {
	    /*
	     * See above comment about namespace matches. For named
	     * attributes, we use the prefix instead of URI as the
	     * match criterion, because in the case of a JSP document,
	     * we'd have to keep track of which namespaces are in scope
	     * when parsing a named attribute, in order to determine
	     * the URI that the prefix of the named attribute's name
	     * matches to.
	     */
	    String attrPrefix = na.getPrefix();
	    if (na.getLocalName().equals(tldAttrs[j].getName())
		    && (attrPrefix == null || attrPrefix.length() == 0
			|| attrPrefix.equals(n.getPrefix()))) {
		jspAttrs[start + i] = new Node.JspAttribute(na, false);
		NamedAttributeVisitor nav = null;
		if (na.getBody() != null) {
		    nav = new NamedAttributeVisitor();
		    na.getBody().visit(nav);
		}
		if (nav != null && nav.hasDynamicContent()) {
		    tagDataAttrs.put(na.getName(),
				     TagData.REQUEST_TIME_VALUE);
		} else {
		    tagDataAttrs.put(na.getName(), na.getText());    
		}
		found = true;
		break;
	    }
	}
	if (!found) {
	    if (tagInfo.hasDynamicAttributes()) {
		jspAttrs[start + i] = new Node.JspAttribute(na, true);
	    } else {
		err.jspError(n, "jsp.error.bad_attribute",
			     na.getName(), n.getLocalName());
	    }
	}
    }
}
 
Example 15
Source File: Parser.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
/**
    * 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;
   }
 
Example 16
Source File: Generator.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Generates declarations for tag handler attributes, and defines the
 * getter and setter methods for each.
 */
private void generateTagHandlerAttributes(TagInfo tagInfo)
    throws JasperException {

    if (tagInfo.hasDynamicAttributes()) {
        out.printil(
            "private java.util.HashMap _jspx_dynamic_attrs = new java.util.HashMap();");
    }

    // Declare attributes
    TagAttributeInfo[] attrInfos = tagInfo.getAttributes();
    for (int i = 0; i < attrInfos.length; i++) {
        out.printin("private ");
        if (attrInfos[i].isFragment()) {
            out.print("javax.servlet.jsp.tagext.JspFragment ");
        } else {
            out.print(JspUtil.toJavaSourceType(attrInfos[i].getTypeName()));
            out.print(" ");
        }
        out.print(attrInfos[i].getName());
        out.println(";");
    }
    out.println();

    // Define attribute getter and setter methods
    for (int i = 0; i < attrInfos.length; i++) {
        // getter method
        out.printin("public ");
        if (attrInfos[i].isFragment()) {
            out.print("javax.servlet.jsp.tagext.JspFragment ");
        } else {
            out.print(JspUtil.toJavaSourceType(attrInfos[i].getTypeName()));
            out.print(" ");
        }
        out.print(toGetterMethod(attrInfos[i].getName()));
        out.println(" {");
        out.pushIndent();
        out.printin("return this.");
        out.print(attrInfos[i].getName());
        out.println(";");
        out.popIndent();
        out.printil("}");
        out.println();

        // setter method
        out.printin("public void ");
        out.print(toSetterMethodName(attrInfos[i].getName()));
        if (attrInfos[i].isFragment()) {
            out.print("(javax.servlet.jsp.tagext.JspFragment ");
        } else {
            out.print("(");
            out.print(JspUtil.toJavaSourceType(attrInfos[i].getTypeName()));
            out.print(" ");
        }
        out.print(attrInfos[i].getName());
        out.println(") {");
        out.pushIndent();
        out.printin("this.");
        out.print(attrInfos[i].getName());
        out.print(" = ");
        out.print(attrInfos[i].getName());
        out.println(";");
        out.popIndent();
        out.printil("}");
        out.println();
    }
}