View | Details | Raw Unified | Return to bug 45691
Collapse All | Expand All

(-)Generator.java (-3 / +25 lines)
Lines 43-48 Link Here
43
import org.apache.jasper.Constants;
43
import org.apache.jasper.Constants;
44
import org.apache.jasper.JasperException;
44
import org.apache.jasper.JasperException;
45
import org.apache.jasper.JspCompilationContext;
45
import org.apache.jasper.JspCompilationContext;
46
import org.apache.jasper.compiler.Node.NamedAttribute;
46
import org.apache.jasper.runtime.JspRuntimeLibrary;
47
import org.apache.jasper.runtime.JspRuntimeLibrary;
47
import org.xml.sax.Attributes;
48
import org.xml.sax.Attributes;
48
49
Lines 102-107 Link Here
102
103
103
    private GenBuffer charArrayBuffer;
104
    private GenBuffer charArrayBuffer;
104
105
106
    private HashMap<NamedAttribute, String> variableNamesOfNamedAttributes;
107
108
    /** The {@code variableNameCounter} is used to generate different variable names for named attributes. */
109
    private int variableNameCounter;
110
105
    /**
111
    /**
106
     * @param s
112
     * @param s
107
     *            the input string
113
     *            the input string
Lines 819-825 Link Here
819
                }
825
                }
820
                return v;
826
                return v;
821
            } else if (attr.isNamedAttribute()) {
827
            } else if (attr.isNamedAttribute()) {
822
                return attr.getNamedAttributeNode().getTemporaryVariableName();
828
                return getVariableName(attr.getNamedAttributeNode());
823
            } else {
829
            } else {
824
                if (encode) {
830
                if (encode) {
825
                    return "org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode("
831
                    return "org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode("
Lines 3128-3134 Link Here
3128
        public String generateNamedAttributeValue(Node.NamedAttribute n)
3134
        public String generateNamedAttributeValue(Node.NamedAttribute n)
3129
                throws JasperException {
3135
                throws JasperException {
3130
3136
3131
            String varName = n.getTemporaryVariableName();
3137
            String varName = getVariableName(n);
3132
3138
3133
            // If the only body element for this named attribute node is
3139
            // If the only body element for this named attribute node is
3134
            // template text, we need not generate an extra call to
3140
            // template text, we need not generate an extra call to
Lines 3183-3189 Link Here
3183
         */
3189
         */
3184
        public String generateNamedAttributeJspFragment(Node.NamedAttribute n,
3190
        public String generateNamedAttributeJspFragment(Node.NamedAttribute n,
3185
                String tagHandlerVar) throws JasperException {
3191
                String tagHandlerVar) throws JasperException {
3186
            String varName = n.getTemporaryVariableName();
3192
            String varName = getVariableName(n);
3187
3193
3188
            out.printin("javax.servlet.jsp.tagext.JspFragment " + varName
3194
            out.printin("javax.servlet.jsp.tagext.JspFragment " + varName
3189
                    + " = ");
3195
                    + " = ");
Lines 3324-3329 Link Here
3324
        if (isPoolingEnabled) {
3330
        if (isPoolingEnabled) {
3325
            tagHandlerPoolNames = new Vector();
3331
            tagHandlerPoolNames = new Vector();
3326
        }
3332
        }
3333
3334
        variableNamesOfNamedAttributes = new HashMap<NamedAttribute, String>();
3335
        variableNameCounter = 0;
3327
    }
3336
    }
3328
3337
3329
    /**
3338
    /**
Lines 3764-3769 Link Here
3764
    }
3773
    }
3765
3774
3766
    /*
3775
    /*
3776
     * Returns the variable name of a named attribute.
3777
     */
3778
    private String getVariableName(NamedAttribute attribute) {
3779
        String name = variableNamesOfNamedAttributes.get(attribute);
3780
        if (name == null) {
3781
            name = Constants.TEMP_VARIABLE_NAME_PREFIX + (variableNameCounter++);
3782
            variableNamesOfNamedAttributes.put(attribute, name);
3783
        }
3784
3785
        return name;
3786
    }
3787
3788
    /*
3767
     * Generates the getter method for the given attribute name.
3789
     * Generates the getter method for the given attribute name.
3768
     */
3790
     */
3769
    private String toGetterMethod(String attrName) {
3791
    private String toGetterMethod(String attrName) {
(-)Node.java (-14 lines)
Lines 1842-1850 Link Here
1842
     */
1842
     */
1843
    public static class NamedAttribute extends Node {
1843
    public static class NamedAttribute extends Node {
1844
1844
1845
        // A unique temporary variable name suitable for code generation
1846
        private String temporaryVariableName;
1847
1848
        // True if this node is to be trimmed, or false otherwise
1845
        // True if this node is to be trimmed, or false otherwise
1849
        private boolean trim = true;
1846
        private boolean trim = true;
1850
1847
Lines 1907-1923 Link Here
1907
            return trim;
1904
            return trim;
1908
        }
1905
        }
1909
1906
1910
        /**
1911
         * @return A unique temporary variable name to store the result in.
1912
         *         (this probably could go elsewhere, but it's convenient here)
1913
         */
1914
        public String getTemporaryVariableName() {
1915
            if (temporaryVariableName == null) {
1916
                temporaryVariableName = JspUtil.nextTemporaryVariableName();
1917
            }
1918
            return temporaryVariableName;
1919
        }
1920
1921
        /*
1907
        /*
1922
         * Get the attribute value from this named attribute (<jsp:attribute>).
1908
         * Get the attribute value from this named attribute (<jsp:attribute>).
1923
         * Since this method is only for attributes that are not rtexpr, we can
1909
         * Since this method is only for attributes that are not rtexpr, we can

Return to bug 45691