001: /*
002: * $Id: ELIterateTag.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.strutsel.taglib.logic;
022:
023: import org.apache.struts.taglib.logic.IterateTag;
024: import org.apache.strutsel.taglib.utils.EvalHelper;
025:
026: import javax.servlet.jsp.JspException;
027:
028: /**
029: * Custom tag that iterates the elements of a collection, which can be either
030: * an attribute or the property of an attribute. The collection can be any of
031: * the following: an array of objects, an Enumeration, an Iterator, a
032: * Collection (which includes Lists, Sets and Vectors), or a Map (which
033: * includes Hashtables) whose elements will be iterated over. <p> This class
034: * is a subclass of the class <code>org.apache.struts.taglib.logic.IterateTag</code>
035: * which provides most of the described functionality. This subclass allows
036: * all attribute values to be specified as expressions utilizing the
037: * JavaServer Pages Standard Library expression language.
038: *
039: * @version $Rev: 471754 $
040: */
041: public class ELIterateTag extends IterateTag {
042: /**
043: * Instance variable mapped to "collection" tag attribute. (Mapping set in
044: * associated BeanInfo class.)
045: */
046: private String collectionExpr;
047:
048: /**
049: * Instance variable mapped to "id" tag attribute. (Mapping set in
050: * associated BeanInfo class.)
051: */
052: private String idExpr;
053:
054: /**
055: * Instance variable mapped to "indexId" tag attribute. (Mapping set in
056: * associated BeanInfo class.)
057: */
058: private String indexIdExpr;
059:
060: /**
061: * Instance variable mapped to "length" tag attribute. (Mapping set in
062: * associated BeanInfo class.)
063: */
064: private String lengthExpr;
065:
066: /**
067: * Instance variable mapped to "name" tag attribute. (Mapping set in
068: * associated BeanInfo class.)
069: */
070: private String nameExpr;
071:
072: /**
073: * Instance variable mapped to "offset" tag attribute. (Mapping set in
074: * associated BeanInfo class.)
075: */
076: private String offsetExpr;
077:
078: /**
079: * Instance variable mapped to "property" tag attribute. (Mapping set in
080: * associated BeanInfo class.)
081: */
082: private String propertyExpr;
083:
084: /**
085: * Instance variable mapped to "scope" tag attribute. (Mapping set in
086: * associated BeanInfo class.)
087: */
088: private String scopeExpr;
089:
090: /**
091: * Instance variable mapped to "type" tag attribute. (Mapping set in
092: * associated BeanInfo class.)
093: */
094: private String typeExpr;
095:
096: /**
097: * Getter method for "collection" tag attribute. (Mapping set in
098: * associated BeanInfo class.)
099: */
100: public String getCollectionExpr() {
101: return (collectionExpr);
102: }
103:
104: /**
105: * Getter method for "id" tag attribute. (Mapping set in associated
106: * BeanInfo class.)
107: */
108: public String getIdExpr() {
109: return (idExpr);
110: }
111:
112: /**
113: * Getter method for "indexId" tag attribute. (Mapping set in associated
114: * BeanInfo class.)
115: */
116: public String getIndexIdExpr() {
117: return (indexIdExpr);
118: }
119:
120: /**
121: * Getter method for "length" tag attribute. (Mapping set in associated
122: * BeanInfo class.)
123: */
124: public String getLengthExpr() {
125: return (lengthExpr);
126: }
127:
128: /**
129: * Getter method for "name" tag attribute. (Mapping set in associated
130: * BeanInfo class.)
131: */
132: public String getNameExpr() {
133: return (nameExpr);
134: }
135:
136: /**
137: * Getter method for "offset" tag attribute. (Mapping set in associated
138: * BeanInfo class.)
139: */
140: public String getOffsetExpr() {
141: return (offsetExpr);
142: }
143:
144: /**
145: * Getter method for "property" tag attribute. (Mapping set in associated
146: * BeanInfo class.)
147: */
148: public String getPropertyExpr() {
149: return (propertyExpr);
150: }
151:
152: /**
153: * Getter method for "scope" tag attribute. (Mapping set in associated
154: * BeanInfo class.)
155: */
156: public String getScopeExpr() {
157: return (scopeExpr);
158: }
159:
160: /**
161: * Getter method for "type" tag attribute. (Mapping set in associated
162: * BeanInfo class.)
163: */
164: public String getTypeExpr() {
165: return (typeExpr);
166: }
167:
168: /**
169: * Setter method for "collection" tag attribute. (Mapping set in
170: * associated BeanInfo class.)
171: */
172: public void setCollectionExpr(String collectionExpr) {
173: this .collectionExpr = collectionExpr;
174: }
175:
176: /**
177: * Setter method for "id" tag attribute. (Mapping set in associated
178: * BeanInfo class.)
179: */
180: public void setIdExpr(String idExpr) {
181: this .idExpr = idExpr;
182: }
183:
184: /**
185: * Setter method for "indexId" tag attribute. (Mapping set in associated
186: * BeanInfo class.)
187: */
188: public void setIndexIdExpr(String indexIdExpr) {
189: this .indexIdExpr = indexIdExpr;
190: }
191:
192: /**
193: * Setter method for "length" tag attribute. (Mapping set in associated
194: * BeanInfo class.)
195: */
196: public void setLengthExpr(String lengthExpr) {
197: this .lengthExpr = lengthExpr;
198: }
199:
200: /**
201: * Setter method for "name" tag attribute. (Mapping set in associated
202: * BeanInfo class.)
203: */
204: public void setNameExpr(String nameExpr) {
205: this .nameExpr = nameExpr;
206: }
207:
208: /**
209: * Setter method for "offset" tag attribute. (Mapping set in associated
210: * BeanInfo class.)
211: */
212: public void setOffsetExpr(String offsetExpr) {
213: this .offsetExpr = offsetExpr;
214: }
215:
216: /**
217: * Setter method for "property" tag attribute. (Mapping set in associated
218: * BeanInfo class.)
219: */
220: public void setPropertyExpr(String propertyExpr) {
221: this .propertyExpr = propertyExpr;
222: }
223:
224: /**
225: * Setter method for "scope" tag attribute. (Mapping set in associated
226: * BeanInfo class.)
227: */
228: public void setScopeExpr(String scopeExpr) {
229: this .scopeExpr = scopeExpr;
230: }
231:
232: /**
233: * Setter method for "type" tag attribute. (Mapping set in associated
234: * BeanInfo class.)
235: */
236: public void setTypeExpr(String typeExpr) {
237: this .typeExpr = typeExpr;
238: }
239:
240: /**
241: * Releases state of custom tag so this instance can be reused.
242: */
243: public void release() {
244: super .release();
245: setCollectionExpr(null);
246: setIdExpr(null);
247: setIndexIdExpr(null);
248: setLengthExpr(null);
249: setNameExpr(null);
250: setOffsetExpr(null);
251: setPropertyExpr(null);
252: setScopeExpr(null);
253: setTypeExpr(null);
254: }
255:
256: /**
257: * Process the start tag.
258: *
259: * @throws JspException if a JSP exception has occurred
260: */
261: public int doStartTag() throws JspException {
262: evaluateExpressions();
263:
264: return (super .doStartTag());
265: }
266:
267: /**
268: * Processes all attribute values which use the JSTL expression evaluation
269: * engine to determine their values.
270: *
271: * @throws JspException if a JSP exception has occurred
272: */
273: private void evaluateExpressions() throws JspException {
274: String string = null;
275: Object object = null;
276:
277: if ((object = EvalHelper.eval("collection",
278: getCollectionExpr(), this , pageContext)) != null) {
279: setCollection(object);
280: }
281:
282: if ((string = EvalHelper.evalString("id", getIdExpr(), this ,
283: pageContext)) != null) {
284: setId(string);
285: }
286:
287: if ((string = EvalHelper.evalString("indexId",
288: getIndexIdExpr(), this , pageContext)) != null) {
289: setIndexId(string);
290: }
291:
292: if ((string = EvalHelper.evalString("length", getLengthExpr(),
293: this , pageContext)) != null) {
294: setLength(string);
295: }
296:
297: if ((string = EvalHelper.evalString("name", getNameExpr(),
298: this , pageContext)) != null) {
299: setName(string);
300: }
301:
302: if ((string = EvalHelper.evalString("offset", getOffsetExpr(),
303: this , pageContext)) != null) {
304: setOffset(string);
305: }
306:
307: if ((string = EvalHelper.evalString("property",
308: getPropertyExpr(), this , pageContext)) != null) {
309: setProperty(string);
310: }
311:
312: if ((string = EvalHelper.evalString("scope", getScopeExpr(),
313: this , pageContext)) != null) {
314: setScope(string);
315: }
316:
317: if ((string = EvalHelper.evalString("type", getTypeExpr(),
318: this, pageContext)) != null) {
319: setType(string);
320: }
321: }
322: }
|