KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > strutsel > taglib > tiles > ELPutTag


1 /*
2  * $Id: ELPutTag.java 54933 2004-10-16 17:04:52Z germuska $
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
19 package org.apache.strutsel.taglib.tiles;
20
21 import org.apache.struts.taglib.tiles.PutTag;
22 import javax.servlet.jsp.JspException JavaDoc;
23 import org.apache.strutsel.taglib.utils.EvalHelper;
24
25 /**
26  * Put an attribute in enclosing attribute container tag.
27  * Enclosing attribute container tag can be : <insert> or <definition>.
28  * Exception is thrown if no appropriate tag can be found.
29  * Put tag can have following atributes :
30  * <li>
31  * <ul>name : Name of the attribute</ul>
32  * <ul>value | content : value to put as attribute</ul>
33  * <ul>type : value type. Only valid if value is a String and is set by
34  * value="something" or by a bean.
35  * Possible type are : string (value is used as direct string),
36  * page | template (value is used as a page url to insert),
37  * definition (value is used as a definition name to insert)</ul>
38  * <ul>direct : Specify if value is to be used as a direct string or as a
39  * page url to insert. This is another way to specify the type. It only apply
40  * if value is set as a string, and type is not present.</ul>
41  * <ul>beanName : Name of a bean used for setting value. Only valid if value is not set.
42  * If property is specified, value come from bean's property. Otherwise, bean
43  * itself is used for value.</ul>
44  * <ul>beanProperty : Name of the property used for retrieving value.</ul>
45  * <ul>beanScope : Scope containing bean. </ul>
46  * <ul>role : Role to check when 'insert' will be called. If enclosing tag is
47  * &lt;insert&gt;, role is checked immediately. If enclosing tag is
48  * &lt;definition&gt;, role will be checked when this definition will be
49  * inserted.</ul>
50  * </li>
51  * Value can also come from tag body. Tag body is taken into account only if
52  * value is not set by one of the tag attributes. In this case Attribute type is
53  * "string", unless tag body define another type.
54  *<p>
55  * This class is a subclass of the class
56  * <code>org.apache.struts.taglib.tiles.PutTag</code> which provides most of
57  * the described functionality. This subclass allows all attribute values to
58  * be specified as expressions utilizing the JavaServer Pages Standard Library
59  * expression language.
60  *
61  * @version $Rev: 54933 $
62  */

63 public class ELPutTag extends PutTag {
64
65     /**
66      * Instance variable mapped to "name" tag attribute.
67      * (Mapping set in associated BeanInfo class.)
68      */

69     private String JavaDoc nameExpr;
70     /**
71      * Instance variable mapped to "value" tag attribute.
72      * (Mapping set in associated BeanInfo class.)
73      */

74     private String JavaDoc valueExpr;
75     /**
76      * Instance variable mapped to "content" tag attribute.
77      * (Mapping set in associated BeanInfo class.)
78      */

79     private String JavaDoc contentExpr;
80     /**
81      * Instance variable mapped to "direct" tag attribute.
82      * (Mapping set in associated BeanInfo class.)
83      */

84     private String JavaDoc directExpr;
85     /**
86      * Instance variable mapped to "type" tag attribute.
87      * (Mapping set in associated BeanInfo class.)
88      */

89     private String JavaDoc typeExpr;
90     /**
91      * Instance variable mapped to "beanName" tag attribute.
92      * (Mapping set in associated BeanInfo class.)
93      */

94     private String JavaDoc beanNameExpr;
95     /**
96      * Instance variable mapped to "beanProperty" tag attribute.
97      * (Mapping set in associated BeanInfo class.)
98      */

99     private String JavaDoc beanPropertyExpr;
100     /**
101      * Instance variable mapped to "beanScope" tag attribute.
102      * (Mapping set in associated BeanInfo class.)
103      */

104     private String JavaDoc beanScopeExpr;
105     /**
106      * Instance variable mapped to "role" tag attribute.
107      * (Mapping set in associated BeanInfo class.)
108      */

109     private String JavaDoc roleExpr;
110
111     /**
112      * Getter method for "name" tag attribute.
113      * (Mapping set in associated BeanInfo class.)
114      */

115     public String JavaDoc getNameExpr() { return (nameExpr); }
116     /**
117      * Getter method for "value" tag attribute.
118      * (Mapping set in associated BeanInfo class.)
119      */

120     public String JavaDoc getValueExpr() { return (valueExpr); }
121     /**
122      * Getter method for "content" tag attribute.
123      * (Mapping set in associated BeanInfo class.)
124      */

125     public String JavaDoc getContentExpr() { return (contentExpr); }
126     /**
127      * Getter method for "direct" tag attribute.
128      * (Mapping set in associated BeanInfo class.)
129      */

130     public String JavaDoc getDirectExpr() { return (directExpr); }
131     /**
132      * Getter method for "type" tag attribute.
133      * (Mapping set in associated BeanInfo class.)
134      */

135     public String JavaDoc getTypeExpr() { return (typeExpr); }
136     /**
137      * Getter method for "beanName" tag attribute.
138      * (Mapping set in associated BeanInfo class.)
139      */

140     public String JavaDoc getBeanNameExpr() { return (beanNameExpr); }
141     /**
142      * Getter method for "beanProperty" tag attribute.
143      * (Mapping set in associated BeanInfo class.)
144      */

145     public String JavaDoc getBeanPropertyExpr() { return (beanPropertyExpr); }
146     /**
147      * Getter method for "beanScope" tag attribute.
148      * (Mapping set in associated BeanInfo class.)
149      */

150     public String JavaDoc getBeanScopeExpr() { return (beanScopeExpr); }
151     /**
152      * Getter method for "role" tag attribute.
153      * (Mapping set in associated BeanInfo class.)
154      */

155     public String JavaDoc getRoleExpr() { return (roleExpr); }
156
157     /**
158      * Setter method for "name" tag attribute.
159      * (Mapping set in associated BeanInfo class.)
160      */

161     public void setNameExpr(String JavaDoc nameExpr) { this.nameExpr = nameExpr; }
162     /**
163      * Setter method for "value" tag attribute.
164      * (Mapping set in associated BeanInfo class.)
165      */

166     public void setValueExpr(String JavaDoc valueExpr) { this.valueExpr = valueExpr; }
167     /**
168      * Setter method for "content" tag attribute.
169      * (Mapping set in associated BeanInfo class.)
170      */

171     public void setContentExpr(String JavaDoc contentExpr) { this.contentExpr = contentExpr; }
172     /**
173      * Setter method for "direct" tag attribute.
174      * (Mapping set in associated BeanInfo class.)
175      */

176     public void setDirectExpr(String JavaDoc directExpr) { this.directExpr = directExpr; }
177     /**
178      * Setter method for "type" tag attribute.
179      * (Mapping set in associated BeanInfo class.)
180      */

181     public void setTypeExpr(String JavaDoc typeExpr) { this.typeExpr = typeExpr; }
182     /**
183      * Setter method for "beanName" tag attribute.
184      * (Mapping set in associated BeanInfo class.)
185      */

186     public void setBeanNameExpr(String JavaDoc beanNameExpr) { this.beanNameExpr = beanNameExpr; }
187     /**
188      * Setter method for "beanProperty" tag attribute.
189      * (Mapping set in associated BeanInfo class.)
190      */

191     public void setBeanPropertyExpr(String JavaDoc beanPropertyExpr) { this.beanPropertyExpr = beanPropertyExpr; }
192     /**
193      * Setter method for "beanScope" tag attribute.
194      * (Mapping set in associated BeanInfo class.)
195      */

196     public void setBeanScopeExpr(String JavaDoc beanScopeExpr) { this.beanScopeExpr = beanScopeExpr; }
197     /**
198      * Setter method for "role" tag attribute.
199      * (Mapping set in associated BeanInfo class.)
200      */

201     public void setRoleExpr(String JavaDoc roleExpr) { this.roleExpr = roleExpr; }
202
203     /**
204      * Resets attribute values for tag reuse.
205      */

206     public void release()
207     {
208         super.release();
209         setNameExpr(null);
210         setValueExpr(null);
211         setContentExpr(null);
212         setDirectExpr(null);
213         setTypeExpr(null);
214         setBeanNameExpr(null);
215         setBeanPropertyExpr(null);
216         setBeanScopeExpr(null);
217         setRoleExpr(null);
218     }
219     
220     /**
221      * Process the start tag.
222      *
223      * @exception JspException if a JSP exception has occurred
224      */

225     public int doStartTag() throws JspException JavaDoc {
226         evaluateExpressions();
227         return (super.doStartTag());
228     }
229     
230     /**
231      * Processes all attribute values which use the JSTL expression evaluation
232      * engine to determine their values.
233      *
234      * @exception JspException if a JSP exception has occurred
235      */

236     private void evaluateExpressions() throws JspException JavaDoc {
237         String JavaDoc string = null;
238
239         if ((string = EvalHelper.evalString("name", getNameExpr(),
240                                             this, pageContext)) != null)
241             setName(string);
242         if ((string = EvalHelper.evalString("value", getValueExpr(),
243                                             this, pageContext)) != null)
244             setValue(string);
245         if ((string = EvalHelper.evalString("content", getContentExpr(),
246                                             this, pageContext)) != null)
247             setContent(string);
248         if ((string = EvalHelper.evalString("direct", getDirectExpr(),
249                                             this, pageContext)) != null)
250             setDirect(string);
251         if ((string = EvalHelper.evalString("type", getTypeExpr(),
252                                             this, pageContext)) != null)
253             setType(string);
254         if ((string = EvalHelper.evalString("beanName", getBeanNameExpr(),
255                                             this, pageContext)) != null)
256             setBeanName(string);
257         if ((string = EvalHelper.evalString("beanProperty", getBeanPropertyExpr(),
258                                             this, pageContext)) != null)
259             setBeanProperty(string);
260         if ((string = EvalHelper.evalString("beanScope", getBeanScopeExpr(),
261                                             this, pageContext)) != null)
262             setBeanScope(string);
263         if ((string = EvalHelper.evalString("role", getRoleExpr(),
264                                             this, pageContext)) != null)
265             setRole(string);
266     }
267 }
268
Popular Tags