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

(-)java/org/apache/jasper/compiler/Generator.java (-26 / +62 lines)
Lines 167-192 Link Here
167
        return b.toString();
167
        return b.toString();
168
    }
168
    }
169
169
170
    /**
171
     * Finds the <jsp:body> subelement of the given parent node. If not
172
     * found, null is returned.
173
     */
174
    protected static Node.JspBody findJspBody(Node parent) {
175
        Node.JspBody result = null;
176
177
        Node.Nodes subelements = parent.getBody();
178
        for (int i = 0; (subelements != null) && (i < subelements.size()); i++) {
179
            Node n = subelements.getNode(i);
180
            if (n instanceof Node.JspBody) {
181
                result = (Node.JspBody) n;
182
                break;
183
            }
184
        }
185
186
        return result;
187
    }
188
189
190
    private String createJspId() {
170
    private String createJspId() {
191
        if (this.jspIdPrefix == null) {
171
        if (this.jspIdPrefix == null) {
192
            StringBuilder sb = new StringBuilder(32);
172
            StringBuilder sb = new StringBuilder(32);
Lines 358-363 Link Here
358
338
359
            @Override
339
            @Override
360
            public void visit(Node.CustomTag n) throws JasperException {
340
            public void visit(Node.CustomTag n) throws JasperException {
341
                // XXX - Actually there is no need to declare those
342
                // "_jspx_" + varName + "_" + nestingLevel variables when we are
343
                // inside a JspFragment.
361
344
362
                if (n.getCustomNestingLevel() > 0) {
345
                if (n.getCustomNestingLevel() > 0) {
363
                    TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
346
                    TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
Lines 991-996 Link Here
991
            }
974
            }
992
        }
975
        }
993
976
977
        /**
978
         * Finds the &lt;jsp:body&gt; subelement of the given parent node. If not
979
         * found, null is returned.
980
         */
981
        private Node.JspBody findJspBody(Node parent) {
982
            Node.JspBody result = null;
983
984
            Node.Nodes subelements = parent.getBody();
985
            for (int i = 0; (subelements != null) && (i < subelements.size()); i++) {
986
                Node n = subelements.getNode(i);
987
                if (n instanceof Node.JspBody) {
988
                    result = (Node.JspBody) n;
989
                    break;
990
                }
991
            }
992
993
            return result;
994
        }
995
994
        @Override
996
        @Override
995
        public void visit(Node.ForwardAction n) throws JasperException {
997
        public void visit(Node.ForwardAction n) throws JasperException {
996
            Node.JspAttribute page = n.getPage();
998
            Node.JspAttribute page = n.getPage();
Lines 2505-2515 Link Here
2505
        }
2507
        }
2506
2508
2507
        private void declareScriptingVars(Node.CustomTag n, int scope) {
2509
        private void declareScriptingVars(Node.CustomTag n, int scope) {
2510
            if (isFragment) {
2511
                // No need to declare Java variables, if we inside a
2512
                // JspFragment, because a fragment is always scriptless.
2513
                return;
2514
            }
2508
2515
2509
            Vector<Object> vec = n.getScriptingVars(scope);
2516
            List<Object> vec = n.getScriptingVars(scope);
2510
            if (vec != null) {
2517
            if (vec != null) {
2511
                for (int i = 0; i < vec.size(); i++) {
2518
                for (int i = 0; i < vec.size(); i++) {
2512
                    Object elem = vec.elementAt(i);
2519
                    Object elem = vec.get(i);
2513
                    if (elem instanceof VariableInfo) {
2520
                    if (elem instanceof VariableInfo) {
2514
                        VariableInfo varInfo = (VariableInfo) elem;
2521
                        VariableInfo varInfo = (VariableInfo) elem;
2515
                        if (varInfo.getDeclare()) {
2522
                        if (varInfo.getDeclare()) {
Lines 2552-2557 Link Here
2552
            if (n.getCustomNestingLevel() == 0) {
2559
            if (n.getCustomNestingLevel() == 0) {
2553
                return;
2560
                return;
2554
            }
2561
            }
2562
            if (isFragment) {
2563
                // No need to declare Java variables, if we inside a
2564
                // JspFragment, because a fragment is always scriptless.
2565
                // Thus, there is no need to save/ restore/ sync them.
2566
                // Note, that JspContextWrapper.syncFoo() methods will take
2567
                // care of saving/ restoring/ sync'ing of JspContext attributes.
2568
                return;
2569
            }
2555
2570
2556
            TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
2571
            TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
2557
            VariableInfo[] varInfos = n.getVariableInfos();
2572
            VariableInfo[] varInfos = n.getVariableInfos();
Lines 2559-2571 Link Here
2559
                return;
2574
                return;
2560
            }
2575
            }
2561
2576
2577
            List<Object> declaredVariables = n.getScriptingVars(scope);
2578
2562
            if (varInfos.length > 0) {
2579
            if (varInfos.length > 0) {
2563
                for (int i = 0; i < varInfos.length; i++) {
2580
                for (int i = 0; i < varInfos.length; i++) {
2564
                    if (varInfos[i].getScope() != scope)
2581
                    if (varInfos[i].getScope() != scope)
2565
                        continue;
2582
                        continue;
2566
                    // If the scripting variable has been declared, skip codes
2583
                    // If the scripting variable has been declared, skip codes
2567
                    // for saving and restoring it.
2584
                    // for saving and restoring it.
2568
                    if (n.getScriptingVars(scope).contains(varInfos[i]))
2585
                    if (declaredVariables.contains(varInfos[i]))
2569
                        continue;
2586
                        continue;
2570
                    String varName = varInfos[i].getVarName();
2587
                    String varName = varInfos[i].getVarName();
2571
                    String tmpVarName = "_jspx_" + varName + "_"
2588
                    String tmpVarName = "_jspx_" + varName + "_"
Lines 2581-2587 Link Here
2581
                        continue;
2598
                        continue;
2582
                    // If the scripting variable has been declared, skip codes
2599
                    // If the scripting variable has been declared, skip codes
2583
                    // for saving and restoring it.
2600
                    // for saving and restoring it.
2584
                    if (n.getScriptingVars(scope).contains(tagVarInfos[i]))
2601
                    if (declaredVariables.contains(tagVarInfos[i]))
2585
                        continue;
2602
                        continue;
2586
                    String varName = tagVarInfos[i].getNameGiven();
2603
                    String varName = tagVarInfos[i].getNameGiven();
2587
                    if (varName == null) {
2604
                    if (varName == null) {
Lines 2612-2617 Link Here
2612
            if (n.getCustomNestingLevel() == 0) {
2629
            if (n.getCustomNestingLevel() == 0) {
2613
                return;
2630
                return;
2614
            }
2631
            }
2632
            if (isFragment) {
2633
                // No need to declare Java variables, if we inside a
2634
                // JspFragment, because a fragment is always scriptless.
2635
                // Thus, there is no need to save/ restore/ sync them.
2636
                // Note, that JspContextWrapper.syncFoo() methods will take
2637
                // care of saving/ restoring/ sync'ing of JspContext attributes.
2638
                return;
2639
            }
2615
2640
2616
            TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
2641
            TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
2617
            VariableInfo[] varInfos = n.getVariableInfos();
2642
            VariableInfo[] varInfos = n.getVariableInfos();
Lines 2619-2631 Link Here
2619
                return;
2644
                return;
2620
            }
2645
            }
2621
2646
2647
            List<Object> declaredVariables = n.getScriptingVars(scope);
2648
2622
            if (varInfos.length > 0) {
2649
            if (varInfos.length > 0) {
2623
                for (int i = 0; i < varInfos.length; i++) {
2650
                for (int i = 0; i < varInfos.length; i++) {
2624
                    if (varInfos[i].getScope() != scope)
2651
                    if (varInfos[i].getScope() != scope)
2625
                        continue;
2652
                        continue;
2626
                    // If the scripting variable has been declared, skip codes
2653
                    // If the scripting variable has been declared, skip codes
2627
                    // for saving and restoring it.
2654
                    // for saving and restoring it.
2628
                    if (n.getScriptingVars(scope).contains(varInfos[i]))
2655
                    if (declaredVariables.contains(varInfos[i]))
2629
                        continue;
2656
                        continue;
2630
                    String varName = varInfos[i].getVarName();
2657
                    String varName = varInfos[i].getVarName();
2631
                    String tmpVarName = "_jspx_" + varName + "_"
2658
                    String tmpVarName = "_jspx_" + varName + "_"
Lines 2641-2647 Link Here
2641
                        continue;
2668
                        continue;
2642
                    // If the scripting variable has been declared, skip codes
2669
                    // If the scripting variable has been declared, skip codes
2643
                    // for saving and restoring it.
2670
                    // for saving and restoring it.
2644
                    if (n.getScriptingVars(scope).contains(tagVarInfos[i]))
2671
                    if (declaredVariables.contains(tagVarInfos[i]))
2645
                        continue;
2672
                        continue;
2646
                    String varName = tagVarInfos[i].getNameGiven();
2673
                    String varName = tagVarInfos[i].getNameGiven();
2647
                    if (varName == null) {
2674
                    if (varName == null) {
Lines 2666-2671 Link Here
2666
         * given scope.
2693
         * given scope.
2667
         */
2694
         */
2668
        private void syncScriptingVars(Node.CustomTag n, int scope) {
2695
        private void syncScriptingVars(Node.CustomTag n, int scope) {
2696
            if (isFragment) {
2697
                // No need to declare Java variables, if we inside a
2698
                // JspFragment, because a fragment is always scriptless.
2699
                // Thus, there is no need to save/ restore/ sync them.
2700
                // Note, that JspContextWrapper.syncFoo() methods will take
2701
                // care of saving/ restoring/ sync'ing of JspContext attributes.
2702
                return;
2703
            }
2704
2669
            TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
2705
            TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
2670
            VariableInfo[] varInfos = n.getVariableInfos();
2706
            VariableInfo[] varInfos = n.getVariableInfos();
2671
2707
(-)java/org/apache/jasper/compiler/Node.java (-6 / +6 lines)
Lines 1433-1443 Link Here
1433
1433
1434
        private boolean implementsDynamicAttributes;
1434
        private boolean implementsDynamicAttributes;
1435
1435
1436
        private Vector<Object> atBeginScriptingVars;
1436
        private List<Object> atBeginScriptingVars;
1437
1437
1438
        private Vector<Object> atEndScriptingVars;
1438
        private List<Object> atEndScriptingVars;
1439
1439
1440
        private Vector<Object> nestedScriptingVars;
1440
        private List<Object> nestedScriptingVars;
1441
1441
1442
        private Node.CustomTag customTagParent;
1442
        private Node.CustomTag customTagParent;
1443
1443
Lines 1657-1663 Link Here
1657
            return this.numCount;
1657
            return this.numCount;
1658
        }
1658
        }
1659
1659
1660
        public void setScriptingVars(Vector<Object> vec, int scope) {
1660
        public void setScriptingVars(List<Object> vec, int scope) {
1661
            switch (scope) {
1661
            switch (scope) {
1662
            case VariableInfo.AT_BEGIN:
1662
            case VariableInfo.AT_BEGIN:
1663
                this.atBeginScriptingVars = vec;
1663
                this.atBeginScriptingVars = vec;
Lines 1675-1682 Link Here
1675
         * Gets the scripting variables for the given scope that need to be
1675
         * Gets the scripting variables for the given scope that need to be
1676
         * declared.
1676
         * declared.
1677
         */
1677
         */
1678
        public Vector<Object> getScriptingVars(int scope) {
1678
        public List<Object> getScriptingVars(int scope) {
1679
            Vector<Object> vec = null;
1679
            List<Object> vec = null;
1680
1680
1681
            switch (scope) {
1681
            switch (scope) {
1682
            case VariableInfo.AT_BEGIN:
1682
            case VariableInfo.AT_BEGIN:
(-)java/org/apache/jasper/compiler/ScriptingVariabler.java (-28 / +6 lines)
Lines 59-69 Link Here
59
    static class ScriptingVariableVisitor extends Node.Visitor {
59
    static class ScriptingVariableVisitor extends Node.Visitor {
60
60
61
        private ErrorDispatcher err;
61
        private ErrorDispatcher err;
62
        private Hashtable<String,Integer> scriptVars;
62
        private Map<String, Integer> scriptVars;
63
        
63
64
        public ScriptingVariableVisitor(ErrorDispatcher err) {
64
        public ScriptingVariableVisitor(ErrorDispatcher err) {
65
            this.err = err;
65
            this.err = err;
66
            scriptVars = new Hashtable<String,Integer>();
66
            scriptVars = new HashMap<String,Integer>();
67
        }
67
        }
68
68
69
        @Override
69
        @Override
Lines 83-89 Link Here
83
                return;
83
                return;
84
            }
84
            }
85
85
86
            Vector<Object> vec = new Vector<Object>();
86
            List<Object> vec = new ArrayList<Object>();
87
87
88
            Integer ownRange = null;
88
            Integer ownRange = null;
89
            Node.CustomTag parent = n.getCustomTagParent();
89
            Node.CustomTag parent = n.getCustomTagParent();
Lines 107-117 Link Here
107
                    String varName = varInfos[i].getVarName();
107
                    String varName = varInfos[i].getVarName();
108
                    
108
                    
109
                    Integer currentRange = scriptVars.get(varName);
109
                    Integer currentRange = scriptVars.get(varName);
110
                    // If a fragment helper has been used for the parent tag
111
                    // the scripting variables always need to be declared
112
                    if (currentRange == null ||
110
                    if (currentRange == null ||
113
                            ownRange.compareTo(currentRange) > 0 ||
111
                            ownRange.compareTo(currentRange) > 0) {
114
                            parent != null && isImplementedAsFragment(parent)) {
115
                        scriptVars.put(varName, ownRange);
112
                        scriptVars.put(varName, ownRange);
116
                        vec.add(varInfos[i]);
113
                        vec.add(varInfos[i]);
117
                    }
114
                    }
Lines 134-144 Link Here
134
                    }
131
                    }
135
132
136
                    Integer currentRange = scriptVars.get(varName);
133
                    Integer currentRange = scriptVars.get(varName);
137
                    // If a fragment helper has been used for the parent tag
138
                    // the scripting variables always need to be declared
139
                    if (currentRange == null ||
134
                    if (currentRange == null ||
140
                            ownRange.compareTo(currentRange) > 0 ||
135
                            ownRange.compareTo(currentRange) > 0) {
141
                            parent != null && isImplementedAsFragment(parent)) {
142
                        scriptVars.put(varName, ownRange);
136
                        scriptVars.put(varName, ownRange);
143
                        vec.add(tagVarInfos[i]);
137
                        vec.add(tagVarInfos[i]);
144
                    }
138
                    }
Lines 149-170 Link Here
149
        }
143
        }
150
    }
144
    }
151
145
152
    private static boolean isImplementedAsFragment(Node.CustomTag n) {
153
        // Replicates logic from Generator to determine if a fragment
154
        // helper will be used
155
        if (n.implementsSimpleTag()) {
156
            if (Generator.findJspBody(n) == null) {
157
                if (!n.hasEmptyBody()) {
158
                    return true;
159
                }
160
                return false;
161
            }
162
            return true;
163
        }
164
        return false;
165
    }
166
167
    
168
    public static void set(Node.Nodes page, ErrorDispatcher err)
146
    public static void set(Node.Nodes page, ErrorDispatcher err)
169
            throws JasperException {
147
            throws JasperException {
170
        page.visit(new CustomTagCounter());
148
        page.visit(new CustomTagCounter());

Return to bug 48616