View Javadoc

1   /*
2    * $Id: ELMessageTag.java 376778 2006-02-10 18:08:07Z husted $
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.strutsel.taglib.bean;
19  
20  import org.apache.struts.taglib.bean.MessageTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Custom tag that retrieves an internationalized messages string (with
27   * optional parametric replacement) from the <code>ActionResources</code>
28   * object stored as a context attribute by our associated
29   * <code>ActionServlet</code> implementation. <p> This class is a subclass of
30   * the class <code>org.apache.struts.taglib.bean.MessageTag</code> which
31   * provides most of the described functionality.  This subclass allows all
32   * attribute values to be specified as expressions utilizing the JavaServer
33   * Pages Standard Library expression language.
34   *
35   * @version $Rev: 376778 $
36   */
37  public class ELMessageTag extends MessageTag {
38      /***
39       * Instance variable mapped to "arg0" tag attribute. (Mapping set in
40       * associated BeanInfo class.)
41       */
42      private String arg0Expr;
43  
44      /***
45       * Instance variable mapped to "arg1" tag attribute. (Mapping set in
46       * associated BeanInfo class.)
47       */
48      private String arg1Expr;
49  
50      /***
51       * Instance variable mapped to "arg2" tag attribute. (Mapping set in
52       * associated BeanInfo class.)
53       */
54      private String arg2Expr;
55  
56      /***
57       * Instance variable mapped to "arg3" tag attribute. (Mapping set in
58       * associated BeanInfo class.)
59       */
60      private String arg3Expr;
61  
62      /***
63       * Instance variable mapped to "arg4" tag attribute. (Mapping set in
64       * associated BeanInfo class.)
65       */
66      private String arg4Expr;
67  
68      /***
69       * Instance variable mapped to "bundle" tag attribute. (Mapping set in
70       * associated BeanInfo class.)
71       */
72      private String bundleExpr;
73  
74      /***
75       * Instance variable mapped to "key" tag attribute. (Mapping set in
76       * associated BeanInfo class.)
77       */
78      private String keyExpr;
79  
80      /***
81       * Instance variable mapped to "locale" tag attribute. (Mapping set in
82       * associated BeanInfo class.)
83       */
84      private String localeExpr;
85  
86      /***
87       * Instance variable mapped to "name" tag attribute. (Mapping set in
88       * associated BeanInfo class.)
89       */
90      private String nameExpr;
91  
92      /***
93       * Instance variable mapped to "property" tag attribute. (Mapping set in
94       * associated BeanInfo class.)
95       */
96      private String propertyExpr;
97  
98      /***
99       * Instance variable mapped to "scope" tag attribute. (Mapping set in
100      * associated BeanInfo class.)
101      */
102     private String scopeExpr;
103 
104     /***
105      * Getter method for "arg0" tag attribute. (Mapping set in associated
106      * BeanInfo class.)
107      */
108     public String getArg0Expr() {
109         return (arg0Expr);
110     }
111 
112     /***
113      * Getter method for "arg1" tag attribute. (Mapping set in associated
114      * BeanInfo class.)
115      */
116     public String getArg1Expr() {
117         return (arg1Expr);
118     }
119 
120     /***
121      * Getter method for "arg2" tag attribute. (Mapping set in associated
122      * BeanInfo class.)
123      */
124     public String getArg2Expr() {
125         return (arg2Expr);
126     }
127 
128     /***
129      * Getter method for "arg3" tag attribute. (Mapping set in associated
130      * BeanInfo class.)
131      */
132     public String getArg3Expr() {
133         return (arg3Expr);
134     }
135 
136     /***
137      * Getter method for "arg4" tag attribute. (Mapping set in associated
138      * BeanInfo class.)
139      */
140     public String getArg4Expr() {
141         return (arg4Expr);
142     }
143 
144     /***
145      * Getter method for "bundle" tag attribute. (Mapping set in associated
146      * BeanInfo class.)
147      */
148     public String getBundleExpr() {
149         return (bundleExpr);
150     }
151 
152     /***
153      * Getter method for "key" tag attribute. (Mapping set in associated
154      * BeanInfo class.)
155      */
156     public String getKeyExpr() {
157         return (keyExpr);
158     }
159 
160     /***
161      * Getter method for "locale" tag attribute. (Mapping set in associated
162      * BeanInfo class.)
163      */
164     public String getLocaleExpr() {
165         return (localeExpr);
166     }
167 
168     /***
169      * Getter method for "name" tag attribute. (Mapping set in associated
170      * BeanInfo class.)
171      */
172     public String getNameExpr() {
173         return (nameExpr);
174     }
175 
176     /***
177      * Getter method for "property" tag attribute. (Mapping set in associated
178      * BeanInfo class.)
179      */
180     public String getPropertyExpr() {
181         return (propertyExpr);
182     }
183 
184     /***
185      * Getter method for "scope" tag attribute. (Mapping set in associated
186      * BeanInfo class.)
187      */
188     public String getScopeExpr() {
189         return (scopeExpr);
190     }
191 
192     /***
193      * Setter method for "arg0" tag attribute. (Mapping set in associated
194      * BeanInfo class.)
195      */
196     public void setArg0Expr(String arg0Expr) {
197         this.arg0Expr = arg0Expr;
198     }
199 
200     /***
201      * Setter method for "arg1" tag attribute. (Mapping set in associated
202      * BeanInfo class.)
203      */
204     public void setArg1Expr(String arg1Expr) {
205         this.arg1Expr = arg1Expr;
206     }
207 
208     /***
209      * Setter method for "arg2" tag attribute. (Mapping set in associated
210      * BeanInfo class.)
211      */
212     public void setArg2Expr(String arg2Expr) {
213         this.arg2Expr = arg2Expr;
214     }
215 
216     /***
217      * Setter method for "arg3" tag attribute. (Mapping set in associated
218      * BeanInfo class.)
219      */
220     public void setArg3Expr(String arg3Expr) {
221         this.arg3Expr = arg3Expr;
222     }
223 
224     /***
225      * Setter method for "arg4" tag attribute. (Mapping set in associated
226      * BeanInfo class.)
227      */
228     public void setArg4Expr(String arg4Expr) {
229         this.arg4Expr = arg4Expr;
230     }
231 
232     /***
233      * Setter method for "bundle" tag attribute. (Mapping set in associated
234      * BeanInfo class.)
235      */
236     public void setBundleExpr(String bundleExpr) {
237         this.bundleExpr = bundleExpr;
238     }
239 
240     /***
241      * Setter method for "key" tag attribute. (Mapping set in associated
242      * BeanInfo class.)
243      */
244     public void setKeyExpr(String keyExpr) {
245         this.keyExpr = keyExpr;
246     }
247 
248     /***
249      * Setter method for "locale" tag attribute. (Mapping set in associated
250      * BeanInfo class.)
251      */
252     public void setLocaleExpr(String localeExpr) {
253         this.localeExpr = localeExpr;
254     }
255 
256     /***
257      * Setter method for "name" tag attribute. (Mapping set in associated
258      * BeanInfo class.)
259      */
260     public void setNameExpr(String nameExpr) {
261         this.nameExpr = nameExpr;
262     }
263 
264     /***
265      * Setter method for "property" tag attribute. (Mapping set in associated
266      * BeanInfo class.)
267      */
268     public void setPropertyExpr(String propertyExpr) {
269         this.propertyExpr = propertyExpr;
270     }
271 
272     /***
273      * Setter method for "scope" tag attribute. (Mapping set in associated
274      * BeanInfo class.)
275      */
276     public void setScopeExpr(String scopeExpr) {
277         this.scopeExpr = scopeExpr;
278     }
279 
280     /***
281      * Resets attribute values for tag reuse.
282      */
283     public void release() {
284         super.release();
285         setArg0Expr(null);
286         setArg1Expr(null);
287         setArg2Expr(null);
288         setArg3Expr(null);
289         setArg4Expr(null);
290         setBundleExpr(null);
291         setKeyExpr(null);
292         setLocaleExpr(null);
293         setNameExpr(null);
294         setPropertyExpr(null);
295         setScopeExpr(null);
296     }
297 
298     /***
299      * Process the start tag.
300      *
301      * @throws JspException if a JSP exception has occurred
302      */
303     public int doStartTag() throws JspException {
304         evaluateExpressions();
305 
306         return (super.doStartTag());
307     }
308 
309     /***
310      * Processes all attribute values which use the JSTL expression evaluation
311      * engine to determine their values.
312      *
313      * @throws JspException if a JSP exception has occurred
314      */
315     private void evaluateExpressions()
316         throws JspException {
317         String string = null;
318 
319         if ((string =
320                 EvalHelper.evalString("arg0", getArg0Expr(), this, pageContext)) != null) {
321             setArg0(string);
322         }
323 
324         if ((string =
325                 EvalHelper.evalString("arg1", getArg1Expr(), this, pageContext)) != null) {
326             setArg1(string);
327         }
328 
329         if ((string =
330                 EvalHelper.evalString("arg2", getArg2Expr(), this, pageContext)) != null) {
331             setArg2(string);
332         }
333 
334         if ((string =
335                 EvalHelper.evalString("arg3", getArg3Expr(), this, pageContext)) != null) {
336             setArg3(string);
337         }
338 
339         if ((string =
340                 EvalHelper.evalString("arg4", getArg4Expr(), this, pageContext)) != null) {
341             setArg4(string);
342         }
343 
344         if ((string =
345                 EvalHelper.evalString("bundle", getBundleExpr(), this,
346                     pageContext)) != null) {
347             setBundle(string);
348         }
349 
350         if ((string =
351                 EvalHelper.evalString("key", getKeyExpr(), this, pageContext)) != null) {
352             setKey(string);
353         }
354 
355         if ((string =
356                 EvalHelper.evalString("locale", getLocaleExpr(), this,
357                     pageContext)) != null) {
358             setLocale(string);
359         }
360 
361         if ((string =
362                 EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) {
363             setName(string);
364         }
365 
366         if ((string =
367                 EvalHelper.evalString("property", getPropertyExpr(), this,
368                     pageContext)) != null) {
369             setProperty(string);
370         }
371 
372         if ((string =
373                 EvalHelper.evalString("scope", getScopeExpr(), this, pageContext)) != null) {
374             setScope(string);
375         }
376     }
377 }