View Javadoc

1   /*
2    * $Id: ELUseAttributeTag.java 376781 2006-02-10 18:09:48Z 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.tiles;
19  
20  import org.apache.struts.tiles.taglib.UseAttributeTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Custom tag exposing a component attribute to page. <p> This class is a
27   * subclass of the class <code>org.apache.struts.taglib.tiles.UseAttributeTag</code>
28   * which provides most of the described functionality.  This subclass allows
29   * all attribute values to be specified as expressions utilizing the
30   * JavaServer Pages Standard Library expression language.
31   *
32   * @version $Rev: 376781 $
33   */
34  public class ELUseAttributeTag extends UseAttributeTag {
35      /***
36       * Instance variable mapped to "id" tag attribute. (Mapping set in
37       * associated BeanInfo class.)
38       */
39      private String idExpr;
40  
41      /***
42       * Instance variable mapped to "classname" tag attribute. (Mapping set in
43       * associated BeanInfo class.)
44       */
45      private String classnameExpr;
46  
47      /***
48       * Instance variable mapped to "scope" tag attribute. (Mapping set in
49       * associated BeanInfo class.)
50       */
51      private String scopeExpr;
52  
53      /***
54       * Instance variable mapped to "name" tag attribute. (Mapping set in
55       * associated BeanInfo class.)
56       */
57      private String nameExpr;
58  
59      /***
60       * Instance variable mapped to "ignore" tag attribute. (Mapping set in
61       * associated BeanInfo class.)
62       */
63      private String ignoreExpr;
64  
65      /***
66       * Getter method for "id" tag attribute. (Mapping set in associated
67       * BeanInfo class.)
68       */
69      public String getIdExpr() {
70          return (idExpr);
71      }
72  
73      /***
74       * Getter method for "classname" tag attribute. (Mapping set in associated
75       * BeanInfo class.)
76       */
77      public String getClassnameExpr() {
78          return (classnameExpr);
79      }
80  
81      /***
82       * Getter method for "scope" tag attribute. (Mapping set in associated
83       * BeanInfo class.)
84       */
85      public String getScopeExpr() {
86          return (scopeExpr);
87      }
88  
89      /***
90       * Getter method for "name" tag attribute. (Mapping set in associated
91       * BeanInfo class.)
92       */
93      public String getNameExpr() {
94          return (nameExpr);
95      }
96  
97      /***
98       * Getter method for "ignore" tag attribute. (Mapping set in associated
99       * BeanInfo class.)
100      */
101     public String getIgnoreExpr() {
102         return (ignoreExpr);
103     }
104 
105     /***
106      * Setter method for "id" tag attribute. (Mapping set in associated
107      * BeanInfo class.)
108      */
109     public void setIdExpr(String idExpr) {
110         this.idExpr = idExpr;
111     }
112 
113     /***
114      * Setter method for "classname" tag attribute. (Mapping set in associated
115      * BeanInfo class.)
116      */
117     public void setClassnameExpr(String classnameExpr) {
118         this.classnameExpr = classnameExpr;
119     }
120 
121     /***
122      * Setter method for "scope" tag attribute. (Mapping set in associated
123      * BeanInfo class.)
124      */
125     public void setScopeExpr(String scopeExpr) {
126         this.scopeExpr = scopeExpr;
127     }
128 
129     /***
130      * Setter method for "name" tag attribute. (Mapping set in associated
131      * BeanInfo class.)
132      */
133     public void setNameExpr(String nameExpr) {
134         this.nameExpr = nameExpr;
135     }
136 
137     /***
138      * Setter method for "ignore" tag attribute. (Mapping set in associated
139      * BeanInfo class.)
140      */
141     public void setIgnoreExpr(String ignoreExpr) {
142         this.ignoreExpr = ignoreExpr;
143     }
144 
145     /***
146      * Resets attribute values for tag reuse.
147      */
148     public void release() {
149         super.release();
150         setIdExpr(null);
151         setClassnameExpr(null);
152         setScopeExpr(null);
153         setNameExpr(null);
154         setIgnoreExpr(null);
155     }
156 
157     /***
158      * Process the start tag.
159      *
160      * @throws JspException if a JSP exception has occurred
161      */
162     public int doStartTag() throws JspException {
163         evaluateExpressions();
164 
165         return (super.doStartTag());
166     }
167 
168     /***
169      * Processes all attribute values which use the JSTL expression evaluation
170      * engine to determine their values.
171      *
172      * @throws JspException if a JSP exception has occurred
173      */
174     private void evaluateExpressions()
175         throws JspException {
176         String string = null;
177         Boolean bool = null;
178 
179         if ((string =
180                 EvalHelper.evalString("id", getIdExpr(), this, pageContext)) != null) {
181             setId(string);
182         }
183 
184         if ((string =
185                 EvalHelper.evalString("classname", getClassnameExpr(), this,
186                     pageContext)) != null) {
187             setClassname(string);
188         }
189 
190         if ((string =
191                 EvalHelper.evalString("scope", getScopeExpr(), this, pageContext)) != null) {
192             setScope(string);
193         }
194 
195         if ((string =
196                 EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) {
197             setName(string);
198         }
199 
200         if ((bool =
201                 EvalHelper.evalBoolean("ignore", getIgnoreExpr(), this,
202                     pageContext)) != null) {
203             setIgnore(bool.booleanValue());
204         }
205     }
206 }