1/*2 * This file was automatically generated by Apache Tiles Autotag.3 */4package org.apache.tiles.freemarker.template;
56import java.io.IOException;
7import java.util.Map;
89import org.apache.tiles.autotag.core.runtime.ModelBody;
10import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
1112import freemarker.core.Environment;
13import freemarker.template.TemplateDirectiveBody;
14import freemarker.template.TemplateDirectiveModel;
15import freemarker.template.TemplateException;
16import freemarker.template.TemplateModel;
1718/**19 * <p>20 * <strong>Put an attribute in enclosing attribute container tag.</strong>21 * </p>22 * <p>23 * Enclosing attribute container tag can be :24 * <ul>25 * <li><initContainer></li>26 * <li><definition></li>27 * <li><insertAttribute></li>28 * <li><insertDefinition></li>29 * <li><putListAttribute></li>30 * </ul>31 * (or any other tag which implements the <code>PutAttributeTagParent</code>32 * interface. Exception is thrown if no appropriate tag can be found.33 * </p>34 * <p>35 * Put tag can have following atributes :36 * <ul>37 * <li>name : Name of the attribute</li>38 * <li>value : value to put as attribute</li>39 * <li>type : value type. Possible type are : string (value is used as direct40 * string), template (value is used as a page url to insert), definition (value41 * is used as a definition name to insert), object (value is used as it is)</li>42 * <li>role : Role to check when 'insertAttribute' will be called.</li>43 * </ul>44 * </p>45 * <p>46 * Value can also come from tag body. Tag body is taken into account only if47 * value is not set by one of the tag attributes. In this case Attribute type is48 * "string", unless tag body define another type.49 * </p>50 */51publicclassPutAttributeFMModelimplements TemplateDirectiveModel {
5253/**54 * The template model.55 */56private org.apache.tiles.template.PutAttributeModel model;
5758/**59 * Constructor.60 *61 * @param model62 * The template model.63 */64publicPutAttributeFMModel(org.apache.tiles.template.PutAttributeModel model) {
65this.model = model;
66 }
6768/** {@inheritDoc} */69 @SuppressWarnings("unchecked")
70 @Override
71publicvoid execute(Environment env, @SuppressWarnings("rawtypes") Map params, TemplateModel[] loopVars,
72 TemplateDirectiveBody body) throws TemplateException, IOException {
73 AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.freemarker.autotag.FreemarkerAutotagRuntime();
74if (runtime instanceof TemplateDirectiveModel) {
75 ((TemplateDirectiveModel) runtime).execute(env, params, loopVars, body);
76 }
77 org.apache.tiles.request.Request request = runtime.createRequest();
78 ModelBody modelBody = runtime.createModelBody();
79 model.execute(
80 runtime.getParameter("name", java.lang.String.class, null),
81 runtime.getParameter("value", java.lang.Object.class, null),
82 runtime.getParameter("expression", java.lang.String.class, null),
83 runtime.getParameter("role", java.lang.String.class, null),
84 runtime.getParameter("type", java.lang.String.class, null),
85 runtime.getParameter("cascade", java.lang.Boolean.class, false),
86 request, modelBody
87 );
88 }
89 }