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