1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.strutsel.taglib.logic;
19
20 import org.apache.struts.taglib.logic.MatchTag;
21 import org.apache.strutsel.taglib.utils.EvalHelper;
22
23 import javax.servlet.jsp.JspException;
24
25 /***
26 * Evalute the nested body content of this tag if the specified value is a
27 * substring of the specified variable. <p> This class is a subclass of the
28 * class <code>org.apache.struts.taglib.logic.MatchTag</code> which provides
29 * most of the described functionality. This subclass allows all attribute
30 * values to be specified as expressions utilizing the JavaServer Pages
31 * Standard Library expression language.
32 *
33 * @version $Rev: 376780 $
34 */
35 public class ELMatchTag extends MatchTag {
36 /***
37 * Instance variable mapped to "cookie" tag attribute. (Mapping set in
38 * associated BeanInfo class.)
39 */
40 private String cookieExpr;
41
42 /***
43 * Instance variable mapped to "header" tag attribute. (Mapping set in
44 * associated BeanInfo class.)
45 */
46 private String headerExpr;
47
48 /***
49 * Instance variable mapped to "location" tag attribute. (Mapping set in
50 * associated BeanInfo class.)
51 */
52 private String locationExpr;
53
54 /***
55 * Instance variable mapped to "name" tag attribute. (Mapping set in
56 * associated BeanInfo class.)
57 */
58 private String nameExpr;
59
60 /***
61 * Instance variable mapped to "parameter" tag attribute. (Mapping set in
62 * associated BeanInfo class.)
63 */
64 private String parameterExpr;
65
66 /***
67 * Instance variable mapped to "property" tag attribute. (Mapping set in
68 * associated BeanInfo class.)
69 */
70 private String propertyExpr;
71
72 /***
73 * Instance variable mapped to "scope" tag attribute. (Mapping set in
74 * associated BeanInfo class.)
75 */
76 private String scopeExpr;
77
78 /***
79 * Instance variable mapped to "value" tag attribute. (Mapping set in
80 * associated BeanInfo class.)
81 */
82 private String valueExpr;
83
84 /***
85 * String value of expression to be evaluated.
86 */
87 private String expr;
88
89 /***
90 * Evaluated value of expression.
91 */
92 private String exprValue;
93
94 /***
95 * Getter method for "cookie" tag attribute. (Mapping set in associated
96 * BeanInfo class.)
97 */
98 public String getCookieExpr() {
99 return (cookieExpr);
100 }
101
102 /***
103 * Getter method for "header" tag attribute. (Mapping set in associated
104 * BeanInfo class.)
105 */
106 public String getHeaderExpr() {
107 return (headerExpr);
108 }
109
110 /***
111 * Getter method for "location" tag attribute. (Mapping set in associated
112 * BeanInfo class.)
113 */
114 public String getLocationExpr() {
115 return (locationExpr);
116 }
117
118 /***
119 * Getter method for "name" tag attribute. (Mapping set in associated
120 * BeanInfo class.)
121 */
122 public String getNameExpr() {
123 return (nameExpr);
124 }
125
126 /***
127 * Getter method for "parameter" tag attribute. (Mapping set in associated
128 * BeanInfo class.)
129 */
130 public String getParameterExpr() {
131 return (parameterExpr);
132 }
133
134 /***
135 * Getter method for "property" tag attribute. (Mapping set in associated
136 * BeanInfo class.)
137 */
138 public String getPropertyExpr() {
139 return (propertyExpr);
140 }
141
142 /***
143 * Getter method for "scope" tag attribute. (Mapping set in associated
144 * BeanInfo class.)
145 */
146 public String getScopeExpr() {
147 return (scopeExpr);
148 }
149
150 /***
151 * Getter method for "value" tag attribute. (Mapping set in associated
152 * BeanInfo class.)
153 */
154 public String getValueExpr() {
155 return (valueExpr);
156 }
157
158 /***
159 * Setter method for "cookie" tag attribute. (Mapping set in associated
160 * BeanInfo class.)
161 */
162 public void setCookieExpr(String cookieExpr) {
163 this.cookieExpr = cookieExpr;
164 }
165
166 /***
167 * Setter method for "header" tag attribute. (Mapping set in associated
168 * BeanInfo class.)
169 */
170 public void setHeaderExpr(String headerExpr) {
171 this.headerExpr = headerExpr;
172 }
173
174 /***
175 * Setter method for "location" tag attribute. (Mapping set in associated
176 * BeanInfo class.)
177 */
178 public void setLocationExpr(String locationExpr) {
179 this.locationExpr = locationExpr;
180 }
181
182 /***
183 * Setter method for "name" tag attribute. (Mapping set in associated
184 * BeanInfo class.)
185 */
186 public void setNameExpr(String nameExpr) {
187 this.nameExpr = nameExpr;
188 }
189
190 /***
191 * Setter method for "parameter" tag attribute. (Mapping set in associated
192 * BeanInfo class.)
193 */
194 public void setParameterExpr(String parameterExpr) {
195 this.parameterExpr = parameterExpr;
196 }
197
198 /***
199 * Setter method for "property" tag attribute. (Mapping set in associated
200 * BeanInfo class.)
201 */
202 public void setPropertyExpr(String propertyExpr) {
203 this.propertyExpr = propertyExpr;
204 }
205
206 /***
207 * Setter method for "scope" tag attribute. (Mapping set in associated
208 * BeanInfo class.)
209 */
210 public void setScopeExpr(String scopeExpr) {
211 this.scopeExpr = scopeExpr;
212 }
213
214 /***
215 * Setter method for "value" tag attribute. (Mapping set in associated
216 * BeanInfo class.)
217 */
218 public void setValueExpr(String valueExpr) {
219 this.valueExpr = valueExpr;
220 }
221
222 /***
223 * Returns the string value of the expression. This value will be
224 * evaluated by the JSTL EL engine.
225 */
226 public String getExpr() {
227 return (expr);
228 }
229
230 /***
231 * Sets the string value of the expression. This expression will be
232 * evaluated by the JSTL EL engine.
233 */
234 public void setExpr(String expr) {
235 this.expr = expr;
236 }
237
238 /***
239 * Returns the evaluated expression.
240 */
241 public String getExprValue() {
242 return (exprValue);
243 }
244
245 /***
246 * Sets the evaluated expression.
247 */
248 public void setExprValue(String exprValue) {
249 this.exprValue = exprValue;
250 }
251
252 /***
253 * Releases state of custom tag so this instance can be reused.
254 */
255 public void release() {
256 super.release();
257 setCookieExpr(null);
258 setHeaderExpr(null);
259 setLocationExpr(null);
260 setNameExpr(null);
261 setParameterExpr(null);
262 setPropertyExpr(null);
263 setScopeExpr(null);
264 setValueExpr(null);
265 setExpr(null);
266 setExprValue(null);
267 }
268
269 /***
270 * Process the start tag.
271 *
272 * @throws JspException if a JSP exception has occurred
273 */
274 public int doStartTag() throws JspException {
275 evaluateExpressions();
276
277 return (super.doStartTag());
278 }
279
280 /***
281 * Evaluates the condition that is being tested by this particular tag,
282 * and returns <code>true</code> if the nested body content of this tag
283 * should be evaluated, or <code>false</code> if it should be skipped.
284 *
285 * @param desired Desired value for a true result
286 * @throws JspException if a JSP exception occurs
287 */
288 protected boolean condition(boolean desired)
289 throws JspException {
290 boolean result = false;
291
292 if (getExprValue() != null) {
293 result =
294 ELMatchSupport.condition(desired, getExprValue(), value,
295 location, messages, pageContext);
296 } else {
297 result = super.condition(desired);
298 }
299
300 return (result);
301 }
302
303 /***
304 * Processes all attribute values which use the JSTL expression evaluation
305 * engine to determine their values.
306 *
307 * @throws JspException if a JSP exception has occurred
308 */
309 private void evaluateExpressions()
310 throws JspException {
311 String string = null;
312
313 if ((string =
314 EvalHelper.evalString("cookie", getCookieExpr(), this,
315 pageContext)) != null) {
316 setCookie(string);
317 }
318
319 if ((string =
320 EvalHelper.evalString("expr", getExpr(), this, pageContext)) != null) {
321 setExprValue(string);
322 }
323
324 if ((string =
325 EvalHelper.evalString("header", getHeaderExpr(), this,
326 pageContext)) != null) {
327 setHeader(string);
328 }
329
330 if ((string =
331 EvalHelper.evalString("location", getLocationExpr(), this,
332 pageContext)) != null) {
333 setLocation(string);
334 }
335
336 if ((string =
337 EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) {
338 setName(string);
339 }
340
341 if ((string =
342 EvalHelper.evalString("parameter", getParameterExpr(), this,
343 pageContext)) != null) {
344 setParameter(string);
345 }
346
347 if ((string =
348 EvalHelper.evalString("property", getPropertyExpr(), this,
349 pageContext)) != null) {
350 setProperty(string);
351 }
352
353 if ((string =
354 EvalHelper.evalString("scope", getScopeExpr(), this, pageContext)) != null) {
355 setScope(string);
356 }
357
358 if ((string =
359 EvalHelper.evalString("value", getValueExpr(), this, pageContext)) != null) {
360 setValue(string);
361 }
362 }
363 }