2
* Copyright 1999,2004 The Apache Software Foundation.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
package org.apache.jasper.compiler;
19
import org.apache.jasper.JasperException;
22
* Collect info about the page and nodes, and make them availabe through
23
* the PageInfo object.
25
* @author Kin-man Chung
32
* A visitor for collecting information on the page and the body of
35
static class CollectVisitor extends Node.Visitor {
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;
44
public void visit(Node.ParamAction n) throws JasperException {
45
if (n.getValue().isExpression()) {
46
scriptingElementSeen = true;
48
paramActionSeen = true;
51
public void visit(Node.IncludeAction n) throws JasperException {
52
if (n.getPage().isExpression()) {
53
scriptingElementSeen = true;
55
includeActionSeen = true;
59
public void visit(Node.ForwardAction n) throws JasperException {
60
if (n.getPage().isExpression()) {
61
scriptingElementSeen = true;
66
public void visit(Node.SetProperty n) throws JasperException {
67
if (n.getValue() != null && n.getValue().isExpression()) {
68
scriptingElementSeen = true;
70
setPropertySeen = true;
73
public void visit(Node.UseBean n) throws JasperException {
74
if (n.getBeanName() != null && n.getBeanName().isExpression()) {
75
scriptingElementSeen = true;
81
public void visit(Node.PlugIn n) throws JasperException {
82
if (n.getHeight() != null && n.getHeight().isExpression()) {
83
scriptingElementSeen = true;
85
if (n.getWidth() != null && n.getWidth().isExpression()) {
86
scriptingElementSeen = true;
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 );
97
* Check all child nodes for various elements and update the given
98
* ChildInfo object accordingly. Visits body in the process.
100
private void checkSeen( Node.ChildInfo ci, Node n )
101
throws JasperException
103
// save values collected so far
104
boolean scriptingElementSeenSave = scriptingElementSeen;
105
scriptingElementSeen = false;
106
boolean usebeanSeenSave = usebeanSeen;
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;
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;
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;
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);
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;
154
public void visit(Node.JspElement n) throws JasperException {
155
if (n.getNameAttribute().isExpression())
156
scriptingElementSeen = true;
158
Node.JspAttribute[] attrs = n.getJspAttributes();
159
for (int i = 0; i < attrs.length; i++) {
160
if (attrs[i].isExpression()) {
161
scriptingElementSeen = true;
168
public void visit(Node.JspBody n) throws JasperException {
169
checkSeen( n.getChildInfo(), n );
172
public void visit(Node.NamedAttribute n) throws JasperException {
173
checkSeen( n.getChildInfo(), n );
176
public void visit(Node.Declaration n) throws JasperException {
177
scriptingElementSeen = true;
180
public void visit(Node.Expression n) throws JasperException {
181
scriptingElementSeen = true;
184
public void visit(Node.Scriptlet n) throws JasperException {
185
scriptingElementSeen = true;
188
public void updatePageInfo(PageInfo pageInfo) {
189
pageInfo.setScriptless(! scriptingElementSeen);
194
public static void collect(Compiler compiler, Node.Nodes page)
195
throws JasperException {
197
CollectVisitor collectVisitor = new CollectVisitor();
198
page.visit(collectVisitor);
199
collectVisitor.updatePageInfo(compiler.getPageInfo());