View Javadoc

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>&lt;tiles:insertTemplate&gt;</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>&lt;tiles:putAttribute&gt;</code> or
26   * <code>&lt;tiles:putListAttribute&gt;</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   * &lt;code&gt;
38   *           &lt;tiles:insertTemplate template=&quot;/basic/myLayout.jsp&quot; flush=&quot;true&quot;&gt;
39   *              &lt;tiles:putAttribute name=&quot;title&quot; value=&quot;My first page&quot; /&gt;
40   *              &lt;tiles:putAttribute name=&quot;header&quot; value=&quot;/common/header.jsp&quot; /&gt;
41   *              &lt;tiles:putAttribute name=&quot;footer&quot; value=&quot;/common/footer.jsp&quot; /&gt;
42   *              &lt;tiles:putAttribute name=&quot;menu&quot; value=&quot;/basic/menu.jsp&quot; /&gt;
43   *              &lt;tiles:putAttribute name=&quot;body&quot; value=&quot;/basic/helloBody.jsp&quot; /&gt;
44   *           &lt;/tiles:insertTemplate&gt;
45   *         &lt;/code&gt;
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  }