1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.tiles.renderer.impl;
22
23 import java.io.IOException;
24
25 import org.apache.tiles.Attribute;
26 import org.apache.tiles.context.TilesRequestContext;
27 import org.apache.tiles.impl.InvalidTemplateException;
28
29 /***
30 * Renders an attribute that contains a reference to a template.
31 *
32 * @version $Rev: 821299 $ $Date: 2009-10-03 14:15:05 +0200 (sab, 03 ott 2009) $
33 * @since 2.1.0
34 */
35 public class TemplateAttributeRenderer extends AbstractTypeDetectingAttributeRenderer {
36
37 /*** {@inheritDoc} */
38 @Override
39 public void write(Object value, Attribute attribute,
40 TilesRequestContext request)
41 throws IOException {
42 if (value != null) {
43 if (value instanceof String) {
44 request.dispatch(value.toString());
45 } else {
46 throw new InvalidTemplateException(
47 "Cannot render a template that is not a string: "
48 + value.toString());
49 }
50 } else {
51 throw new InvalidTemplateException("Cannot render a null template");
52 }
53 }
54
55 /*** {@inheritDoc} */
56 public boolean isRenderable(Object value, Attribute attribute,
57 TilesRequestContext request) {
58 if (value instanceof String) {
59 return ((String) value).startsWith("/");
60 }
61 return false;
62 }
63 }