Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
InsertTemplateFMModel |
|
| 1.5;1.5 |
1 | /* | |
2 | * This file was automatically generated by Apache Tiles Autotag. | |
3 | */ | |
4 | package org.apache.tiles.freemarker.template; | |
5 | ||
6 | import java.io.IOException; | |
7 | import java.util.Map; | |
8 | ||
9 | import org.apache.tiles.autotag.core.runtime.ModelBody; | |
10 | import org.apache.tiles.autotag.core.runtime.AutotagRuntime; | |
11 | ||
12 | import freemarker.core.Environment; | |
13 | import freemarker.template.TemplateDirectiveBody; | |
14 | import freemarker.template.TemplateDirectiveModel; | |
15 | import freemarker.template.TemplateException; | |
16 | import freemarker.template.TemplateModel; | |
17 | ||
18 | /** | |
19 | * <p> | |
20 | * <strong>Insert a template.</strong> | |
21 | * </p> | |
22 | * <p> | |
23 | * Insert a template with the possibility to pass parameters (called | |
24 | * attributes). A template can be seen as a procedure that can take parameters | |
25 | * or attributes. <code><tiles:insertTemplate></code> allows to define | |
26 | * these attributes and pass them to the inserted jsp page, called template. | |
27 | * Attributes are defined using nested tag | |
28 | * <code><tiles:putAttribute></code> or | |
29 | * <code><tiles:putListAttribute></code>. | |
30 | * </p> | |
31 | * <p> | |
32 | * You must specify <code>template</code> attribute, for inserting a template | |
33 | * </p> | |
34 | * | |
35 | * <p> | |
36 | * <strong>Example : </strong> | |
37 | * </p> | |
38 | * | |
39 | * <pre> | |
40 | * <code> | |
41 | * <tiles:insertTemplate template="/basic/myLayout.jsp" flush="true"> | |
42 | * <tiles:putAttribute name="title" value="My first page" /> | |
43 | * <tiles:putAttribute name="header" value="/common/header.jsp" /> | |
44 | * <tiles:putAttribute name="footer" value="/common/footer.jsp" /> | |
45 | * <tiles:putAttribute name="menu" value="/basic/menu.jsp" /> | |
46 | * <tiles:putAttribute name="body" value="/basic/helloBody.jsp" /> | |
47 | * </tiles:insertTemplate> | |
48 | * </code> | |
49 | * </pre> | |
50 | */ | |
51 | public class InsertTemplateFMModel implements TemplateDirectiveModel { | |
52 | ||
53 | /** | |
54 | * The template model. | |
55 | */ | |
56 | private org.apache.tiles.template.InsertTemplateModel model; | |
57 | ||
58 | /** | |
59 | * Constructor. | |
60 | * | |
61 | * @param model | |
62 | * The template model. | |
63 | */ | |
64 | 1 | public InsertTemplateFMModel(org.apache.tiles.template.InsertTemplateModel model) { |
65 | 1 | this.model = model; |
66 | 1 | } |
67 | ||
68 | /** {@inheritDoc} */ | |
69 | @SuppressWarnings("unchecked") | |
70 | @Override | |
71 | public void execute(Environment env, @SuppressWarnings("rawtypes") Map params, TemplateModel[] loopVars, | |
72 | TemplateDirectiveBody body) throws TemplateException, IOException { | |
73 | 0 | AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.freemarker.autotag.FreemarkerAutotagRuntime(); |
74 | 0 | if (runtime instanceof TemplateDirectiveModel) { |
75 | 0 | ((TemplateDirectiveModel) runtime).execute(env, params, loopVars, body); |
76 | } | |
77 | 0 | org.apache.tiles.request.Request request = runtime.createRequest(); |
78 | 0 | ModelBody modelBody = runtime.createModelBody(); |
79 | 0 | model.execute( |
80 | runtime.getParameter("template", java.lang.String.class, null), | |
81 | runtime.getParameter("templateType", java.lang.String.class, null), | |
82 | runtime.getParameter("templateExpression", java.lang.String.class, null), | |
83 | runtime.getParameter("role", java.lang.String.class, null), | |
84 | runtime.getParameter("preparer", java.lang.String.class, null), | |
85 | runtime.getParameter("flush", java.lang.Boolean.class, false), | |
86 | request, modelBody | |
87 | ); | |
88 | 0 | } |
89 | } |