View Javadoc

1   /*
2    * $Id: ELSizeTag.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.SizeTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Define a scripting variable that will contain the number of elements found
27   * in a specified array, Collection, or Map. <p> This class is a subclass of
28   * the class <code>org.apache.struts.taglib.bean.SizeTag</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: 376778 $
34   */
35  public class ELSizeTag extends SizeTag {
36      /***
37       * Instance variable mapped to "collection" tag attribute. (Mapping set in
38       * associated BeanInfo class.)
39       */
40      private String collectionExpr;
41  
42      /***
43       * Instance variable mapped to "id" tag attribute. (Mapping set in
44       * associated BeanInfo class.)
45       */
46      private String idExpr;
47  
48      /***
49       * Instance variable mapped to "name" tag attribute. (Mapping set in
50       * associated BeanInfo class.)
51       */
52      private String nameExpr;
53  
54      /***
55       * Instance variable mapped to "property" tag attribute. (Mapping set in
56       * associated BeanInfo class.)
57       */
58      private String propertyExpr;
59  
60      /***
61       * Instance variable mapped to "scope" tag attribute. (Mapping set in
62       * associated BeanInfo class.)
63       */
64      private String scopeExpr;
65  
66      /***
67       * Getter method for "collection" tag attribute. (Mapping set in
68       * associated BeanInfo class.)
69       */
70      public String getCollectionExpr() {
71          return (collectionExpr);
72      }
73  
74      /***
75       * Getter method for "id" tag attribute. (Mapping set in associated
76       * BeanInfo class.)
77       */
78      public String getIdExpr() {
79          return (idExpr);
80      }
81  
82      /***
83       * Getter method for "name" tag attribute. (Mapping set in associated
84       * BeanInfo class.)
85       */
86      public String getNameExpr() {
87          return (nameExpr);
88      }
89  
90      /***
91       * Getter method for "property" tag attribute. (Mapping set in associated
92       * BeanInfo class.)
93       */
94      public String getPropertyExpr() {
95          return (propertyExpr);
96      }
97  
98      /***
99       * Getter method for "scope" tag attribute. (Mapping set in associated
100      * BeanInfo class.)
101      */
102     public String getScopeExpr() {
103         return (scopeExpr);
104     }
105 
106     /***
107      * Setter method for "collection" tag attribute. (Mapping set in
108      * associated BeanInfo class.)
109      */
110     public void setCollectionExpr(String collectionExpr) {
111         this.collectionExpr = collectionExpr;
112     }
113 
114     /***
115      * Setter method for "id" tag attribute. (Mapping set in associated
116      * BeanInfo class.)
117      */
118     public void setIdExpr(String idExpr) {
119         this.idExpr = idExpr;
120     }
121 
122     /***
123      * Setter method for "name" tag attribute. (Mapping set in associated
124      * BeanInfo class.)
125      */
126     public void setNameExpr(String nameExpr) {
127         this.nameExpr = nameExpr;
128     }
129 
130     /***
131      * Setter method for "property" tag attribute. (Mapping set in associated
132      * BeanInfo class.)
133      */
134     public void setPropertyExpr(String propertyExpr) {
135         this.propertyExpr = propertyExpr;
136     }
137 
138     /***
139      * Setter method for "scope" tag attribute. (Mapping set in associated
140      * BeanInfo class.)
141      */
142     public void setScopeExpr(String scopeExpr) {
143         this.scopeExpr = scopeExpr;
144     }
145 
146     /***
147      * Releases state of custom tag so this instance can be reused.
148      */
149     public void release() {
150         super.release();
151         setCollectionExpr(null);
152         setIdExpr(null);
153         setNameExpr(null);
154         setPropertyExpr(null);
155         setScopeExpr(null);
156     }
157 
158     /***
159      * Process the start tag.
160      *
161      * @throws JspException if a JSP exception has occurred
162      */
163     public int doStartTag() throws JspException {
164         evaluateExpressions();
165 
166         return (super.doStartTag());
167     }
168 
169     /***
170      * Processes all attribute values which use the JSTL expression evaluation
171      * engine to determine their values.
172      *
173      * @throws JspException if a JSP exception has occurred
174      */
175     private void evaluateExpressions()
176         throws JspException {
177         String string = null;
178         Object object = null;
179 
180         if ((object =
181                 EvalHelper.eval("collection", getCollectionExpr(), this,
182                     pageContext)) != null) {
183             setCollection(object);
184         }
185 
186         if ((string =
187                 EvalHelper.evalString("id", getIdExpr(), this, pageContext)) != null) {
188             setId(string);
189         }
190 
191         if ((string =
192                 EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) {
193             setName(string);
194         }
195 
196         if ((string =
197                 EvalHelper.evalString("property", getPropertyExpr(), this,
198                     pageContext)) != null) {
199             setProperty(string);
200         }
201 
202         if ((string =
203                 EvalHelper.evalString("scope", getScopeExpr(), this, pageContext)) != null) {
204             setScope(string);
205         }
206     }
207 }