You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2006/11/02 15:30:41 UTC

svn commit: r470373 - /tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Validator.java

Author: remm
Date: Thu Nov  2 06:30:39 2006
New Revision: 470373

URL: http://svn.apache.org/viewvc?view=rev&rev=470373
Log:
- Redo the checkXmlAttributes method, as I could not sneak in the type checking for litterals that are passed to
  methods (or values, right ?). Unfortunately, some translation time (rather than runtime) errors are needed for these.

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Validator.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Validator.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Validator.java?view=diff&rev=470373&r1=470372&r2=470373
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Validator.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Validator.java Thu Nov  2 06:30:39 2006
@@ -23,7 +23,6 @@
 import java.util.Hashtable;
 import java.util.Iterator;
 
-import javax.el.ELContext;
 import javax.el.ELException;
 import javax.el.ExpressionFactory;
 import javax.el.FunctionMapper;
@@ -1027,43 +1026,86 @@
                             && (attrs.getURI(i) == null
                                     || attrs.getURI(i).length() == 0 || attrs
                                     .getURI(i).equals(n.getURI()))) {
-                        boolean el = true;
-                        boolean deferredValue = false;
-                        if (!tagInfo.getTagLibrary().getRequiredVersion().equals("2.0") 
-                                && attrs.getValue(i).indexOf("#{") != -1) {
-                            el = false;
-                            if (!pageInfo.isELIgnored() && !pageInfo.isDeferredSyntaxAllowedAsLiteral()) {
-                                deferredValue = true;
+                        boolean checkDeferred = !tagInfo.getTagLibrary().getRequiredVersion().equals("2.0");
+                        boolean deferred = false;
+                        boolean deferredValueIsLiteral = false;
+                        boolean expression = isExpression(n, attrs.getValue(i), checkDeferred);
+                        if (checkDeferred && attrs.getValue(i).indexOf("#{") != -1) {
+                            deferred = true;
+                            if (pageInfo.isELIgnored()) {
+                                deferredValueIsLiteral = true;
                             }
                         }
-                        if ((el && tldAttrs[j].canBeRequestTime())
-                                || (deferredValue && tldAttrs[j].isDeferredMethod()) // JSP 2.1
-                                || (deferredValue && tldAttrs[j].isDeferredValue())) { // JSP 2.1
-                            Class expectedType = String.class;
-                            try {
-                                String typeStr = tldAttrs[j].getTypeName();
-                                if (tldAttrs[j].isFragment()) {
-                                    expectedType = JspFragment.class;
-                                } else if (typeStr != null) {
-                                    expectedType = JspUtil.toClass(typeStr,
-                                            loader);
+                        
+                        /*System.out.println("attrs.getLocalName(i): " + attrs.getLocalName(i));
+                        System.out.println("tldAttrs[j].canBeRequestTime(): " + tldAttrs[j].canBeRequestTime());
+                        System.out.println("expression: " + expression);
+                        System.out.println("tldAttrs[j].isDeferredMethod(): " + tldAttrs[j].isDeferredMethod());
+                        System.out.println("tldAttrs[j].isDeferredValue(): " + tldAttrs[j].isDeferredValue());*/
+                        
+                        if (tldAttrs[j].canBeRequestTime()
+                                || tldAttrs[j].isDeferredMethod() || tldAttrs[j].isDeferredValue()) { // JSP 2.1
+                            
+                            if (!expression) {
+                                
+                                if (deferredValueIsLiteral && !pageInfo.isDeferredSyntaxAllowedAsLiteral()) {
+                                    err.jspError(n, "jsp.error.attribute.custom.non_rt_with_expr",
+                                            tldAttrs[j].getName());
+                                }
+                                
+                                if (tldAttrs[j].isDeferredMethod()) {
+                                    // The String litteral must be castable to what is declared as type
+                                    // for the attribute
+                                    
+                                }
+                                if (tldAttrs[j].isDeferredValue()) {
+                                    // The String litteral must be castable to what is declared as type
+                                    // for the attribute
+                                    
+                                }
+
+                                jspAttrs[i] = new Node.JspAttribute(tldAttrs[j],
+                                        attrs.getQName(i), attrs.getURI(i), attrs
+                                                .getLocalName(i),
+                                        attrs.getValue(i), false, null, false);
+                            } else {
+                                
+                                if (deferred && !tldAttrs[j].isDeferredMethod() && !tldAttrs[j].isDeferredValue()) {
+                                    // No deferred expressions allowed for this attribute
+                                    err.jspError(n, "jsp.error.attribute.custom.non_rt_with_expr",
+                                            tldAttrs[j].getName());
+                                }
+                                if (!deferred && (tldAttrs[j].isDeferredMethod() || tldAttrs[j].isDeferredValue())) {
+                                    // Only deferred expressions are allowed for this attribute
+                                    err.jspError(n, "jsp.error.attribute.custom.non_rt_with_expr",
+                                            tldAttrs[j].getName());
+                                }
+                                
+                                Class expectedType = String.class;
+                                try {
+                                    String typeStr = tldAttrs[j].getTypeName();
+                                    if (tldAttrs[j].isFragment()) {
+                                        expectedType = JspFragment.class;
+                                    } else if (typeStr != null) {
+                                        expectedType = JspUtil.toClass(typeStr,
+                                                loader);
+                                    }
+                                    jspAttrs[i] = getJspAttribute(tldAttrs[j],
+                                            attrs.getQName(i), attrs.getURI(i),
+                                            attrs.getLocalName(i), attrs
+                                            .getValue(i), expectedType, n,
+                                            false);
+                                } catch (ClassNotFoundException e) {
+                                    err.jspError
+                                        (n, "jsp.error.unknown_attribute_type",
+                                         tldAttrs[j].getName(), tldAttrs[j].getTypeName());
                                 }
-                                jspAttrs[i] = getJspAttribute(tldAttrs[j],
-                                        attrs.getQName(i), attrs.getURI(i),
-                                        attrs.getLocalName(i), attrs
-                                                .getValue(i), expectedType, n,
-                                        false);
-                            } catch (ClassNotFoundException e) {
-                                err.jspError(n,
-                                        "jsp.error.unknown_attribute_type",
-                                        tldAttrs[j].getName(), tldAttrs[j]
-                                                .getTypeName());
                             }
+                            
                         } else {
                             // Attribute does not accept any expressions.
                             // Make sure its value does not contain any.
-                            if (isExpression(n, attrs.getValue(i), 
-                                    !tagInfo.getTagLibrary().getRequiredVersion().equals("2.0"))) {
+                            if (expression) {
                                 err.jspError(n, "jsp.error.attribute.custom.non_rt_with_expr",
                                                 tldAttrs[j].getName());
                             }
@@ -1196,7 +1238,8 @@
                     // expression(s)
                     ELNode.Nodes el = ELParser.parse(value);
 
-                    if (el.containsEL() && !pageInfo.isELIgnored()) {
+                    if (el.containsEL() && !pageInfo.isELIgnored()
+                            && (!pageInfo.isDeferredSyntaxAllowedAsLiteral() && value.startsWith("#{"))) {
                         validateFunctions(el, n);
 
                         result = new Node.JspAttribute(tai, qName, uri,



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