View Javadoc

1   /*
2    * $Id: ELIterateTag.java 376780 2006-02-10 18:09:22Z 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.logic;
19  
20  import org.apache.struts.taglib.logic.IterateTag;
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 collection, which can be either
27   * an attribute or the property of an attribute.  The collection can be any of
28   * the following:  an array of objects, an Enumeration, an Iterator, a
29   * Collection (which includes Lists, Sets and Vectors), or a Map (which
30   * includes Hashtables) whose elements will be iterated over. <p> This class
31   * is a subclass of the class <code>org.apache.struts.taglib.logic.IterateTag</code>
32   * which provides most of the described functionality.  This subclass allows
33   * all attribute values to be specified as expressions utilizing the
34   * JavaServer Pages Standard Library expression language.
35   *
36   * @version $Rev: 376780 $
37   */
38  public class ELIterateTag extends IterateTag {
39      /***
40       * Instance variable mapped to "collection" tag attribute. (Mapping set in
41       * associated BeanInfo class.)
42       */
43      private String collectionExpr;
44  
45      /***
46       * Instance variable mapped to "id" tag attribute. (Mapping set in
47       * associated BeanInfo class.)
48       */
49      private String idExpr;
50  
51      /***
52       * Instance variable mapped to "indexId" tag attribute. (Mapping set in
53       * associated BeanInfo class.)
54       */
55      private String indexIdExpr;
56  
57      /***
58       * Instance variable mapped to "length" tag attribute. (Mapping set in
59       * associated BeanInfo class.)
60       */
61      private String lengthExpr;
62  
63      /***
64       * Instance variable mapped to "name" tag attribute. (Mapping set in
65       * associated BeanInfo class.)
66       */
67      private String nameExpr;
68  
69      /***
70       * Instance variable mapped to "offset" tag attribute. (Mapping set in
71       * associated BeanInfo class.)
72       */
73      private String offsetExpr;
74  
75      /***
76       * Instance variable mapped to "property" tag attribute. (Mapping set in
77       * associated BeanInfo class.)
78       */
79      private String propertyExpr;
80  
81      /***
82       * Instance variable mapped to "scope" tag attribute. (Mapping set in
83       * associated BeanInfo class.)
84       */
85      private String scopeExpr;
86  
87      /***
88       * Instance variable mapped to "type" tag attribute. (Mapping set in
89       * associated BeanInfo class.)
90       */
91      private String typeExpr;
92  
93      /***
94       * Getter method for "collection" tag attribute. (Mapping set in
95       * associated BeanInfo class.)
96       */
97      public String getCollectionExpr() {
98          return (collectionExpr);
99      }
100 
101     /***
102      * Getter method for "id" tag attribute. (Mapping set in associated
103      * BeanInfo class.)
104      */
105     public String getIdExpr() {
106         return (idExpr);
107     }
108 
109     /***
110      * Getter method for "indexId" tag attribute. (Mapping set in associated
111      * BeanInfo class.)
112      */
113     public String getIndexIdExpr() {
114         return (indexIdExpr);
115     }
116 
117     /***
118      * Getter method for "length" tag attribute. (Mapping set in associated
119      * BeanInfo class.)
120      */
121     public String getLengthExpr() {
122         return (lengthExpr);
123     }
124 
125     /***
126      * Getter method for "name" tag attribute. (Mapping set in associated
127      * BeanInfo class.)
128      */
129     public String getNameExpr() {
130         return (nameExpr);
131     }
132 
133     /***
134      * Getter method for "offset" tag attribute. (Mapping set in associated
135      * BeanInfo class.)
136      */
137     public String getOffsetExpr() {
138         return (offsetExpr);
139     }
140 
141     /***
142      * Getter method for "property" tag attribute. (Mapping set in associated
143      * BeanInfo class.)
144      */
145     public String getPropertyExpr() {
146         return (propertyExpr);
147     }
148 
149     /***
150      * Getter method for "scope" tag attribute. (Mapping set in associated
151      * BeanInfo class.)
152      */
153     public String getScopeExpr() {
154         return (scopeExpr);
155     }
156 
157     /***
158      * Getter method for "type" tag attribute. (Mapping set in associated
159      * BeanInfo class.)
160      */
161     public String getTypeExpr() {
162         return (typeExpr);
163     }
164 
165     /***
166      * Setter method for "collection" tag attribute. (Mapping set in
167      * associated BeanInfo class.)
168      */
169     public void setCollectionExpr(String collectionExpr) {
170         this.collectionExpr = collectionExpr;
171     }
172 
173     /***
174      * Setter method for "id" tag attribute. (Mapping set in associated
175      * BeanInfo class.)
176      */
177     public void setIdExpr(String idExpr) {
178         this.idExpr = idExpr;
179     }
180 
181     /***
182      * Setter method for "indexId" tag attribute. (Mapping set in associated
183      * BeanInfo class.)
184      */
185     public void setIndexIdExpr(String indexIdExpr) {
186         this.indexIdExpr = indexIdExpr;
187     }
188 
189     /***
190      * Setter method for "length" tag attribute. (Mapping set in associated
191      * BeanInfo class.)
192      */
193     public void setLengthExpr(String lengthExpr) {
194         this.lengthExpr = lengthExpr;
195     }
196 
197     /***
198      * Setter method for "name" tag attribute. (Mapping set in associated
199      * BeanInfo class.)
200      */
201     public void setNameExpr(String nameExpr) {
202         this.nameExpr = nameExpr;
203     }
204 
205     /***
206      * Setter method for "offset" tag attribute. (Mapping set in associated
207      * BeanInfo class.)
208      */
209     public void setOffsetExpr(String offsetExpr) {
210         this.offsetExpr = offsetExpr;
211     }
212 
213     /***
214      * Setter method for "property" tag attribute. (Mapping set in associated
215      * BeanInfo class.)
216      */
217     public void setPropertyExpr(String propertyExpr) {
218         this.propertyExpr = propertyExpr;
219     }
220 
221     /***
222      * Setter method for "scope" tag attribute. (Mapping set in associated
223      * BeanInfo class.)
224      */
225     public void setScopeExpr(String scopeExpr) {
226         this.scopeExpr = scopeExpr;
227     }
228 
229     /***
230      * Setter method for "type" tag attribute. (Mapping set in associated
231      * BeanInfo class.)
232      */
233     public void setTypeExpr(String typeExpr) {
234         this.typeExpr = typeExpr;
235     }
236 
237     /***
238      * Releases state of custom tag so this instance can be reused.
239      */
240     public void release() {
241         super.release();
242         setCollectionExpr(null);
243         setIdExpr(null);
244         setIndexIdExpr(null);
245         setLengthExpr(null);
246         setNameExpr(null);
247         setOffsetExpr(null);
248         setPropertyExpr(null);
249         setScopeExpr(null);
250         setTypeExpr(null);
251     }
252 
253     /***
254      * Process the start tag.
255      *
256      * @throws JspException if a JSP exception has occurred
257      */
258     public int doStartTag() throws JspException {
259         evaluateExpressions();
260 
261         return (super.doStartTag());
262     }
263 
264     /***
265      * Processes all attribute values which use the JSTL expression evaluation
266      * engine to determine their values.
267      *
268      * @throws JspException if a JSP exception has occurred
269      */
270     private void evaluateExpressions()
271         throws JspException {
272         String string = null;
273         Object object = null;
274 
275         if ((object =
276                 EvalHelper.eval("collection", getCollectionExpr(), this,
277                     pageContext)) != null) {
278             setCollection(object);
279         }
280 
281         if ((string =
282                 EvalHelper.evalString("id", getIdExpr(), this, pageContext)) != null) {
283             setId(string);
284         }
285 
286         if ((string =
287                 EvalHelper.evalString("indexId", getIndexIdExpr(), this,
288                     pageContext)) != null) {
289             setIndexId(string);
290         }
291 
292         if ((string =
293                 EvalHelper.evalString("length", getLengthExpr(), this,
294                     pageContext)) != null) {
295             setLength(string);
296         }
297 
298         if ((string =
299                 EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) {
300             setName(string);
301         }
302 
303         if ((string =
304                 EvalHelper.evalString("offset", getOffsetExpr(), this,
305                     pageContext)) != null) {
306             setOffset(string);
307         }
308 
309         if ((string =
310                 EvalHelper.evalString("property", getPropertyExpr(), this,
311                     pageContext)) != null) {
312             setProperty(string);
313         }
314 
315         if ((string =
316                 EvalHelper.evalString("scope", getScopeExpr(), this, pageContext)) != null) {
317             setScope(string);
318         }
319 
320         if ((string =
321                 EvalHelper.evalString("type", getTypeExpr(), this, pageContext)) != null) {
322             setType(string);
323         }
324     }
325 }