- Add translation time type checks for String.
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 2 Nov 2006 22:56:45 +0000 (22:56 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 2 Nov 2006 22:56:45 +0000 (22:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@470584 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/compiler/Validator.java
java/org/apache/jasper/resources/LocalStrings.properties

index 38357c0..f1de408 100644 (file)
@@ -36,6 +36,7 @@ import javax.servlet.jsp.tagext.TagInfo;
 import javax.servlet.jsp.tagext.TagLibraryInfo;
 import javax.servlet.jsp.tagext.ValidationMessage;
 
+import org.apache.el.lang.ELSupport;
 import org.apache.jasper.Constants;
 import org.apache.jasper.JasperException;
 import org.apache.jasper.JspCompilationContext;
@@ -1037,12 +1038,6 @@ class Validator {
                             }
                         }
                         
-                        /*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
                             
@@ -1053,15 +1048,42 @@ class Validator {
                                             tldAttrs[j].getName());
                                 }
                                 
+                                String expectedType = null;
                                 if (tldAttrs[j].isDeferredMethod()) {
                                     // The String litteral must be castable to what is declared as type
                                     // for the attribute
-                                    
+                                    String m = tldAttrs[j].getMethodSignature();
+                                    if (m != null) {
+                                        int rti = m.trim().indexOf(' ');
+                                        if (rti > 0) {
+                                            expectedType = m.substring(0, rti).trim();
+                                        }
+                                    } else {
+                                        expectedType = "java.lang.Object";
+                                    }
                                 }
                                 if (tldAttrs[j].isDeferredValue()) {
                                     // The String litteral must be castable to what is declared as type
                                     // for the attribute
-                                    
+                                    expectedType = tldAttrs[j].getExpectedTypeName();
+                                }
+                                if (expectedType != null) {
+                                    Class expectedClass = String.class;
+                                    try {
+                                        expectedClass = JspUtil.toClass(expectedType, loader);
+                                    } catch (ClassNotFoundException e) {
+                                        err.jspError
+                                            (n, "jsp.error.unknown_attribute_type",
+                                             tldAttrs[j].getName(), expectedType);
+                                    }
+                                    // Check casting
+                                    try {
+                                        ELSupport.coerceToType(attrs.getValue(i), expectedClass);
+                                    } catch (Exception e) {
+                                        err.jspError
+                                            (n, "jsp.error.coerce_to_type",
+                                             tldAttrs[j].getName(), expectedType, attrs.getValue(i));
+                                    }
                                 }
 
                                 jspAttrs[i] = new Node.JspAttribute(tldAttrs[j],
index e86ee33..917f49e 100644 (file)
@@ -337,6 +337,7 @@ jsp.error.var_and_varReader=Only one of \'var\' or \'varReader\' may be specifie
 jsp.error.missing_var_or_varReader=Missing \'var\' or \'varReader\' attribute
 jsp.warning.bad.urlpattern.propertygroup=Bad value {0} in the url-pattern subelement in web.xml
 jsp.error.unknown_attribute_type=Unknown attribute type ({1}) for attribute {0}.
+jsp.error.coerce_to_type=Cannot coerce value ({2}) to type ({1}) for attribute {0}.
 jsp.error.jspelement.missing.name=Mandatory XML-style \'name\' attribute missing
 jsp.error.xmlns.redefinition.notimplemented=Internal error: Attempt to redefine xmlns:{0}.  Redefinition of namespaces is not implemented.
 jsp.error.could.not.add.taglibraries=Could not add one or more tag libraries.