1 /*
2 * This file was automatically generated by Apache Tiles Autotag.
3 */
4 package org.apache.tiles.velocity.template;
5
6 import java.io.IOException;
7 import java.io.Writer;
8
9 import org.apache.tiles.autotag.core.runtime.ModelBody;
10 import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
11 import org.apache.velocity.context.InternalContextAdapter;
12 import org.apache.velocity.runtime.directive.Directive;
13 import org.apache.velocity.runtime.parser.node.Node;
14
15 /**
16 * <p>
17 * <strong>Insert a template.</strong>
18 * </p>
19 * <p>
20 * Insert a template with the possibility to pass parameters (called
21 * attributes). A template can be seen as a procedure that can take parameters
22 * or attributes. <code><tiles:insertTemplate></code> allows to define
23 * these attributes and pass them to the inserted jsp page, called template.
24 * Attributes are defined using nested tag
25 * <code><tiles:putAttribute></code> or
26 * <code><tiles:putListAttribute></code>.
27 * </p>
28 * <p>
29 * You must specify <code>template</code> attribute, for inserting a template
30 * </p>
31 *
32 * <p>
33 * <strong>Example : </strong>
34 * </p>
35 *
36 * <pre>
37 * <code>
38 * <tiles:insertTemplate template="/basic/myLayout.jsp" flush="true">
39 * <tiles:putAttribute name="title" value="My first page" />
40 * <tiles:putAttribute name="header" value="/common/header.jsp" />
41 * <tiles:putAttribute name="footer" value="/common/footer.jsp" />
42 * <tiles:putAttribute name="menu" value="/basic/menu.jsp" />
43 * <tiles:putAttribute name="body" value="/basic/helloBody.jsp" />
44 * </tiles:insertTemplate>
45 * </code>
46 * </pre>
47 */
48 public class InsertTemplateDirective extends Directive {
49
50 /**
51 * The template model.
52 */
53 private org.apache.tiles.template.InsertTemplateModel model = new org.apache.tiles.template.InsertTemplateModel();
54
55 /** {@inheritDoc} */
56 @Override
57 public String getName() {
58 return "tiles_insertTemplate";
59 }
60
61 /** {@inheritDoc} */
62 @Override
63 public int getType() {
64 return BLOCK;
65 }
66
67 /** {@inheritDoc} */
68 @Override
69 public boolean render(InternalContextAdapter context, Writer writer, Node node)
70 throws IOException {
71 AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
72 if (runtime instanceof Directive) {
73 ((Directive) runtime).render(context, writer, node);
74 }
75 org.apache.tiles.request.Request request = runtime.createRequest();
76 ModelBody modelBody = runtime.createModelBody();
77 model.execute(
78 runtime.getParameter("template", java.lang.String.class, null),
79 runtime.getParameter("templateType", java.lang.String.class, null),
80 runtime.getParameter("templateExpression", java.lang.String.class, null),
81 runtime.getParameter("role", java.lang.String.class, null),
82 runtime.getParameter("preparer", java.lang.String.class, null),
83 runtime.getParameter("flush", java.lang.Boolean.class, false),
84 request, modelBody
85 );
86 return true;
87 }
88 }