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.template;
23
24 import org.apache.tiles.Attribute;
25 import org.apache.tiles.AttributeContext;
26 import org.apache.tiles.TilesContainer;
27
28 /***
29 * <p>
30 * <strong>Insert a definition.</strong>
31 * </p>
32 * <p>
33 * Insert a definition with the possibility to override and specify parameters
34 * (called attributes). A definition can be seen as a (partially or totally)
35 * filled template that can override or complete attribute values.
36 * <code><tiles:insertDefinition></code> allows to define these attributes
37 * and pass them to the inserted jsp page, called template. Attributes are
38 * defined using nested tag <code><tiles:putAttribute></code> or
39 * <code><tiles:putListAttribute></code>.
40 * </p>
41 * <p>
42 * You must specify <code>name</code> tag attribute, for inserting a definition
43 * from definitions factory.
44 * </p>
45 * <p>
46 * <strong>Example : </strong>
47 * </p>
48 *
49 * <pre>
50 * <code>
51 * <tiles:insertDefinition name=".my.tiles.defininition flush="true">
52 * <tiles:putAttribute name="title" value="My first page" />
53 * <tiles:putAttribute name="header" value="/common/header.jsp" />
54 * <tiles:putAttribute name="footer" value="/common/footer.jsp" />
55 * <tiles:putAttribute name="menu" value="/basic/menu.jsp" />
56 * <tiles:putAttribute name="body" value="/basic/helloBody.jsp" />
57 * </tiles:insertDefinition>
58 * </code>
59 * </pre>
60 *
61 * @version $Rev: 880940 $ $Date: 2009-11-16 21:11:22 +0100 (lun, 16 nov 2009) $
62 * @since 2.2.0
63 */
64 public class InsertDefinitionModel {
65
66 /***
67 * Starts the operation.
68 *
69 * @param container The Tiles container.
70 * @param requestItems The request objects.
71 * @since 2.2.0
72 */
73 public void start(TilesContainer container, Object... requestItems) {
74 container.startContext(requestItems);
75 }
76
77 /***
78 * Ends the operation.
79 *
80 * @param container The Tiles container.
81 * @param definitionName The name of the definition to render.
82 * @param template If specified, this template will be used instead of the
83 * one used by the definition.
84 * @param templateType The type of the template attribute.
85 * @param templateExpression The expression to evaluate to get the value of the template.
86 * @param role A comma-separated list of roles. If present, the definition
87 * will be rendered only if the current user belongs to one of the roles.
88 * @param preparer The preparer to use to invoke before the definition is
89 * rendered. If specified, it overrides the preparer specified in the
90 * definition itself.
91 * @param requestItems The request objects.
92 * @since 2.2.0
93 */
94 public void end(TilesContainer container, String definitionName,
95 String template, String templateType, String templateExpression,
96 String role, String preparer, Object... requestItems) {
97 try {
98 AttributeContext attributeContext = container
99 .getAttributeContext(requestItems);
100 Attribute templateAttribute = Attribute.createTemplateAttribute(template,
101 templateExpression, templateType, role);
102 attributeContext.setPreparer(preparer);
103 attributeContext.setTemplateAttribute(templateAttribute);
104 container.render(definitionName, requestItems);
105 } finally {
106 container.endContext(requestItems);
107 }
108 }
109
110 /***
111 * Executes the operation.
112 *
113 * @param container The Tiles container.
114 * @param definitionName The name of the definition to render.
115 * @param template If specified, this template will be used instead of the
116 * one used by the definition.
117 * @param templateType The type of the template attribute.
118 * @param templateExpression The expression to evaluate to get the value of the template.
119 * @param role A comma-separated list of roles. If present, the definition
120 * will be rendered only if the current user belongs to one of the roles.
121 * @param preparer The preparer to use to invoke before the definition is
122 * rendered. If specified, it overrides the preparer specified in the
123 * definition itself.
124 * @param requestItems The request objects.
125 * @since 2.2.0
126 */
127 public void execute(TilesContainer container, String definitionName,
128 String template, String templateType, String templateExpression,
129 String role, String preparer, Object... requestItems) {
130 start(container, requestItems);
131 end(container, definitionName, template, templateType, templateExpression, role, preparer, requestItems);
132 }
133 }