luehe 2002/12/13 10:06:08 Modified: jasper2/src/share/org/apache/jasper/compiler Node.java Validator.java Log: Implemented JSP 2.0 clarification for TagData.getAttribute() regarding named attributes: If a static value is specified for an attribute that accepts a request-time attribute expression then that static value is returned, even if the value is provided in the body of a <jsp:attribute> action. The distinguished object REQUEST_TIME_VALUE is only returned if the value is specified as a request-time attribute expression or via the <jsp:attribute> with a body that contains dynamic content (scriptlets, scripting expressions, EL expressions, standard actions, or custom actions). Returns null if the attribute is not set. Revision Changes Path 1.48 +39 -31 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.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- Node.java 12 Dec 2002 03:30:58 -0000 1.47 +++ Node.java 13 Dec 2002 18:06:08 -0000 1.48 @@ -145,16 +145,6 @@ * from the attribute of the node, or from a jsp:attrbute */ public String getTextAttribute(String name) { - class AttributeVisitor extends Visitor { - String attrValue = null; - public void visit(TemplateText txt) { - attrValue = new String(txt.getText()); - } - - public String getAttrValue() { - return attrValue; - } - } String attr = getAttributeValue(name); if (attr != null) { @@ -166,19 +156,7 @@ return null; } - // Get the attribute value from named attribute (jsp:attribute) - // Since this method is only for attributes that are not rtexpr, - // we can assume the body of the jsp:attribute is a template text - if (namedAttribute.getBody() != null) { - AttributeVisitor attributeVisitor = new AttributeVisitor(); - try { - namedAttribute.getBody().visit(attributeVisitor); - } catch (JasperException e) { - } - attr = attributeVisitor.getAttrValue(); - } - - return attr; + return namedAttribute.getText(); } /** @@ -922,7 +900,7 @@ */ public static class ChildInfo { private boolean scriptless; // true if the tag and its body - // contians no scripting elements. + // contain no scripting elements. private boolean hasUseBean; private boolean hasIncludeAction; private boolean hasSetProperty; @@ -1368,6 +1346,36 @@ public String getTemporaryVariableName() { return temporaryVariableName; } + + public String getText() { + + class AttributeVisitor extends Visitor { + String attrValue = null; + public void visit(TemplateText txt) { + attrValue = new String(txt.getText()); + } + + public String getAttrValue() { + return attrValue; + } + } + + // Get the attribute value from this named attribute + // (<jsp:attribute>). + // Since this method is only for attributes that are not rtexpr, + // we can assume the body of the jsp:attribute is a template text + String text = null; + if (getBody() != null) { + AttributeVisitor attributeVisitor = new AttributeVisitor(); + try { + getBody().visit(attributeVisitor); + } catch (JasperException e) { + } + text = attributeVisitor.getAttrValue(); + } + + return text; + } } /** @@ -1557,14 +1565,14 @@ * @return true if the value represents an expression that should * be fed to the expression interpreter * @return false for string literals or rtexprvalues that should - * not be interpreter or reevaluated + * not be interpreted or reevaluated */ public boolean isELInterpreterInput() { return el; } /** - * @return true if the value is a string literal know at translation + * @return true if the value is a string literal known at translation * time. */ public boolean isLiteral() { @@ -1654,8 +1662,8 @@ public static class Visitor { /** - * The method provides a place to put actions that are common to - * all nodes. Override this in the child visitor class if need to. + * This method provides a place to put actions that are common to + * all nodes. Override this in the child visitor class if need to. */ protected void doVisit(Node n) throws JasperException { } 1.61 +29 -5 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.60 retrieving revision 1.61 diff -u -r1.60 -r1.61 --- Validator.java 13 Dec 2002 16:27:43 -0000 1.60 +++ Validator.java 13 Dec 2002 18:06:08 -0000 1.61 @@ -821,8 +821,16 @@ if (na.getName().equals(tldAttrs[j].getName())) { jspAttrs[attrs.getLength() + i] = new Node.JspAttribute(na, false); - tagDataAttrs.put(na.getName(), - TagData.REQUEST_TIME_VALUE); + + NamedAttributeVisitor nav = new NamedAttributeVisitor(); + na.getBody().visit(nav); + if (nav.hasDynamicContent()) { + tagDataAttrs.put(na.getName(), + TagData.REQUEST_TIME_VALUE); + } else { + tagDataAttrs.put(na.getName(), + na.getText()); + } found = true; break; } @@ -1048,6 +1056,22 @@ err.jspError(n, "jsp.error.attribute.standard.non_rt_with_expr", attrName, actionName); + } + } + + private static class NamedAttributeVisitor extends Node.Visitor { + private boolean hasDynamicContent; + + public void doVisit(Node n) throws JasperException { + if (!(n instanceof Node.JspText) + && !(n instanceof Node.TemplateText)) { + hasDynamicContent = true; + } + visitBody(n); + } + + public boolean hasDynamicContent() { + return hasDynamicContent; } } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>