luehe       2002/07/18 14:34:09

  Modified:    jasper2/src/share/org/apache/jasper/compiler Tag:
                        tomcat_4_branch Generator.java Node.java
  Log:
  Fixed Bug# 10670: Problem in JSP compilation
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.35.2.1  +13 -54    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java
  
  Index: Generator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v
  retrieving revision 1.35
  retrieving revision 1.35.2.1
  diff -u -r1.35 -r1.35.2.1
  --- Generator.java    27 Jun 2002 17:32:17 -0000      1.35
  +++ Generator.java    18 Jul 2002 21:34:08 -0000      1.35.2.1
  @@ -1490,64 +1490,23 @@
        }
   
        /*
  -      * Declares any NESTED scripting variables of the given custom tag,
  -      * if the given custom tag is not nested inside itself (i.e, has a
  -      * nesting level of zero). If the custom tag does have a custom nesting
  -      * level greater than 0, this method declares a scripting variable
  -      * derived from the tag's "id" attribute (if present), only if its
  -      * scope is NESTED and it does not match the "id" attribute of any of
  -      * the enclosing tags of the same (custom) type.
  -      *
  -      * Additionally, a NESTED scripting variable is declared only if it
  -      * has not already been declared in the same Java
  -      * scope of the generated code, that is, if this custom tag's parent is
  -      * different from the parent of the custom tag that may already have
  -      * declared this variable.
  +      * Declares any NESTED scripting variables of the given custom tag.
         */
        private void declareNestedScriptingVariables(Node.CustomTag n) {
   
  -         if (n.getCustomNestingLevel() > 0 && !n.hasUnnestedIdAttribute()) {
  -             return;
  -         }
  -
            TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
  -         VariableInfo[] varInfos = n.getVariableInfos();
  -         if ((varInfos == null) && (tagVarInfos == null)) {
  +         VariableInfo[] nestedVarInfos = n.getNestedVariableInfos();
  +         if ((nestedVarInfos == null) && (tagVarInfos == null)) {
                return;
            }
   
  -         if (varInfos != null) {
  -             if (n.getCustomNestingLevel() == 0) {
  -                 // Declare *any* scripting variables with NESTED scope
  -                 for (int i=0; i<varInfos.length; i++) {
  -                     if ((varInfos[i].getScope() == VariableInfo.NESTED)
  -                                 && varInfos[i].getDeclare()) {
  -                         String name = varInfos[i].getVarName();
  -                         out.printin(varInfos[i].getClassName());
  -                         out.print(" ");
  -                         out.print(name);
  -                         out.println(" = null;");
  -                     }
  -                 }
  -             } else {
  -                 /*
  -                  * Declare only scripting variable (with NESTED scope)
  -                  * derived from unnested "id" attribute
  -                  */
  -                 String idAttr = n.getAttributeValue("id");
  -                 for (int i=0; i<varInfos.length; i++) {
  -                     if ((varInfos[i].getScope() == VariableInfo.NESTED)
  -                                 && varInfos[i].getDeclare()) {
  -                         String name = varInfos[i].getVarName();
  -                         if (idAttr.equals(name)) {
  -                             out.printin(varInfos[i].getClassName());
  -                             out.print(" ");
  -                             out.print(name);
  -                             out.println(" = null;");
  -                             break;
  -                         }
  -                     }
  -                 }
  +         if (nestedVarInfos != null) {
  +             for (int i=0; i<nestedVarInfos.length; i++) {
  +                 String name = nestedVarInfos[i].getVarName();
  +                 out.printin(nestedVarInfos[i].getClassName());
  +                 out.print(" ");
  +                 out.print(name);
  +                 out.println(" = null;");
                }
            } else {
                for (int i=0; i<tagVarInfos.length; i++) {
  
  
  
  1.15.2.1  +50 -30    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java
  
  Index: Node.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java,v
  retrieving revision 1.15
  retrieving revision 1.15.2.1
  diff -u -r1.15 -r1.15.2.1
  --- Node.java 21 Jun 2002 00:59:56 -0000      1.15
  +++ Node.java 18 Jul 2002 21:34:08 -0000      1.15.2.1
  @@ -673,8 +673,8 @@
        private String tagHandlerPoolName;
        private TagInfo tagInfo;
        private VariableInfo[] varInfos;
  +     private VariableInfo[] nestedVarInfos;
        private int customNestingLevel;
  -     private boolean hasUnnestedIdAttribute;
   
        public CustomTag(Attributes attrs, Mark start, String name,
                         String prefix, String shortName,
  @@ -685,7 +685,6 @@
            this.shortName = shortName;
            this.tagInfo = tagInfo;
            this.customNestingLevel = computeCustomNestingLevel();
  -         this.hasUnnestedIdAttribute = determineHasUnnestedIdAttribute();
        }
   
        public void accept(Visitor v) throws JasperException {
  @@ -724,6 +723,7 @@
        public void setTagData(TagData tagData) {
            this.tagData = tagData;
            this.varInfos = tagInfo.getVariableInfo(tagData);
  +         determineNestedVarInfos();
        }
   
        public TagData getTagData() {
  @@ -790,13 +790,8 @@
            return varInfos;
        }
   
  -     /*
  -      * Returns true if this custom tag has an "id" attribute that does
  -      * not match the "id" attribute of any of its enclosing parent tags of
  -      * the same custom tag type, and false otherwise. 
  -      */
  -     public boolean hasUnnestedIdAttribute() {
  -         return hasUnnestedIdAttribute;
  +     public VariableInfo[] getNestedVariableInfos() {
  +         return nestedVarInfos;
        }
   
        /*
  @@ -844,35 +839,60 @@
        }
   
        /*
  -      * Checks to see if this custom tag has an "id" attribute that does
  -      * not match the "id" attribute of any of its enclosing parent tags of
  -      * the same custom tag type.
  -      */
  -     private boolean determineHasUnnestedIdAttribute() {
  -         boolean unnested = false;
  -
  -         String id = getAttributeValue("id");
  -         if (id != null) {
  -             if (customNestingLevel == 0) {
  -                 // tag not nested inside itself
  -                 unnested = true;
  -             } else {
  +      * Determines all the scripting variables with NESTED scope contained
  +      * in this custom action's VariableInfo[] that are not already
  +      * contained in the VariableInfo[] of a custom action of the same type
  +      * in the parent chain.
  +      */
  +     private void determineNestedVarInfos() {
  +
  +         if (varInfos == null) {
  +             return;
  +         }
  +
  +         Vector vec = new Vector();
  +
  +         if (customNestingLevel == 0) {
  +             // tag not nested inside itself
  +             for (int i=0; i<varInfos.length; i++) {
  +                 if (varInfos[i].getScope() == VariableInfo.NESTED
  +                         && varInfos[i].getDeclare()) {
  +                     vec.add(varInfos[i]);
  +                 }
  +             }
  +         } else {
  +             for (int i=0; i<varInfos.length; i++) {
  +                 if (varInfos[i].getScope() != VariableInfo.NESTED
  +                         || !varInfos[i].getDeclare()) {
  +                     continue;
  +                 }
                    Node p = parent;
  -                 while (p != null) {
  +                 boolean found = false;
  +                 while ((p != null) && !found) {
                        if ((p instanceof Node.CustomTag)
  -                           && name.equals(((Node.CustomTag) p).name)
  -                           && id.equals(p.getAttributeValue("id"))) {
  -                         break;
  +                             && name.equals(((Node.CustomTag) p).name)) {
  +                         VariableInfo[] parentVarInfos
  +                             = ((Node.CustomTag) p).getVariableInfos();
  +                         for (int j=0; j<parentVarInfos.length; j++) {
  +                             if (varInfos[i].getVarName().equals(
  +                                         parentVarInfos[j].getVarName())) {
  +                                 found = true;
  +                                 break;
  +                             }
  +                         }
                        }
                        p = p.parent;
                    }
                    if (p == null) {
  -                     unnested = true;
  +                     vec.add(varInfos[i]);
                    }
  -             }
  +             }                   
            }
   
  -         return unnested;
  +         if (vec.size() > 0) {
  +             nestedVarInfos =
  +                 (VariableInfo[]) vec.toArray(new VariableInfo[vec.size()]);
  +         }
        }
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to