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 template.</strong>
17   * </p>
18   * <p>
19   * Insert a template with the possibility to pass parameters (called
20   * attributes). A template can be seen as a procedure that can take parameters
21   * or attributes. <code>&lt;tiles:insertTemplate&gt;</code> allows to define
22   * these attributes and pass them to the inserted jsp page, called template.
23   * Attributes are defined using nested tag
24   * <code>&lt;tiles:putAttribute&gt;</code> or
25   * <code>&lt;tiles:putListAttribute&gt;</code>.
26   * </p>
27   * <p>
28   * You must specify <code>template</code> attribute, for inserting a template
29   * </p>
30   * 
31   * <p>
32   * <strong>Example : </strong>
33   * </p>
34   * 
35   * <pre>
36   * &lt;code&gt;
37   *           &lt;tiles:insertTemplate template=&quot;/basic/myLayout.jsp&quot; 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:insertTemplate&gt;
44   *         &lt;/code&gt;
45   * </pre>
46   */
47  public class InsertTemplateTag extends SimpleTagSupport {
48  
49      /**
50       * The template model.
51       */
52      private org.apache.tiles.template.InsertTemplateModel model = new org.apache.tiles.template.InsertTemplateModel();
53  
54      /**
55       * The template to render.
56       */
57      private java.lang.String template;
58  
59      /**
60       * The type of the template attribute.
61       */
62      private java.lang.String templateType;
63  
64      /**
65       * The expression to evaluate to get the value of the template.
66       */
67      private java.lang.String templateExpression;
68  
69      /**
70       * A comma-separated list of roles. If present, the template
71       * will be rendered only if the current user belongs to one of the roles.
72       */
73      private java.lang.String role;
74  
75      /**
76       * The preparer to use to invoke before the definition is
77       * rendered. If specified, it overrides the preparer specified in the
78       * definition itself.
79       */
80      private java.lang.String preparer;
81  
82      /**
83       * If <code>true</code>, the response will be flushed after the insert.
84       */
85      private boolean flush;
86  
87      /**
88       * Getter for template property.
89       *
90       * @return
91       * The template to render.
92       */
93      public java.lang.String getTemplate() {
94          return template;
95      }
96  
97      /**
98       * Setter for template property.
99       *
100      * @param template
101      * The template to render.
102      */
103     public void setTemplate(java.lang.String template) {
104         this.template = template;
105     }
106 
107     /**
108      * Getter for templateType property.
109      *
110      * @return
111      * The type of the template attribute.
112      */
113     public java.lang.String getTemplateType() {
114         return templateType;
115     }
116 
117     /**
118      * Setter for templateType property.
119      *
120      * @param templateType
121      * The type of the template attribute.
122      */
123     public void setTemplateType(java.lang.String templateType) {
124         this.templateType = templateType;
125     }
126 
127     /**
128      * Getter for templateExpression property.
129      *
130      * @return
131      * The expression to evaluate to get the value of the template.
132      */
133     public java.lang.String getTemplateExpression() {
134         return templateExpression;
135     }
136 
137     /**
138      * Setter for templateExpression property.
139      *
140      * @param templateExpression
141      * The expression to evaluate to get the value of the template.
142      */
143     public void setTemplateExpression(java.lang.String templateExpression) {
144         this.templateExpression = templateExpression;
145     }
146 
147     /**
148      * Getter for role property.
149      *
150      * @return
151      * A comma-separated list of roles. If present, the template
152      * will be rendered only if the current user belongs to one of the roles.
153      */
154     public java.lang.String getRole() {
155         return role;
156     }
157 
158     /**
159      * Setter for role property.
160      *
161      * @param role
162      * A comma-separated list of roles. If present, the template
163      * will be rendered only if the current user belongs to one of the roles.
164      */
165     public void setRole(java.lang.String role) {
166         this.role = role;
167     }
168 
169     /**
170      * Getter for preparer property.
171      *
172      * @return
173      * The preparer to use to invoke before the definition is
174      * rendered. If specified, it overrides the preparer specified in the
175      * definition itself.
176      */
177     public java.lang.String getPreparer() {
178         return preparer;
179     }
180 
181     /**
182      * Setter for preparer property.
183      *
184      * @param preparer
185      * The preparer to use to invoke before the definition is
186      * rendered. If specified, it overrides the preparer specified in the
187      * definition itself.
188      */
189     public void setPreparer(java.lang.String preparer) {
190         this.preparer = preparer;
191     }
192 
193     /**
194      * Getter for flush property.
195      *
196      * @return
197      * If <code>true</code>, the response will be flushed after the insert.
198      */
199     public boolean isFlush() {
200         return flush;
201     }
202 
203     /**
204      * Setter for flush property.
205      *
206      * @param flush
207      * If <code>true</code>, the response will be flushed after the insert.
208      */
209     public void setFlush(boolean flush) {
210         this.flush = flush;
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             template,
228             templateType,
229             templateExpression,
230             role,
231             preparer,
232             flush,
233             request, modelBody
234         );
235     }
236 }