--- Generator.java (revision 688768) +++ Generator.java (working copy) @@ -43,6 +43,7 @@ import org.apache.jasper.Constants; import org.apache.jasper.JasperException; import org.apache.jasper.JspCompilationContext; +import org.apache.jasper.compiler.Node.NamedAttribute; import org.apache.jasper.runtime.JspRuntimeLibrary; import org.xml.sax.Attributes; @@ -102,6 +103,11 @@ private GenBuffer charArrayBuffer; + private HashMap variableNamesOfNamedAttributes; + + /** The {@code variableNameCounter} is used to generate different variable names for named attributes. */ + private int variableNameCounter; + /** * @param s * the input string @@ -819,7 +825,7 @@ } return v; } else if (attr.isNamedAttribute()) { - return attr.getNamedAttributeNode().getTemporaryVariableName(); + return getVariableName(attr.getNamedAttributeNode()); } else { if (encode) { return "org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode(" @@ -3128,7 +3134,7 @@ public String generateNamedAttributeValue(Node.NamedAttribute n) throws JasperException { - String varName = n.getTemporaryVariableName(); + String varName = getVariableName(n); // If the only body element for this named attribute node is // template text, we need not generate an extra call to @@ -3183,7 +3189,7 @@ */ public String generateNamedAttributeJspFragment(Node.NamedAttribute n, String tagHandlerVar) throws JasperException { - String varName = n.getTemporaryVariableName(); + String varName = getVariableName(n); out.printin("javax.servlet.jsp.tagext.JspFragment " + varName + " = "); @@ -3324,6 +3330,9 @@ if (isPoolingEnabled) { tagHandlerPoolNames = new Vector(); } + + variableNamesOfNamedAttributes = new HashMap(); + variableNameCounter = 0; } /** @@ -3764,6 +3773,19 @@ } /* + * Returns the variable name of a named attribute. + */ + private String getVariableName(NamedAttribute attribute) { + String name = variableNamesOfNamedAttributes.get(attribute); + if (name == null) { + name = Constants.TEMP_VARIABLE_NAME_PREFIX + (variableNameCounter++); + variableNamesOfNamedAttributes.put(attribute, name); + } + + return name; + } + + /* * Generates the getter method for the given attribute name. */ private String toGetterMethod(String attrName) { --- Node.java (revision 688768) +++ Node.java (working copy) @@ -1842,9 +1842,6 @@ */ public static class NamedAttribute extends Node { - // A unique temporary variable name suitable for code generation - private String temporaryVariableName; - // True if this node is to be trimmed, or false otherwise private boolean trim = true; @@ -1907,17 +1904,6 @@ return trim; } - /** - * @return A unique temporary variable name to store the result in. - * (this probably could go elsewhere, but it's convenient here) - */ - public String getTemporaryVariableName() { - if (temporaryVariableName == null) { - temporaryVariableName = JspUtil.nextTemporaryVariableName(); - } - return temporaryVariableName; - } - /* * Get the attribute value from this named attribute (). * Since this method is only for attributes that are not rtexpr, we can