You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ki...@apache.org on 2003/12/04 20:37:58 UTC

cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources messages.properties messages_es.properties messages_fr.properties messages_ja.properties

kinman      2003/12/04 11:37:58

  Modified:    jasper2/src/share/org/apache/jasper/compiler Parser.java
                        TagFileProcessor.java
               jasper2/src/share/org/apache/jasper/resources
                        messages.properties messages_es.properties
                        messages_fr.properties messages_ja.properties
  Log:
  - Rewrite error checking when processing tag files to conform with the
    lastest JSP spec.  Check that names declared in any of the following
    in a translation unit is unique.
    * name attribute in attribute directive
    * name-given attribute in variable directive
    * alias attribute in variable directive
    * dynamic-attributes attribute in tag directive
  
    except that dynamic-attributes attribute of the tag directive can be declared
    more than once with the same value.
  
    Also check that name-from-attribute attributes of variable directives are
    unique, and that they refer to attribte directives declared in the same
    translation unit, with the correct attribute values.
  
  Revision  Changes    Path
  1.85      +4 -3      jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java,v
  retrieving revision 1.84
  retrieving revision 1.85
  diff -u -r1.84 -r1.85
  --- Parser.java	29 Oct 2003 21:53:43 -0000	1.84
  +++ Parser.java	4 Dec 2003 19:37:58 -0000	1.85
  @@ -1942,6 +1942,7 @@
   	reader.setSingleFile(true);
   	reader.skipUntil("<");
           while (reader.hasMoreInput()) {
  +            start = reader.mark();
               if (reader.matches("%--")) {
                   parseComment(parent);
               } else if (reader.matches("%@")) {
  
  
  
  1.53      +114 -93   jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagFileProcessor.java
  
  Index: TagFileProcessor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagFileProcessor.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- TagFileProcessor.java	2 Sep 2003 21:39:59 -0000	1.52
  +++ TagFileProcessor.java	4 Dec 2003 19:37:58 -0000	1.53
  @@ -68,6 +68,7 @@
   import java.net.URLClassLoader;
   import java.util.Iterator;
   import java.util.Vector;
  +import java.util.HashMap;
   
   import javax.servlet.jsp.tagext.TagAttributeInfo;
   import javax.servlet.jsp.tagext.TagExtraInfo;
  @@ -145,6 +146,19 @@
           private Vector attributeVector;
           private Vector variableVector;
   
  +        private static final String ATTR_NAME =
  +            "the name attribute of the attribute directive";
  +        private static final String VAR_NAME_GIVEN =
  +            "the name-given attribute of the variable directive";
  +        private static final String VAR_NAME_FROM =
  +            "the name-from-attribute attribute of the variable directive";
  +        private static final String VAR_ALIAS =
  +            "the alias attribute of the variable directive";
  +        private static final String TAG_DYNAMIC =
  +            "the dynamic-attributes attribute of the tag directive";
  +        private HashMap nameTable = new HashMap();
  +        private HashMap nameFromTable = new HashMap();
  +
           public TagFileDirectiveVisitor(Compiler compiler,
                                          TagLibraryInfo tagLibInfo,
                                          String name,
  @@ -171,6 +185,9 @@
                                bodycontent);
               }
               dynamicAttrsMapName = n.getAttributeValue("dynamic-attributes");
  +            if (dynamicAttrsMapName != null) {
  +                checkUniqueName(dynamicAttrsMapName, TAG_DYNAMIC, n);
  +            }
               smallIcon = n.getAttributeValue("small-icon");
               largeIcon = n.getAttributeValue("large-icon");
               description = n.getAttributeValue("description");
  @@ -210,9 +227,11 @@
                       type = "java.lang.String";
               }
   
  -            attributeVector.addElement(
  +            TagAttributeInfo tagAttributeInfo =
                       new TagAttributeInfo(attrName, required, type, rtexprvalue,
  -                                         fragment));
  +                                         fragment);
  +            attributeVector.addElement(tagAttributeInfo);
  +            checkUniqueName(attrName, ATTR_NAME, n, tagAttributeInfo);
           }
   
           public void visit(Node.VariableDirective n) throws JasperException {
  @@ -265,6 +284,12 @@
   		 * denotes the name of the variable that is being aliased
   		 */
                   nameGiven = alias;
  +                checkUniqueName(nameFromAttribute, VAR_NAME_FROM, n);
  +                checkUniqueName(alias, VAR_ALIAS, n);
  +            }
  +            else {
  +                // name-given specified
  +                checkUniqueName(nameGiven, VAR_NAME_GIVEN, n);
               }
                   
               variableVector.addElement(new TagVariableInfo(
  @@ -332,6 +357,90 @@
   			       tagVariableInfos,
   			       dynamicAttrsMapName);
           }
  +
  +        static class NameEntry {
  +            private String type;
  +            private Node node;
  +            private TagAttributeInfo attr;
  +
  +            NameEntry(String type, Node node, TagAttributeInfo attr) {
  +                this.type = type;
  +                this.node = node;
  +                this.attr = attr;
  +            }
  +
  +            String getType() { return type;}
  +            Node getNode() { return node; }
  +            TagAttributeInfo getTagAttributeInfo() { return attr; }
  +        }
  +
  +        /**
  +         * Reports a translation error if names specified in attributes of
  +         * directives are not unique in this translation unit.
  +         *
  +         * The value of the following attributes must be unique.
  +         *   1. 'name' attribute of an attribute directive
  +         *   2. 'name-given' attribute of a variable directive
  +         *   3. 'alias' attribute of variable directive
  +         *   4. 'dynamic-attributes' of a tag directive
  +         * except that 'dynamic-attributes' can (and must) have the same
  +         * value when it appears in multiple tag directives.
  +         *
  +         * Also, 'name-from' attribute of a variable directive cannot have
  +         * the same value as that from another variable directive.
  +         */
  +        private void checkUniqueName(String name, String type, Node n)
  +                throws JasperException {
  +            checkUniqueName(name, type, n, null);
  +        }
  +
  +        private void checkUniqueName(String name, String type, Node n,
  +                                     TagAttributeInfo attr)
  +                throws JasperException {
  +
  +            HashMap table = (type == VAR_NAME_FROM)? nameFromTable: nameTable;
  +            NameEntry nameEntry = (NameEntry) table.get(name);
  +            if (nameEntry != null) {
  +                if (type != TAG_DYNAMIC) {
  +                    int line = nameEntry.getNode().getStart().getLineNumber();
  +                    err.jspError(n, "jsp.error.tagfile.nameNotUnique",
  +                         type, nameEntry.getType(), Integer.toString(line));
  +                }
  +            } else {
  +                table.put(name, new NameEntry(type, n, attr));
  +            }
  +        }
  +
  +        /**
  +         * Perform miscellean checks after the nodes are visited.
  +         */
  +        void postCheck() throws JasperException {
  +            // Check that var.name-from-attributes has valid values.
  +	    Iterator iter = nameFromTable.keySet().iterator();
  +            while (iter.hasNext()) {
  +                String nameFrom = (String) iter.next();
  +                NameEntry nameEntry = (NameEntry) nameTable.get(nameFrom);
  +                NameEntry nameFromEntry =
  +                    (NameEntry) nameFromTable.get(nameFrom);
  +                Node nameFromNode = nameFromEntry.getNode();
  +                if (nameEntry == null) {
  +                    err.jspError(nameFromNode,
  +                                 "jsp.error.tagfile.nameFrom.noAttribute",
  +                                 nameFrom);
  +                } else {
  +                    Node node = nameEntry.getNode();
  +                    TagAttributeInfo tagAttr = nameEntry.getTagAttributeInfo();
  +                    if (! "java.lang.String".equals(tagAttr.getTypeName())
  +                            || ! tagAttr.isRequired()
  +                            || tagAttr.canBeRequestTime()){
  +                        err.jspError(nameFromNode,
  +                            "jsp.error.tagfile.nameFrom.badAttribute",
  +                            nameFrom,
  +                            Integer.toString(node.getStart().getLineNumber()));
  +                     }
  +                }
  +            }
  +        }
       }
   
       /**
  @@ -367,97 +476,9 @@
               = new TagFileDirectiveVisitor(pc.getCompiler(), tagLibInfo, name,
                                             path);
           page.visit(tagFileVisitor);
  -
  -        /*
  -         * TODO: need to check for uniqueness of attribute name, variable
  -         * name-given, and variable alias.
  -         */
  -
  -        /*
  -         * It is illegal to have a variable.name-given or variable.alias equal
  -         * to an attribute.name in the same tag file translation unit.
  -         */
  -        Iterator attrsIter = tagFileVisitor.getAttributesVector().iterator();
  -        while (attrsIter.hasNext()) {
  -            TagAttributeInfo attrInfo = (TagAttributeInfo) attrsIter.next();
  -            Iterator varsIter = tagFileVisitor.getVariablesVector().iterator();
  -            while (varsIter.hasNext()) {
  -                TagVariableInfo varInfo = (TagVariableInfo) varsIter.next();
  -                String attrName = attrInfo.getName();
  -                if (attrName.equals(varInfo.getNameGiven())) {
  -                    err.jspError("jsp.error.tagfile.var_name_given_equals_attr_name",
  -                                 path, attrName);
  -                }
  -            }
  -        }
  -
  -        /*
  -         * It is illegal to have a variable.name-given equal another
  -         * variable.alias in the same tag file translation unit.
  -         */
  -        Iterator varsIter = tagFileVisitor.getVariablesVector().iterator();
  -        while (varsIter.hasNext()) {
  -            TagVariableInfo varsInfo = (TagVariableInfo) varsIter.next();
  -            if (varsInfo.getNameFromAttribute() == null) {
  -                // Only interested in aliases.
  -                continue;
  -            }
  -            String nameGiven = varsInfo.getNameGiven();
  -
  -            Iterator varsIter2 = tagFileVisitor.getVariablesVector().iterator();
  -            while (varsIter2.hasNext()) {
  -                TagVariableInfo varsInfo2 = (TagVariableInfo) varsIter2.next();
  -                if (varsInfo2.getNameFromAttribute() != null) {
  -                    // Only interest in non-aliases
  -                    continue;
  -                }
  -                if (nameGiven.equals(varsInfo2.getNameGiven())) {
  -                    err.jspError("jsp.error.tagfile.nameGiven_equals.alias",
  -                                path, nameGiven);
  -                }
  -            }
  -        }
  -
  -	checkDynamicAttributesUniqueness(tagFileVisitor, path, err);
  +        tagFileVisitor.postCheck();
   
           return tagFileVisitor.getTagInfo();
  -    }
  -
  -    /*
  -     * Reports a translation error if there is a tag directive with
  -     * a 'dynamic-attributes' attribute equal to the value of a
  -     * 'name-given' attribute of a variable directive or equal to the
  -     * value of a 'name' attribute of an attribute directive in this
  -     * translation unit.
  -     */
  -    private static void checkDynamicAttributesUniqueness(
  -                                            TagFileDirectiveVisitor tfv,
  -					    String path,
  -					    ErrorDispatcher err)
  -	        throws JasperException {
  -
  -	String dynamicAttrsMapName = tfv.getDynamicAttributesMapName();
  -	if (dynamicAttrsMapName == null) {
  -	    return;
  -	}
  -
  -	Iterator attrs = tfv.getAttributesVector().iterator();
  -	while (attrs.hasNext()) {
  -	    TagAttributeInfo attrInfo = (TagAttributeInfo) attrs.next();
  -	    if (dynamicAttrsMapName.equals(attrInfo.getName())) {
  -		err.jspError("jsp.error.tagfile.tag_dynamic_attrs_equals_attr_name",
  -			     path, dynamicAttrsMapName);
  -	    }
  -	}
  -
  -	Iterator vars = tfv.getVariablesVector().iterator();
  -	while (vars.hasNext()) {
  -	    TagVariableInfo varInfo = (TagVariableInfo) vars.next();
  -	    if (dynamicAttrsMapName.equals(varInfo.getNameGiven())) {
  -		err.jspError("jsp.error.tagfile.tag_dynamic_attrs_equals_var_name_given",
  -			     path, dynamicAttrsMapName);
  -	    }
  -	}
       }
   
       /**
  
  
  
  1.135     +5 -5      jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties
  
  Index: messages.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties,v
  retrieving revision 1.134
  retrieving revision 1.135
  diff -u -r1.134 -r1.135
  --- messages.properties	29 Oct 2003 21:53:43 -0000	1.134
  +++ messages.properties	4 Dec 2003 19:37:58 -0000	1.135
  @@ -181,7 +181,7 @@
   jsp.message.adding_jar=Adding jar {0} to my classpath
   jsp.message.compiling_with=Compiling with: {0}
   jsp.message.template_text=template text
  -jsp.error.missing_attribute=According to the TLD attribute {0} is mandatory for tag {1}
  +jsp.error.missing_attribute=According to the TLD or the tag file, attribute {0} is mandatory for tag {1}
   jsp.error.bad_attribute=Attribute {0} invalid for tag {1} according to TLD
   jsp.error.tld.unable_to_read=Unable to read TLD \"{1}\" from JAR file \"{0}\": {2}
   jsp.error.tld.unable_to_get_jar=Unable to get JAR resource \"{0}\" containing TLD: {1}
  @@ -336,9 +336,9 @@
   jsp.error.attribute.standard.non_rt_with_expr=The {0} attribute of the {1} standard action does not accept any expressions
   jsp.error.scripting.variable.missing_name=Unable to determine scripting variable name from attribute {0}
   jasper.error.emptybodycontent.nonempty=According to TLD, tag {0} must be empty, but is not
  -jsp.error.tagfile.var_name_given_equals_attr_name=In tag file {0}, the name-given attribute or the alias attribute of a variable directive equals the name attribute of an attribute directive: {1}
  -jsp.error.tagfile.tag_dynamic_attrs_equals_var_name_given=In tag file {0}, the dynamic-attributes attribute of a tag directive equals the name-given attribute of a variable directive: {1}
  -jsp.error.tagfile.tag_dynamic_attrs_equals_attr_name=In tag file {0}, the dynamic-attributes attribute of a tag directive equals the name attribute of an attribute directive: {1}
  +jsp.error.tagfile.nameNotUnique=The value of {0} and the value of {1} in line {2} are the same.
  +jsp.error.tagfile.nameFrom.noAttribute=Cannot find an attribute directive with a name attribute with a value \"{0}\", the value of this name-from-attribute attribute.
  +jsp.error.tagfile.nameFrom.badAttribute=The attribute directive (declared in line {1} and whose name attribute is \"{0}\", the value of this name-from-attribute attribute) must be of type java.lang.String, is \"required\" and not a \"rtexprvalue\".
   jsp.error.page.noSession=Cannot access session scope in page that does not participate in any session
   jsp.error.useBean.noSession=Illegal for useBean to use session scope when JSP page declares (via page directive) that it does not participate in sessions
   jsp.error.xml.encodingByteOrderUnsupported = Given byte order for encoding \"{0}\" is not supported.
  
  
  
  1.45      +4 -2      jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_es.properties
  
  Index: messages_es.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_es.properties,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- messages_es.properties	15 Aug 2003 00:06:10 -0000	1.44
  +++ messages_es.properties	4 Dec 2003 19:37:58 -0000	1.45
  @@ -211,7 +211,9 @@
   jsp.error.attribute.custom.non_rt_with_expr=
   jsp.error.scripting.variable.missing_name=
   jasper.error.emptybodycontent.nonempty=
  -jsp.error.tagfile.var_name_given_equals_attr_name=
  +jsp.error.tagfile.nameNotUnique=
  +jsp.error.tagfile.nameFrom.noAttribute=
  +jsp.error.tagfile.nameFrom.badAttribute=
   jsp.error.useBean.noSession=
   jsp.error.xml.encodingByteOrderUnsupported=
   jsp.error.xml.encodingDeclInvalid=
  
  
  
  1.30      +4 -2      jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_fr.properties
  
  Index: messages_fr.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_fr.properties,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- messages_fr.properties	15 Aug 2003 00:06:10 -0000	1.29
  +++ messages_fr.properties	4 Dec 2003 19:37:58 -0000	1.30
  @@ -281,7 +281,9 @@
   jsp.error.attribute.custom.non_rt_with_expr=D''apr�s la TLD, l''attribut {0} n''accepte aucune expression
   jsp.error.scripting.variable.missing_name=Incapable de d�terminer le nom de variable scripting d''apr�s l''attribut {0}
   jasper.error.emptybodycontent.nonempty=D''apr�s la TLD, le tag {0} doit �tre vide, mais ne l''est pas
  -jsp.error.tagfile.var_name_given_equals_attr_name=Dans le fichier de tag {0}, l''attribut name-given ({1}) de la directive variable est �gal au nom d''attribut de la directive attribute
  +jsp.error.tagfile.nameNotUnique=
  +jsp.error.tagfile.nameFrom.noAttribute=
  +jsp.error.tagfile.nameFrom.badAttribute=
   jsp.error.useBean.noSession=Il est ill�gal pour useBean d''utiliser une port�e de session (session scope) quand la page JSP indique (via la directive de page) qu''elle ne participe pas aux sessions
   jsp.error.attributes.not.allowed = {0} ne doit avoir aucun attribut
   jsp.error.nested.jspattribute=
  
  
  
  1.48      +4 -4      jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_ja.properties
  
  Index: messages_ja.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_ja.properties,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- messages_ja.properties	1 Dec 2003 21:37:43 -0000	1.47
  +++ messages_ja.properties	4 Dec 2003 19:37:58 -0000	1.48
  @@ -333,9 +333,9 @@
   jsp.error.attribute.standard.non_rt_with_expr={1} \u6a19\u6e96\u30a2\u30af\u30b7\u30e7\u30f3\u306e {0} \u5c5e\u6027\u306f\u3069\u3093\u306a\u5f0f\u3082\u53d7\u3051\u4ed8\u3051\u307e\u305b\u3093
   jsp.error.scripting.variable.missing_name=\u5c5e\u6027 {0} \u304b\u3089\u30b9\u30af\u30ea\u30d7\u30c8\u5909\u6570\u540d\u3092\u6c7a\u5b9a\u3067\u304d\u307e\u305b\u3093
   jasper.error.emptybodycontent.nonempty=TLD\u306b\u5f93\u3063\u3066\u30bf\u30b0 {0} \u306f\u7a7a\u3067\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093\u304c\u3001\u305d\u3046\u3067\u306f\u3042\u308a\u307e\u305b\u3093
  -jsp.error.tagfile.var_name_given_equals_attr_name=\u30bf\u30b0\u30d5\u30a1\u30a4\u30eb {0} \u4e2d\u3067\u3001variable\u6307\u793a\u5b50\u306ename-given\u5c5e\u6027\u53c8\u306falias\u5c5e\u6027 ({1})\u304cattribute\u6307\u793a\u5b50\u306ename\u5c5e\u6027\u3068\u540c\u3058\u3067\u3059
  -jsp.error.tagfile.tag_dynamic_attrs_equals_var_name_given=\u30bf\u30b0\u30d5\u30a1\u30a4\u30eb {0} \u4e2d\u3067\u3001tag\u6307\u793a\u5b50\u306edynamic-attributes\u5c5e\u6027\u304cvariable\u6307\u793a\u5b50\u306ename-given\u5c5e\u6027\u3068\u540c\u3058\u3067\u3059: {1}
  -jsp.error.tagfile.tag_dynamic_attrs_equals_attr_name=\u30bf\u30b0\u30d5\u30a1\u30a4\u30eb {0} \u4e2d\u3067\u3001tag\u6307\u793a\u5b50\u306edynamic-attributes\u5c5e\u6027\u304cattribute\u6307\u793a\u5b50\u306ename\u5c5e\u6027\u3068\u540c\u3058\u3067\u3059: {1}
  +jsp.error.tagfile.nameNotUnique=
  +jsp.error.tagfile.nameFrom.noAttribute=
  +jsp.error.tagfile.nameFrom.badAttribute=
   jsp.error.page.noSession=\u30bb\u30c3\u30b7\u30e7\u30f3\u306b\u52a0\u308f\u3063\u3066\u3044\u306a\u3044\u30da\u30fc\u30b8\u306e\u4e2d\u3067\u306f\u30bb\u30c3\u30b7\u30e7\u30f3\u30b9\u30b3\u30fc\u30d7\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u305b\u3093
   jsp.error.useBean.noSession=JSP\u30da\u30fc\u30b8\u304c(page\u6307\u793a\u5b50\u306b\u3088\u308a)\u30bb\u30c3\u30b7\u30e7\u30f3\u4e2d\u3067\u5354\u8abf\u3057\u306a\u3044\u3053\u3068\u3092\u5ba3\u8a00\u3057\u3066\u3044\u308b\u6642\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u30b9\u30b3\u30fc\u30d7\u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\u306euseBean\u304c\u4e0d\u6b63\u3067\u3059
   jsp.error.xml.encodingByteOrderUnsupported = \u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0 \"{0}\" \u306b\u6307\u5b9a\u3055\u308c\u305f\u30d0\u30a4\u30c8\u30aa\u30fc\u30c0\u306f\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u307e\u305b\u3093
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org