~ubuntu-branches/ubuntu/intrepid/tomcat5.5/intrepid

« back to all changes in this revision

Viewing changes to jasper/src/share/org/apache/jasper/compiler/Collector.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-09-27 11:19:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060927111917-wov6fmkz3x6rsl68
Tags: 5.5.17-1ubuntu1
(Build-) depend on libmx4j-java (>= 3.0).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 1999,2004 The Apache Software Foundation.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
package org.apache.jasper.compiler;
 
18
 
 
19
import org.apache.jasper.JasperException;
 
20
 
 
21
/**
 
22
 * Collect info about the page and nodes, and make them availabe through
 
23
 * the PageInfo object.
 
24
 *
 
25
 * @author Kin-man Chung
 
26
 * @author Mark Roth
 
27
 */
 
28
 
 
29
class Collector {
 
30
 
 
31
    /**
 
32
     * A visitor for collecting information on the page and the body of
 
33
     * the custom tags.
 
34
     */
 
35
    static class CollectVisitor extends Node.Visitor {
 
36
 
 
37
        private boolean scriptingElementSeen = false;
 
38
        private boolean usebeanSeen = false;
 
39
        private boolean includeActionSeen = false;
 
40
        private boolean paramActionSeen = false;
 
41
        private boolean setPropertySeen = false;
 
42
        private boolean hasScriptingVars = false;
 
43
 
 
44
        public void visit(Node.ParamAction n) throws JasperException {
 
45
            if (n.getValue().isExpression()) {
 
46
                scriptingElementSeen = true;
 
47
            }
 
48
            paramActionSeen = true;
 
49
        }
 
50
 
 
51
        public void visit(Node.IncludeAction n) throws JasperException {
 
52
            if (n.getPage().isExpression()) {
 
53
                scriptingElementSeen = true;
 
54
            }
 
55
            includeActionSeen = true;
 
56
            visitBody(n);
 
57
        }
 
58
 
 
59
        public void visit(Node.ForwardAction n) throws JasperException {
 
60
            if (n.getPage().isExpression()) {
 
61
                scriptingElementSeen = true;
 
62
            }
 
63
            visitBody(n);
 
64
        }
 
65
 
 
66
        public void visit(Node.SetProperty n) throws JasperException {
 
67
            if (n.getValue() != null && n.getValue().isExpression()) {
 
68
                scriptingElementSeen = true;
 
69
            }
 
70
            setPropertySeen = true;
 
71
        }
 
72
 
 
73
        public void visit(Node.UseBean n) throws JasperException {
 
74
            if (n.getBeanName() != null && n.getBeanName().isExpression()) {
 
75
                scriptingElementSeen = true;
 
76
            }
 
77
            usebeanSeen = true;
 
78
                visitBody(n);
 
79
        }
 
80
 
 
81
        public void visit(Node.PlugIn n) throws JasperException {
 
82
            if (n.getHeight() != null && n.getHeight().isExpression()) {
 
83
                scriptingElementSeen = true;
 
84
            }
 
85
            if (n.getWidth() != null && n.getWidth().isExpression()) {
 
86
                scriptingElementSeen = true;
 
87
            }
 
88
            visitBody(n);
 
89
        }
 
90
 
 
91
        public void visit(Node.CustomTag n) throws JasperException {
 
92
            // Check to see what kinds of element we see as child elements
 
93
            checkSeen( n.getChildInfo(), n );
 
94
        }
 
95
 
 
96
        /**
 
97
         * Check all child nodes for various elements and update the given
 
98
         * ChildInfo object accordingly.  Visits body in the process.
 
99
         */
 
100
        private void checkSeen( Node.ChildInfo ci, Node n )
 
101
            throws JasperException
 
102
        {
 
103
            // save values collected so far
 
104
            boolean scriptingElementSeenSave = scriptingElementSeen;
 
105
            scriptingElementSeen = false;
 
106
            boolean usebeanSeenSave = usebeanSeen;
 
107
            usebeanSeen = false;
 
108
            boolean includeActionSeenSave = includeActionSeen;
 
109
            includeActionSeen = false;
 
110
            boolean paramActionSeenSave = paramActionSeen;
 
111
            paramActionSeen = false;
 
112
            boolean setPropertySeenSave = setPropertySeen;
 
113
            setPropertySeen = false;
 
114
            boolean hasScriptingVarsSave = hasScriptingVars;
 
115
            hasScriptingVars = false;
 
116
 
 
117
            // Scan attribute list for expressions
 
118
            if( n instanceof Node.CustomTag ) {
 
119
                Node.CustomTag ct = (Node.CustomTag)n;
 
120
                Node.JspAttribute[] attrs = ct.getJspAttributes();
 
121
                for (int i = 0; attrs != null && i < attrs.length; i++) {
 
122
                    if (attrs[i].isExpression()) {
 
123
                        scriptingElementSeen = true;
 
124
                        break;
 
125
                    }
 
126
                }
 
127
            }
 
128
 
 
129
            visitBody(n);
 
130
 
 
131
            if( (n instanceof Node.CustomTag) && !hasScriptingVars) {
 
132
                Node.CustomTag ct = (Node.CustomTag)n;
 
133
                hasScriptingVars = ct.getVariableInfos().length > 0 ||
 
134
                    ct.getTagVariableInfos().length > 0;
 
135
            }
 
136
 
 
137
            // Record if the tag element and its body contains any scriptlet.
 
138
            ci.setScriptless(! scriptingElementSeen);
 
139
            ci.setHasUseBean(usebeanSeen);
 
140
            ci.setHasIncludeAction(includeActionSeen);
 
141
            ci.setHasParamAction(paramActionSeen);
 
142
            ci.setHasSetProperty(setPropertySeen);
 
143
            ci.setHasScriptingVars(hasScriptingVars);
 
144
 
 
145
            // Propagate value of scriptingElementSeen up.
 
146
            scriptingElementSeen = scriptingElementSeen || scriptingElementSeenSave;
 
147
            usebeanSeen = usebeanSeen || usebeanSeenSave;
 
148
            setPropertySeen = setPropertySeen || setPropertySeenSave;
 
149
            includeActionSeen = includeActionSeen || includeActionSeenSave;
 
150
            paramActionSeen = paramActionSeen || paramActionSeenSave;
 
151
            hasScriptingVars = hasScriptingVars || hasScriptingVarsSave;
 
152
        }
 
153
 
 
154
        public void visit(Node.JspElement n) throws JasperException {
 
155
            if (n.getNameAttribute().isExpression())
 
156
                scriptingElementSeen = true;
 
157
 
 
158
            Node.JspAttribute[] attrs = n.getJspAttributes();
 
159
            for (int i = 0; i < attrs.length; i++) {
 
160
                if (attrs[i].isExpression()) {
 
161
                    scriptingElementSeen = true;
 
162
                    break;
 
163
                }
 
164
            }
 
165
            visitBody(n);
 
166
        }
 
167
 
 
168
        public void visit(Node.JspBody n) throws JasperException {
 
169
            checkSeen( n.getChildInfo(), n );
 
170
        }
 
171
 
 
172
        public void visit(Node.NamedAttribute n) throws JasperException {
 
173
            checkSeen( n.getChildInfo(), n );
 
174
        }
 
175
 
 
176
        public void visit(Node.Declaration n) throws JasperException {
 
177
            scriptingElementSeen = true;
 
178
        }
 
179
 
 
180
        public void visit(Node.Expression n) throws JasperException {
 
181
            scriptingElementSeen = true;
 
182
        }
 
183
 
 
184
        public void visit(Node.Scriptlet n) throws JasperException {
 
185
            scriptingElementSeen = true;
 
186
        }
 
187
 
 
188
        public void updatePageInfo(PageInfo pageInfo) {
 
189
            pageInfo.setScriptless(! scriptingElementSeen);
 
190
        }
 
191
    }
 
192
 
 
193
 
 
194
    public static void collect(Compiler compiler, Node.Nodes page)
 
195
        throws JasperException {
 
196
 
 
197
    CollectVisitor collectVisitor = new CollectVisitor();
 
198
        page.visit(collectVisitor);
 
199
        collectVisitor.updatePageInfo(compiler.getPageInfo());
 
200
 
 
201
    }
 
202
}
 
203