View Javadoc

1   /*
2    * This file was automatically generated by Apache Tiles Autotag.
3    */
4   package org.apache.tiles.jsp.taglib;
5   
6   import java.io.IOException;
7   
8   import javax.servlet.jsp.JspException;
9   import javax.servlet.jsp.tagext.SimpleTagSupport;
10  
11  import org.apache.tiles.autotag.core.runtime.ModelBody;
12  import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
13  
14  /**
15   * <p>
16   * <strong>Put an attribute in enclosing attribute container tag.</strong>
17   * </p>
18   * <p>
19   * Enclosing attribute container tag can be :
20   * <ul>
21   * <li>&lt;initContainer&gt;</li>
22   * <li>&lt;definition&gt;</li>
23   * <li>&lt;insertAttribute&gt;</li>
24   * <li>&lt;insertDefinition&gt;</li>
25   * <li>&lt;putListAttribute&gt;</li>
26   * </ul>
27   * (or any other tag which implements the <code>PutAttributeTagParent</code>
28   * interface. Exception is thrown if no appropriate tag can be found.
29   * </p>
30   * <p>
31   * Put tag can have following atributes :
32   * <ul>
33   * <li>name : Name of the attribute</li>
34   * <li>value : value to put as attribute</li>
35   * <li>type : value type. Possible type are : string (value is used as direct
36   * string), template (value is used as a page url to insert), definition (value
37   * is used as a definition name to insert), object (value is used as it is)</li>
38   * <li>role : Role to check when 'insertAttribute' will be called.</li>
39   * </ul>
40   * </p>
41   * <p>
42   * Value can also come from tag body. Tag body is taken into account only if
43   * value is not set by one of the tag attributes. In this case Attribute type is
44   * "string", unless tag body define another type.
45   * </p>
46   */
47  public class PutAttributeTag extends SimpleTagSupport {
48  
49      /**
50       * The template model.
51       */
52      private org.apache.tiles.template.PutAttributeModel model = new org.apache.tiles.template.PutAttributeModel();
53  
54      /**
55       * The name of the attribute to put.
56       */
57      private java.lang.String name;
58  
59      /**
60       * The value of the attribute. Use this parameter, or
61       * expression, or body.
62       */
63      private java.lang.Object value;
64  
65      /**
66       * The expression to calculate the value from. Use this
67       * parameter, or value, or body.
68       */
69      private java.lang.String expression;
70  
71      /**
72       * A comma-separated list of roles. If present, the attribute
73       * will be rendered only if the current user belongs to one of the roles.
74       */
75      private java.lang.String role;
76  
77      /**
78       * The type (renderer) of the attribute.
79       */
80      private java.lang.String type;
81  
82      /**
83       * If <code>true</code> the attribute will be cascaded to all nested attributes.
84       */
85      private boolean cascade;
86  
87      /**
88       * Getter for name property.
89       *
90       * @return
91       * The name of the attribute to put.
92       */
93      public java.lang.String getName() {
94          return name;
95      }
96  
97      /**
98       * Setter for name property.
99       *
100      * @param name
101      * The name of the attribute to put.
102      */
103     public void setName(java.lang.String name) {
104         this.name = name;
105     }
106 
107     /**
108      * Getter for value property.
109      *
110      * @return
111      * The value of the attribute. Use this parameter, or
112      * expression, or body.
113      */
114     public java.lang.Object getValue() {
115         return value;
116     }
117 
118     /**
119      * Setter for value property.
120      *
121      * @param value
122      * The value of the attribute. Use this parameter, or
123      * expression, or body.
124      */
125     public void setValue(java.lang.Object value) {
126         this.value = value;
127     }
128 
129     /**
130      * Getter for expression property.
131      *
132      * @return
133      * The expression to calculate the value from. Use this
134      * parameter, or value, or body.
135      */
136     public java.lang.String getExpression() {
137         return expression;
138     }
139 
140     /**
141      * Setter for expression property.
142      *
143      * @param expression
144      * The expression to calculate the value from. Use this
145      * parameter, or value, or body.
146      */
147     public void setExpression(java.lang.String expression) {
148         this.expression = expression;
149     }
150 
151     /**
152      * Getter for role property.
153      *
154      * @return
155      * A comma-separated list of roles. If present, the attribute
156      * will be rendered only if the current user belongs to one of the roles.
157      */
158     public java.lang.String getRole() {
159         return role;
160     }
161 
162     /**
163      * Setter for role property.
164      *
165      * @param role
166      * A comma-separated list of roles. If present, the attribute
167      * will be rendered only if the current user belongs to one of the roles.
168      */
169     public void setRole(java.lang.String role) {
170         this.role = role;
171     }
172 
173     /**
174      * Getter for type property.
175      *
176      * @return
177      * The type (renderer) of the attribute.
178      */
179     public java.lang.String getType() {
180         return type;
181     }
182 
183     /**
184      * Setter for type property.
185      *
186      * @param type
187      * The type (renderer) of the attribute.
188      */
189     public void setType(java.lang.String type) {
190         this.type = type;
191     }
192 
193     /**
194      * Getter for cascade property.
195      *
196      * @return
197      * If <code>true</code> the attribute will be cascaded to all nested attributes.
198      */
199     public boolean isCascade() {
200         return cascade;
201     }
202 
203     /**
204      * Setter for cascade property.
205      *
206      * @param cascade
207      * If <code>true</code> the attribute will be cascaded to all nested attributes.
208      */
209     public void setCascade(boolean cascade) {
210         this.cascade = cascade;
211     }
212 
213     /** {@inheritDoc} */
214     @Override
215     public void doTag() throws JspException, IOException {
216         AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.jsp.autotag.JspAutotagRuntime();
217         if (runtime instanceof SimpleTagSupport) {
218             SimpleTagSupport tag = (SimpleTagSupport) runtime;
219             tag.setJspContext(getJspContext());
220             tag.setJspBody(getJspBody());
221             tag.setParent(getParent());
222             tag.doTag();
223         }
224         org.apache.tiles.request.Request request = runtime.createRequest();        
225         ModelBody modelBody = runtime.createModelBody();
226         model.execute(
227             name,
228             value,
229             expression,
230             role,
231             type,
232             cascade,
233             request, modelBody
234         );
235     }
236 }