1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.strutsel.taglib.tiles;
19
20 import org.apache.struts.tiles.taglib.PutTag;
21 import org.apache.strutsel.taglib.utils.EvalHelper;
22
23 import javax.servlet.jsp.JspException;
24
25 /***
26 * <p>Put an attribute in enclosing attribute container tag. Enclosing
27 * attribute container tag can be : <insert> or <definition>.
28 * Exception is thrown if no appropriate tag can be found. Put tag can have
29 * following atributes :</p>
30 *
31 * <ul>
32 *
33 * <li>name : Name of the attribute</li>
34 *
35 * <li>value | content : value to put as attribute</li>
36 *
37 * <li>type : value type. Only valid if value is a String and is set by
38 * value="something" or by a bean. Possible type are : string (value is used
39 * as direct string), page | template (value is used as a page url to insert),
40 * definition (value is used as a definition name to insert)</li>
41 *
42 * <li>direct : Specify if value is to be used as a direct string or as a page
43 * url to insert. This is another way to specify the type. It only apply if
44 * value is set as a string, and type is not present.</li>
45 *
46 * <li>beanName : Name of a bean used for setting value. Only valid if value
47 * is not set. If property is specified, value come from bean's property.
48 * Otherwise, bean itself is used for value.</li>
49 *
50 * <li>beanProperty : Name of the property used for retrieving value.</li>
51 *
52 * <li>beanScope : Scope containing bean. </li>
53 *
54 * <li>role : Role to check when 'insert' will be called. If enclosing tag is
55 * <insert>, role is checked immediately. If enclosing tag is
56 * <definition>, role will be checked when this definition will be
57 * inserted.</li>
58 *
59 * </li> Value can also come from tag body. Tag body is taken into account
60 * only if value is not set by one of the tag attributes. In this case
61 * Attribute type is "string", unless tag body define another type.</li>
62 *
63 * </ul>
64 *
65 * <p> This class is a subclass of the class <code>org.apache.struts.taglib.tiles.PutTag</code>
66 * which provides most of the described functionality. This subclass allows
67 * all attribute values to be specified as expressions utilizing the
68 * JavaServer Pages Standard Library expression language. </p>
69 *
70 * @version $Rev: 376781 $
71 */
72 public class ELPutTag extends PutTag {
73 /***
74 * Instance variable mapped to "name" tag attribute. (Mapping set in
75 * associated BeanInfo class.)
76 */
77 private String nameExpr;
78
79 /***
80 * Instance variable mapped to "value" tag attribute. (Mapping set in
81 * associated BeanInfo class.)
82 */
83 private String valueExpr;
84
85 /***
86 * Instance variable mapped to "content" tag attribute. (Mapping set in
87 * associated BeanInfo class.)
88 */
89 private String contentExpr;
90
91 /***
92 * Instance variable mapped to "direct" tag attribute. (Mapping set in
93 * associated BeanInfo class.)
94 */
95 private String directExpr;
96
97 /***
98 * Instance variable mapped to "type" tag attribute. (Mapping set in
99 * associated BeanInfo class.)
100 */
101 private String typeExpr;
102
103 /***
104 * Instance variable mapped to "beanName" tag attribute. (Mapping set in
105 * associated BeanInfo class.)
106 */
107 private String beanNameExpr;
108
109 /***
110 * Instance variable mapped to "beanProperty" tag attribute. (Mapping set
111 * in associated BeanInfo class.)
112 */
113 private String beanPropertyExpr;
114
115 /***
116 * Instance variable mapped to "beanScope" tag attribute. (Mapping set in
117 * associated BeanInfo class.)
118 */
119 private String beanScopeExpr;
120
121 /***
122 * Instance variable mapped to "role" tag attribute. (Mapping set in
123 * associated BeanInfo class.)
124 */
125 private String roleExpr;
126
127 /***
128 * Getter method for "name" tag attribute. (Mapping set in associated
129 * BeanInfo class.)
130 */
131 public String getNameExpr() {
132 return (nameExpr);
133 }
134
135 /***
136 * Getter method for "value" tag attribute. (Mapping set in associated
137 * BeanInfo class.)
138 */
139 public String getValueExpr() {
140 return (valueExpr);
141 }
142
143 /***
144 * Getter method for "content" tag attribute. (Mapping set in associated
145 * BeanInfo class.)
146 */
147 public String getContentExpr() {
148 return (contentExpr);
149 }
150
151 /***
152 * Getter method for "direct" tag attribute. (Mapping set in associated
153 * BeanInfo class.)
154 */
155 public String getDirectExpr() {
156 return (directExpr);
157 }
158
159 /***
160 * Getter method for "type" tag attribute. (Mapping set in associated
161 * BeanInfo class.)
162 */
163 public String getTypeExpr() {
164 return (typeExpr);
165 }
166
167 /***
168 * Getter method for "beanName" tag attribute. (Mapping set in associated
169 * BeanInfo class.)
170 */
171 public String getBeanNameExpr() {
172 return (beanNameExpr);
173 }
174
175 /***
176 * Getter method for "beanProperty" tag attribute. (Mapping set in
177 * associated BeanInfo class.)
178 */
179 public String getBeanPropertyExpr() {
180 return (beanPropertyExpr);
181 }
182
183 /***
184 * Getter method for "beanScope" tag attribute. (Mapping set in associated
185 * BeanInfo class.)
186 */
187 public String getBeanScopeExpr() {
188 return (beanScopeExpr);
189 }
190
191 /***
192 * Getter method for "role" tag attribute. (Mapping set in associated
193 * BeanInfo class.)
194 */
195 public String getRoleExpr() {
196 return (roleExpr);
197 }
198
199 /***
200 * Setter method for "name" tag attribute. (Mapping set in associated
201 * BeanInfo class.)
202 */
203 public void setNameExpr(String nameExpr) {
204 this.nameExpr = nameExpr;
205 }
206
207 /***
208 * Setter method for "value" tag attribute. (Mapping set in associated
209 * BeanInfo class.)
210 */
211 public void setValueExpr(String valueExpr) {
212 this.valueExpr = valueExpr;
213 }
214
215 /***
216 * Setter method for "content" tag attribute. (Mapping set in associated
217 * BeanInfo class.)
218 */
219 public void setContentExpr(String contentExpr) {
220 this.contentExpr = contentExpr;
221 }
222
223 /***
224 * Setter method for "direct" tag attribute. (Mapping set in associated
225 * BeanInfo class.)
226 */
227 public void setDirectExpr(String directExpr) {
228 this.directExpr = directExpr;
229 }
230
231 /***
232 * Setter method for "type" tag attribute. (Mapping set in associated
233 * BeanInfo class.)
234 */
235 public void setTypeExpr(String typeExpr) {
236 this.typeExpr = typeExpr;
237 }
238
239 /***
240 * Setter method for "beanName" tag attribute. (Mapping set in associated
241 * BeanInfo class.)
242 */
243 public void setBeanNameExpr(String beanNameExpr) {
244 this.beanNameExpr = beanNameExpr;
245 }
246
247 /***
248 * Setter method for "beanProperty" tag attribute. (Mapping set in
249 * associated BeanInfo class.)
250 */
251 public void setBeanPropertyExpr(String beanPropertyExpr) {
252 this.beanPropertyExpr = beanPropertyExpr;
253 }
254
255 /***
256 * Setter method for "beanScope" tag attribute. (Mapping set in associated
257 * BeanInfo class.)
258 */
259 public void setBeanScopeExpr(String beanScopeExpr) {
260 this.beanScopeExpr = beanScopeExpr;
261 }
262
263 /***
264 * Setter method for "role" tag attribute. (Mapping set in associated
265 * BeanInfo class.)
266 */
267 public void setRoleExpr(String roleExpr) {
268 this.roleExpr = roleExpr;
269 }
270
271 /***
272 * Resets attribute values for tag reuse.
273 */
274 public void release() {
275 super.release();
276 setNameExpr(null);
277 setValueExpr(null);
278 setContentExpr(null);
279 setDirectExpr(null);
280 setTypeExpr(null);
281 setBeanNameExpr(null);
282 setBeanPropertyExpr(null);
283 setBeanScopeExpr(null);
284 setRoleExpr(null);
285 }
286
287 /***
288 * Process the start tag.
289 *
290 * @throws JspException if a JSP exception has occurred
291 */
292 public int doStartTag() throws JspException {
293 evaluateExpressions();
294
295 return (super.doStartTag());
296 }
297
298 /***
299 * Processes all attribute values which use the JSTL expression evaluation
300 * engine to determine their values.
301 *
302 * @throws JspException if a JSP exception has occurred
303 */
304 private void evaluateExpressions()
305 throws JspException {
306 String string = null;
307
308 if ((string =
309 EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) {
310 setName(string);
311 }
312
313 if ((string =
314 EvalHelper.evalString("value", getValueExpr(), this, pageContext)) != null) {
315 setValue(string);
316 }
317
318 if ((string =
319 EvalHelper.evalString("content", getContentExpr(), this,
320 pageContext)) != null) {
321 setContent(string);
322 }
323
324 if ((string =
325 EvalHelper.evalString("direct", getDirectExpr(), this,
326 pageContext)) != null) {
327 setDirect(string);
328 }
329
330 if ((string =
331 EvalHelper.evalString("type", getTypeExpr(), this, pageContext)) != null) {
332 setType(string);
333 }
334
335 if ((string =
336 EvalHelper.evalString("beanName", getBeanNameExpr(), this,
337 pageContext)) != null) {
338 setBeanName(string);
339 }
340
341 if ((string =
342 EvalHelper.evalString("beanProperty", getBeanPropertyExpr(),
343 this, pageContext)) != null) {
344 setBeanProperty(string);
345 }
346
347 if ((string =
348 EvalHelper.evalString("beanScope", getBeanScopeExpr(), this,
349 pageContext)) != null) {
350 setBeanScope(string);
351 }
352
353 if ((string =
354 EvalHelper.evalString("role", getRoleExpr(), this, pageContext)) != null) {
355 setRole(string);
356 }
357 }
358 }