1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.tiles.jsp.taglib;
23
24 import java.io.IOException;
25
26 import javax.servlet.jsp.JspContext;
27 import javax.servlet.jsp.JspException;
28 import javax.servlet.jsp.tagext.SimpleTagSupport;
29
30 import org.apache.tiles.jsp.context.JspUtil;
31 import org.apache.tiles.template.InsertTemplateModel;
32
33 /***
34 * This is the tag handler for <tiles:insertTemplate>, which includes a
35 * template ready to be filled.
36 *
37 * @version $Rev: 929598 $ $Date: 2010-03-31 17:53:02 +0200 (mer, 31 mar 2010) $
38 */
39 public class InsertTemplateTag extends SimpleTagSupport {
40
41 /***
42 * The template model.
43 */
44 private InsertTemplateModel model = new InsertTemplateModel();
45
46 /***
47 * The role to check. If the user is in the specified role, the tag is taken
48 * into account; otherwise, the tag is ignored (skipped).
49 *
50 * @since 2.1.1
51 */
52 private String role;
53
54 /***
55 * The view preparer to use before the rendering.
56 *
57 * @since 2.1.1
58 */
59 private String preparer;
60
61 /***
62 * This flag, if <code>true</code>, flushes the content after rendering.
63 *
64 * @since 2.1.1
65 */
66 private boolean flush;
67
68 /***
69 * This flag, if <code>true</code>, ignores exception thrown by preparers
70 * and those caused by problems with definitions.
71 *
72 * @since 2.1.1
73 */
74 private boolean ignore;
75
76 /***
77 * A string representing the URI of a template (for example, a JSP page).
78 *
79 * @since 2.1.0
80 */
81 private String template;
82
83 /***
84 * The type of the template attribute.
85 *
86 * @since 2.2.0
87 */
88 private String templateType;
89
90 /***
91 * The expression to evaluate to get the value of the template.
92 *
93 * @since 2.2.0
94 */
95 private String templateExpression;
96
97 /***
98 * Returns the role to check. If the user is in the specified role, the tag is
99 * taken into account; otherwise, the tag is ignored (skipped).
100 *
101 * @return The role to check.
102 * @since 2.1.1
103 */
104 public String getRole() {
105 return role;
106 }
107
108 /***
109 * Sets the role to check. If the user is in the specified role, the tag is
110 * taken into account; otherwise, the tag is ignored (skipped).
111 *
112 * @param role The role to check.
113 * @since 2.1.1
114 */
115 public void setRole(String role) {
116 this.role = role;
117 }
118
119 /***
120 * Returns the preparer name.
121 *
122 * @return The preparer name.
123 * @since 2.1.1
124 */
125 public String getPreparer() {
126 return preparer;
127 }
128
129 /***
130 * Sets the preparer name.
131 *
132 * @param preparer The preparer name.
133 * @since 2.1.1
134 */
135 public void setPreparer(String preparer) {
136 this.preparer = preparer;
137 }
138
139 /***
140 * Returns the flush flag. If <code>true</code>, current page out stream
141 * is flushed after insertion.
142 *
143 * @return The flush flag.
144 * @since 2.1.1
145 */
146 public boolean isFlush() {
147 return flush;
148 }
149
150 /***
151 * Sets the flush flag. If <code>true</code>, current page out stream
152 * is flushed after insertion.
153 *
154 * @param flush The flush flag.
155 * @since 2.1.1
156 */
157 public void setFlush(boolean flush) {
158 this.flush = flush;
159 }
160
161 /***
162 * Returns the ignore flag. If it is set to true, and the attribute
163 * specified by the name does not exist, simply return without writing
164 * anything. The default value is false, which will cause a runtime
165 * exception to be thrown.
166 *
167 * @return The ignore flag.
168 * @since 2.1.1
169 */
170 public boolean isIgnore() {
171 return ignore;
172 }
173
174 /***
175 * Sets the ignore flag. If this attribute is set to true, and the attribute
176 * specified by the name does not exist, simply return without writing
177 * anything. The default value is false, which will cause a runtime
178 * exception to be thrown.
179 *
180 * @param ignore The ignore flag.
181 * @since 2.1.1
182 */
183 public void setIgnore(boolean ignore) {
184 this.ignore = ignore;
185 }
186
187 /***
188 * Returns a string representing the URI of a template (for example, a JSP
189 * page).
190 *
191 * @return The template URI.
192 * @since 2.1.0
193 */
194 public String getTemplate() {
195 return template;
196 }
197
198 /***
199 * Sets a string representing the URI of a template (for example, a JSP
200 * page).
201 *
202 * @param template The template URI.
203 * @since 2.1.0
204 */
205 public void setTemplate(String template) {
206 this.template = template;
207 }
208
209 /***
210 * Returns the type of the template attribute.
211 *
212 * @return The template type.
213 * @since 2.2.0
214 */
215 public String getTemplateType() {
216 return templateType;
217 }
218
219 /***
220 * Sets the type of the template attribute.
221 *
222 * @param templateType The template type.
223 * @since 2.2.0
224 */
225 public void setTemplateType(String templateType) {
226 this.templateType = templateType;
227 }
228
229 /***
230 * Returns the expression to evaluate to get the value of the template.
231 *
232 * @return The template expression.
233 * @since 2.2.0
234 */
235 public String getTemplateExpression() {
236 return templateExpression;
237 }
238
239 /***
240 * Sets the expression to evaluate to get the value of the template.
241 *
242 * @param templateExpression The template expression.
243 * @since 2.2.0
244 */
245 public void setTemplateExpression(String templateExpression) {
246 this.templateExpression = templateExpression;
247 }
248
249 /*** {@inheritDoc} */
250 @Override
251 public void doTag() throws JspException, IOException {
252 JspContext jspContext = getJspContext();
253 model.start(JspUtil.getCurrentContainer(jspContext), jspContext);
254 JspUtil.evaluateFragment(getJspBody());
255 model.end(JspUtil.getCurrentContainer(jspContext), template,
256 templateType, templateExpression, role, preparer, jspContext);
257 if(isFlush()){
258 jspContext.getOut().flush();
259 }
260 }
261 }