From 60c601a9701d681fdbb134b6a1ed0df77327aff0 Mon Sep 17 00:00:00 2001 From: remm Date: Thu, 2 Nov 2006 14:30:39 +0000 Subject: [PATCH] - 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. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@470373 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/jasper/compiler/Validator.java | 107 +++++++++++++++++-------- 1 file changed, 75 insertions(+), 32 deletions(-) diff --git a/java/org/apache/jasper/compiler/Validator.java b/java/org/apache/jasper/compiler/Validator.java index a28e22a41..38357c099 100644 --- a/java/org/apache/jasper/compiler/Validator.java +++ b/java/org/apache/jasper/compiler/Validator.java @@ -23,7 +23,6 @@ import java.util.HashMap; 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 @@ class Validator { && (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 @@ class Validator { // 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, -- 2.11.0