Coverage Report - org.apache.tiles.freemarker.template.InsertTemplateFMModel
 
Classes in this File Line Coverage Branch Coverage Complexity
InsertTemplateFMModel
30%
3/10
0%
0/2
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>&lt;tiles:insertTemplate&gt;</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>&lt;tiles:putAttribute&gt;</code> or
 29  
  * <code>&lt;tiles:putListAttribute&gt;</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  
  * &lt;code&gt;
 41  
  *           &lt;tiles:insertTemplate template=&quot;/basic/myLayout.jsp&quot; flush=&quot;true&quot;&gt;
 42  
  *              &lt;tiles:putAttribute name=&quot;title&quot; value=&quot;My first page&quot; /&gt;
 43  
  *              &lt;tiles:putAttribute name=&quot;header&quot; value=&quot;/common/header.jsp&quot; /&gt;
 44  
  *              &lt;tiles:putAttribute name=&quot;footer&quot; value=&quot;/common/footer.jsp&quot; /&gt;
 45  
  *              &lt;tiles:putAttribute name=&quot;menu&quot; value=&quot;/basic/menu.jsp&quot; /&gt;
 46  
  *              &lt;tiles:putAttribute name=&quot;body&quot; value=&quot;/basic/helloBody.jsp&quot; /&gt;
 47  
  *           &lt;/tiles:insertTemplate&gt;
 48  
  *         &lt;/code&gt;
 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  
 }