View Javadoc

1   /*
2    * $Id: ELMessagesTag.java 376779 2006-02-10 18:08:58Z 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.html;
19  
20  import org.apache.struts.taglib.html.MessagesTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Custom tag that iterates the elements of a message collection. It defaults
27   * to retrieving the messages from <code>Action.ERROR_KEY</code>, but if the
28   * message attribute is set to true then the messages will be retrieved from
29   * <code>Action.MESSAGE_KEY</code>. This is an alternative to the default
30   * <code>ErrorsTag</code>. <p> This class is a subclass of the class
31   * <code>org.apache.struts.taglib.html.MessagesTag</code> which provides most
32   * of the described functionality.  This subclass allows all attribute values
33   * to be specified as expressions utilizing the JavaServer Pages Standard
34   * Library expression language.
35   *
36   * @version $Rev: 376779 $
37   */
38  public class ELMessagesTag extends MessagesTag {
39      /***
40       * Instance variable mapped to "id" tag attribute. (Mapping set in
41       * associated BeanInfo class.)
42       */
43      private String idExpr;
44  
45      /***
46       * Instance variable mapped to "bundle" tag attribute. (Mapping set in
47       * associated BeanInfo class.)
48       */
49      private String bundleExpr;
50  
51      /***
52       * Instance variable mapped to "locale" tag attribute. (Mapping set in
53       * associated BeanInfo class.)
54       */
55      private String localeExpr;
56  
57      /***
58       * Instance variable mapped to "name" tag attribute. (Mapping set in
59       * associated BeanInfo class.)
60       */
61      private String nameExpr;
62  
63      /***
64       * Instance variable mapped to "property" tag attribute. (Mapping set in
65       * associated BeanInfo class.)
66       */
67      private String propertyExpr;
68  
69      /***
70       * Instance variable mapped to "header" tag attribute. (Mapping set in
71       * associated BeanInfo class.)
72       */
73      private String headerExpr;
74  
75      /***
76       * Instance variable mapped to "footer" tag attribute. (Mapping set in
77       * associated BeanInfo class.)
78       */
79      private String footerExpr;
80  
81      /***
82       * Instance variable mapped to "message" tag attribute. (Mapping set in
83       * associated BeanInfo class.)
84       */
85      private String messageExpr;
86  
87      /***
88       * Getter method for "id" tag attribute. (Mapping set in associated
89       * BeanInfo class.)
90       */
91      public String getIdExpr() {
92          return (idExpr);
93      }
94  
95      /***
96       * Getter method for "bundle" tag attribute. (Mapping set in associated
97       * BeanInfo class.)
98       */
99      public String getBundleExpr() {
100         return (bundleExpr);
101     }
102 
103     /***
104      * Getter method for "locale" tag attribute. (Mapping set in associated
105      * BeanInfo class.)
106      */
107     public String getLocaleExpr() {
108         return (localeExpr);
109     }
110 
111     /***
112      * Getter method for "name" tag attribute. (Mapping set in associated
113      * BeanInfo class.)
114      */
115     public String getNameExpr() {
116         return (nameExpr);
117     }
118 
119     /***
120      * Getter method for "property" tag attribute. (Mapping set in associated
121      * BeanInfo class.)
122      */
123     public String getPropertyExpr() {
124         return (propertyExpr);
125     }
126 
127     /***
128      * Getter method for "header" tag attribute. (Mapping set in associated
129      * BeanInfo class.)
130      */
131     public String getHeaderExpr() {
132         return (headerExpr);
133     }
134 
135     /***
136      * Getter method for "footer" tag attribute. (Mapping set in associated
137      * BeanInfo class.)
138      */
139     public String getFooterExpr() {
140         return (footerExpr);
141     }
142 
143     /***
144      * Getter method for "message" tag attribute. (Mapping set in associated
145      * BeanInfo class.)
146      */
147     public String getMessageExpr() {
148         return (messageExpr);
149     }
150 
151     /***
152      * Setter method for "id" tag attribute. (Mapping set in associated
153      * BeanInfo class.)
154      */
155     public void setIdExpr(String idExpr) {
156         this.idExpr = idExpr;
157     }
158 
159     /***
160      * Setter method for "bundle" tag attribute. (Mapping set in associated
161      * BeanInfo class.)
162      */
163     public void setBundleExpr(String bundleExpr) {
164         this.bundleExpr = bundleExpr;
165     }
166 
167     /***
168      * Setter method for "locale" tag attribute. (Mapping set in associated
169      * BeanInfo class.)
170      */
171     public void setLocaleExpr(String localeExpr) {
172         this.localeExpr = localeExpr;
173     }
174 
175     /***
176      * Setter method for "name" tag attribute. (Mapping set in associated
177      * BeanInfo class.)
178      */
179     public void setNameExpr(String nameExpr) {
180         this.nameExpr = nameExpr;
181     }
182 
183     /***
184      * Setter method for "property" tag attribute. (Mapping set in associated
185      * BeanInfo class.)
186      */
187     public void setPropertyExpr(String propertyExpr) {
188         this.propertyExpr = propertyExpr;
189     }
190 
191     /***
192      * Setter method for "header" tag attribute. (Mapping set in associated
193      * BeanInfo class.)
194      */
195     public void setHeaderExpr(String headerExpr) {
196         this.headerExpr = headerExpr;
197     }
198 
199     /***
200      * Setter method for "footer" tag attribute. (Mapping set in associated
201      * BeanInfo class.)
202      */
203     public void setFooterExpr(String footerExpr) {
204         this.footerExpr = footerExpr;
205     }
206 
207     /***
208      * Setter method for "message" tag attribute. (Mapping set in associated
209      * BeanInfo class.)
210      */
211     public void setMessageExpr(String messageExpr) {
212         this.messageExpr = messageExpr;
213     }
214 
215     /***
216      * Resets attribute values for tag reuse.
217      */
218     public void release() {
219         super.release();
220         setIdExpr(null);
221         setBundleExpr(null);
222         setLocaleExpr(null);
223         setNameExpr(null);
224         setPropertyExpr(null);
225         setHeaderExpr(null);
226         setFooterExpr(null);
227         setMessageExpr(null);
228     }
229 
230     /***
231      * Process the start tag.
232      *
233      * @throws JspException if a JSP exception has occurred
234      */
235     public int doStartTag() throws JspException {
236         evaluateExpressions();
237 
238         return (super.doStartTag());
239     }
240 
241     /***
242      * Processes all attribute values which use the JSTL expression evaluation
243      * engine to determine their values.
244      *
245      * @throws JspException if a JSP exception has occurred
246      */
247     private void evaluateExpressions()
248         throws JspException {
249         String string = null;
250 
251         if ((string =
252                 EvalHelper.evalString("id", getIdExpr(), this, pageContext)) != null) {
253             setId(string);
254         }
255 
256         if ((string =
257                 EvalHelper.evalString("bundle", getBundleExpr(), this,
258                     pageContext)) != null) {
259             setBundle(string);
260         }
261 
262         if ((string =
263                 EvalHelper.evalString("locale", getLocaleExpr(), this,
264                     pageContext)) != null) {
265             setLocale(string);
266         }
267 
268         if ((string =
269                 EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) {
270             setName(string);
271         }
272 
273         if ((string =
274                 EvalHelper.evalString("property", getPropertyExpr(), this,
275                     pageContext)) != null) {
276             setProperty(string);
277         }
278 
279         if ((string =
280                 EvalHelper.evalString("header", getHeaderExpr(), this,
281                     pageContext)) != null) {
282             setHeader(string);
283         }
284 
285         if ((string =
286                 EvalHelper.evalString("footer", getFooterExpr(), this,
287                     pageContext)) != null) {
288             setFooter(string);
289         }
290 
291         if ((string =
292                 EvalHelper.evalString("message", getMessageExpr(), this,
293                     pageContext)) != null) {
294             setMessage(string);
295         }
296     }
297 }