luehe       2002/09/19 16:21:40

  Modified:    jasper2/src/share/org/apache/jasper/compiler Generator.java
                        JspUtil.java Validator.java
  Log:
  Fixed 12718: A variable scoped within a fragment in a tag file is
               always expsed as a string
  
  Revision  Changes    Path
  1.102     +67 -10    
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.101
  retrieving revision 1.102
  diff -u -r1.101 -r1.102
  --- Generator.java    13 Sep 2002 00:29:48 -0000      1.101
  +++ Generator.java    19 Sep 2002 23:21:39 -0000      1.102
  @@ -587,7 +587,7 @@
                       
                       JspUtil.FunctionSignature functionSignature = 
                           new JspUtil.FunctionSignature( fnSignature, 
  -                        tli.getShortName(), err );
  +                        tli.getShortName(), err, ctxt.getClassLoader() );
                       out.print( quote( functionSignature.getMethodName() ) );
                       out.print(", ");
                       Class[] args = functionSignature.getParameterTypes();
  @@ -701,6 +701,7 @@
        private FragmentHelperClass fragmentHelperClass;
        private int methodNesting;
        private TagInfo tagInfo;
  +     private ClassLoader loader;
   
        /**
         * Constructor.
  @@ -709,11 +710,13 @@
                               ServletWriter out, 
                               MethodsBuffer methodsBuffer, 
                               FragmentHelperClass fragmentHelperClass,
  +                            ClassLoader loader,
                               TagInfo tagInfo) {
            this.isTagFile = isTagFile;
            this.out = out;
            this.methodsBuffer = methodsBuffer;
            this.fragmentHelperClass = fragmentHelperClass;
  +         this.loader = loader;
            this.tagInfo = tagInfo;
            methodNesting = 0;
            handlerInfos = new Hashtable();
  @@ -1831,21 +1834,66 @@
             */
            class ParamVisitor extends Node.Visitor {
   
  +             // The name of the fragment to which the <jsp:param> applies
  +             private String fragName;
  +
  +             public ParamVisitor(String fragName) {
  +                 this.fragName = fragName;
  +             }
  +
                   public void visit(Node.ParamAction n) throws JasperException {
                    out.printin("_jspx_params.put(");
                    out.print(quote(n.getTextAttribute("name")));
                    out.print(", ");
                    out.print(attributeValue(n.getValue(), false,
  -                                          String.class, "null"));
  +                                          getParamClass(n), "null"));
                    out.println(");");
                }
  +
  +             /*
  +              * Checks to see if the given <jsp:param> matches a tag file
  +              * variable scoped to the same fragment as the enclosing
  +              * <jsp:invoke>. If a match is found, the class specified in
  +              * the variable directive's 'variable-class' attribute (if 
  +              * present) is loaded and returned.
  +              */
  +             private Class getParamClass(Node.ParamAction n)
  +                         throws JasperException {
  +
  +                 Class clazz = String.class;
  +
  +                 TagVariableInfo[] tagVars = tagInfo.getTagVariableInfos();
  +                 if (tagVars != null) {
  +                     String paramName = n.getTextAttribute("name");
  +                     for (int i=0; i<tagVars.length; i++) {
  +                         String varName = tagVars[i].getNameGiven();
  +                         if (varName == null) {
  +                             // XXX name-from-attribute:
  +                             // What to do in this case?
  +                         }
  +                         String tagVarFrag = tagVars[i].getFragment();
  +                         if (!paramName.equals(varName)
  +                                 || tagVarFrag == null
  +                                 || !this.fragName.equals(tagVarFrag))
  +                             continue;
  +                         try {
  +                             clazz = JspUtil.toClass(tagVars[i].getClassName(), 
loader);
  +                         } catch (ClassNotFoundException cnfe) {
  +                             throw new JasperException(cnfe);
  +                         }
  +                     }
  +                 }
  +
  +                 return clazz;
  +             }
            }
   
            // Assemble parameter map
            out.printil("_jspx_params = new java.util.HashMap();");
            if (n.getBody() != null) {
                prepareParams(n);
  -             n.getBody().visit(new ParamVisitor());
  +             n.getBody().visit(new ParamVisitor(
  +                                            n.getTextAttribute("fragment")));
            }
            
            // Invoke fragment with parameter map
  @@ -1903,10 +1951,14 @@
                n.getBody().visit(new ParamVisitor());
            }
   
  -         // Add AT_BEGIN and NESTED scripting variables to parameter map
  +         // Add AT_BEGIN and NESTED scripting variables (that are not 
  +         // scoped to any fragment) to parameter map
            TagVariableInfo[] tagVars = tagInfo.getTagVariableInfos();
            if (tagVars != null) {
                for (int i=0; i<tagVars.length; i++) {
  +                 if (tagVars[i].getFragment() != null) {
  +                     continue;
  +                 }
                    int scope = tagVars[i].getScope();
                    if (scope != VariableInfo.AT_BEGIN
                            && scope != VariableInfo.NESTED) {
  @@ -2878,17 +2930,22 @@
            }
   
            gen.fragmentHelperClass.generatePreamble();
  -         page.visit(gen.new GenerateVisitor(gen.ctxt.isTagFile(), out,
  +         page.visit(gen.new GenerateVisitor(gen.ctxt.isTagFile(),
  +                                            out,
                                               gen.methodsBuffer,
                                               gen.fragmentHelperClass,
  +                                            gen.ctxt.getClassLoader(),
                                               tagInfo));
            gen.generateTagHandlerPostamble(  tagInfo );
        } else {
            gen.generatePreamble(page);
            gen.fragmentHelperClass.generatePreamble();
  -         page.visit(gen.new GenerateVisitor(gen.ctxt.isTagFile(), out,
  +         page.visit(gen.new GenerateVisitor(gen.ctxt.isTagFile(),
  +                                            out,
                                               gen.methodsBuffer, 
  -                                            gen.fragmentHelperClass, null));
  +                                            gen.fragmentHelperClass,
  +                                            gen.ctxt.getClassLoader(),
  +                                            null));
            gen.generatePostamble(page);
        }
       }
  
  
  
  1.17      +8 -7      
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspUtil.java
  
  Index: JspUtil.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspUtil.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- JspUtil.java      4 Sep 2002 16:58:57 -0000       1.16
  +++ JspUtil.java      19 Sep 2002 23:21:39 -0000      1.17
  @@ -538,7 +538,8 @@
        * name represents a primitive type, in which case it is converted to a
        * <tt>Class</tt> object by appending ".class" to it (e.g., "int.class").
        */
  -    public static Class toClass(String type) throws ClassNotFoundException {
  +    public static Class toClass(String type, ClassLoader loader)
  +         throws ClassNotFoundException {
        if ("boolean".equals(type))
            return boolean.class;
        else if ("char".equals(type))
  @@ -556,7 +557,7 @@
        else if ("double".equals(type))
            return double.class;
        else
  -         return Class.forName(type);
  +         return loader.loadClass(type);
       }
   
       /**
  @@ -715,7 +716,7 @@
            *     signature.
            */
           public FunctionSignature( String signature, String tagName,
  -            ErrorDispatcher err )
  +            ErrorDispatcher err, ClassLoader loader )
               throws JasperException
           {
               try {
  @@ -763,7 +764,7 @@
                                   tagName, this.methodName ) );
                           }
   
  -                        parameterTypes.add(toClass(argType));
  +                        parameterTypes.add(toClass(argType, loader));
   
                           String comma;
                           do {
  
  
  
  1.38      +14 -9     
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Validator.java
  
  Index: Validator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Validator.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- Validator.java    17 Sep 2002 20:21:25 -0000      1.37
  +++ Validator.java    19 Sep 2002 23:21:39 -0000      1.38
  @@ -358,7 +358,8 @@
        private ErrorDispatcher err;
        private TagInfo tagInfo;
        private TagData tagData;
  -        
  +        private ClassLoader loader;
  +
        // A FunctionMapper, used to validate EL expressions.
           private FunctionMapper functionMapper;
   
  @@ -442,8 +443,9 @@
            this.err = compiler.getErrorDispatcher();
            this.tagInfo = compiler.getCompilationContext().getTagInfo();
            this.tagData = compiler.getCompilationContext().getTagData();
  +         this.loader = compiler.getCompilationContext().getClassLoader();
               this.functionMapper = new ValidatorFunctionMapper( this.pageInfo, 
  -                this.err );
  +                this.err, this.loader );
        }
   
        public void visit(Node.JspRoot n) throws JasperException {
  @@ -710,7 +712,8 @@
                                       expectedType = JspFragment.class;
                                   }
                                   else if( typeStr != null ) {
  -                                    expectedType = JspUtil.toClass( typeStr );
  +                                    expectedType = JspUtil.toClass(typeStr,
  +                                                                loader);
                                   }
                                   jspAttrs[i]
                                       = getJspAttribute(attrs.getQName(i),
  @@ -1209,7 +1212,8 @@
       {
           private PageInfo pageInfo;
           private ErrorDispatcher err;
  -        
  +        private ClassLoader loader;
  +
           /**
            * HashMap of cached functions that we already looked up.
            * Key = prefix, value = HashMap, where key = localName,
  @@ -1218,10 +1222,11 @@
           private HashMap cachedFunctions = new HashMap();
           
           public ValidatorFunctionMapper( PageInfo pageInfo, 
  -            ErrorDispatcher err ) 
  +            ErrorDispatcher err, ClassLoader loader ) 
           {
               this.pageInfo = pageInfo;
               this.err = err;
  +         this.loader = loader;
           }
           
           public Method resolveFunction( String prefix, String localName ) {
  @@ -1251,7 +1256,7 @@
                               JspUtil.FunctionSignature functionSignature = 
                                   new JspUtil.FunctionSignature( 
                                   fnInfo.getFunctionSignature(),
  -                                info.getShortName(), this.err );
  +                                info.getShortName(), this.err, this.loader );
                               Class c = Class.forName( clazz );
                               result = c.getDeclaredMethod( 
                                   functionSignature.getMethodName(),
  
  
  

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

Reply via email to