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>Insert a definition.</strong>
17   * </p>
18   * <p>
19   * Insert a definition with the possibility to override and specify parameters
20   * (called attributes). A definition can be seen as a (partially or totally)
21   * filled template that can override or complete attribute values.
22   * <code>&lt;tiles:insertDefinition&gt;</code> allows to define these attributes
23   * and pass them to the inserted jsp page, called template. Attributes are
24   * defined using nested tag <code>&lt;tiles:putAttribute&gt;</code> or
25   * <code>&lt;tiles:putListAttribute&gt;</code>.
26   * </p>
27   * <p>
28   * You must specify <code>name</code> tag attribute, for inserting a definition
29   * from definitions factory.
30   * </p>
31   * <p>
32   * <strong>Example : </strong>
33   * </p>
34   * 
35   * <pre>
36   * &lt;code&gt;
37   *           &lt;tiles:insertDefinition name=&quot;.my.tiles.defininition flush=&quot;true&quot;&gt;
38   *              &lt;tiles:putAttribute name=&quot;title&quot; value=&quot;My first page&quot; /&gt;
39   *              &lt;tiles:putAttribute name=&quot;header&quot; value=&quot;/common/header.jsp&quot; /&gt;
40   *              &lt;tiles:putAttribute name=&quot;footer&quot; value=&quot;/common/footer.jsp&quot; /&gt;
41   *              &lt;tiles:putAttribute name=&quot;menu&quot; value=&quot;/basic/menu.jsp&quot; /&gt;
42   *              &lt;tiles:putAttribute name=&quot;body&quot; value=&quot;/basic/helloBody.jsp&quot; /&gt;
43   *           &lt;/tiles:insertDefinition&gt;
44   *         &lt;/code&gt;
45   * </pre>
46   */
47  public class InsertDefinitionTag extends SimpleTagSupport {
48  
49      /**
50       * The template model.
51       */
52      private org.apache.tiles.template.InsertDefinitionModel model = new org.apache.tiles.template.InsertDefinitionModel();
53  
54      /**
55       * The name of the definition to render.
56       */
57      private java.lang.String definitionName;
58  
59      /**
60       * If specified, this template will be used instead of the
61       * one used by the definition.
62       */
63      private java.lang.String template;
64  
65      /**
66       * The type of the template attribute.
67       */
68      private java.lang.String templateType;
69  
70      /**
71       * The expression to evaluate to get the value of the template.
72       */
73      private java.lang.String templateExpression;
74  
75      /**
76       * A comma-separated list of roles. If present, the definition
77       * will be rendered only if the current user belongs to one of the roles.
78       */
79      private java.lang.String role;
80  
81      /**
82       * The preparer to use to invoke before the definition is
83       * rendered. If specified, it overrides the preparer specified in the
84       * definition itself.
85       */
86      private java.lang.String preparer;
87  
88      /**
89       * If <code>true</code>, the response will be flushed after the insert.
90       */
91      private boolean flush;
92  
93      /**
94       * Getter for name property.
95       *
96       * @return
97       * The name of the definition to render.
98       */
99      public java.lang.String getName() {
100         return definitionName;
101     }
102 
103     /**
104      * Setter for name property.
105      *
106      * @param definitionName
107      * The name of the definition to render.
108      */
109     public void setName(java.lang.String definitionName) {
110         this.definitionName = definitionName;
111     }
112 
113     /**
114      * Getter for template property.
115      *
116      * @return
117      * If specified, this template will be used instead of the
118      * one used by the definition.
119      */
120     public java.lang.String getTemplate() {
121         return template;
122     }
123 
124     /**
125      * Setter for template property.
126      *
127      * @param template
128      * If specified, this template will be used instead of the
129      * one used by the definition.
130      */
131     public void setTemplate(java.lang.String template) {
132         this.template = template;
133     }
134 
135     /**
136      * Getter for templateType property.
137      *
138      * @return
139      * The type of the template attribute.
140      */
141     public java.lang.String getTemplateType() {
142         return templateType;
143     }
144 
145     /**
146      * Setter for templateType property.
147      *
148      * @param templateType
149      * The type of the template attribute.
150      */
151     public void setTemplateType(java.lang.String templateType) {
152         this.templateType = templateType;
153     }
154 
155     /**
156      * Getter for templateExpression property.
157      *
158      * @return
159      * The expression to evaluate to get the value of the template.
160      */
161     public java.lang.String getTemplateExpression() {
162         return templateExpression;
163     }
164 
165     /**
166      * Setter for templateExpression property.
167      *
168      * @param templateExpression
169      * The expression to evaluate to get the value of the template.
170      */
171     public void setTemplateExpression(java.lang.String templateExpression) {
172         this.templateExpression = templateExpression;
173     }
174 
175     /**
176      * Getter for role property.
177      *
178      * @return
179      * A comma-separated list of roles. If present, the definition
180      * will be rendered only if the current user belongs to one of the roles.
181      */
182     public java.lang.String getRole() {
183         return role;
184     }
185 
186     /**
187      * Setter for role property.
188      *
189      * @param role
190      * A comma-separated list of roles. If present, the definition
191      * will be rendered only if the current user belongs to one of the roles.
192      */
193     public void setRole(java.lang.String role) {
194         this.role = role;
195     }
196 
197     /**
198      * Getter for preparer property.
199      *
200      * @return
201      * The preparer to use to invoke before the definition is
202      * rendered. If specified, it overrides the preparer specified in the
203      * definition itself.
204      */
205     public java.lang.String getPreparer() {
206         return preparer;
207     }
208 
209     /**
210      * Setter for preparer property.
211      *
212      * @param preparer
213      * The preparer to use to invoke before the definition is
214      * rendered. If specified, it overrides the preparer specified in the
215      * definition itself.
216      */
217     public void setPreparer(java.lang.String preparer) {
218         this.preparer = preparer;
219     }
220 
221     /**
222      * Getter for flush property.
223      *
224      * @return
225      * If <code>true</code>, the response will be flushed after the insert.
226      */
227     public boolean isFlush() {
228         return flush;
229     }
230 
231     /**
232      * Setter for flush property.
233      *
234      * @param flush
235      * If <code>true</code>, the response will be flushed after the insert.
236      */
237     public void setFlush(boolean flush) {
238         this.flush = flush;
239     }
240 
241     /** {@inheritDoc} */
242     @Override
243     public void doTag() throws JspException, IOException {
244         AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.jsp.autotag.JspAutotagRuntime();
245         if (runtime instanceof SimpleTagSupport) {
246             SimpleTagSupport tag = (SimpleTagSupport) runtime;
247             tag.setJspContext(getJspContext());
248             tag.setJspBody(getJspBody());
249             tag.setParent(getParent());
250             tag.doTag();
251         }
252         org.apache.tiles.request.Request request = runtime.createRequest();        
253         ModelBody modelBody = runtime.createModelBody();
254         model.execute(
255             definitionName,
256             template,
257             templateType,
258             templateExpression,
259             role,
260             preparer,
261             flush,
262             request, modelBody
263         );
264     }
265 }