This project has retired. For details please refer to its Attic page.
InsertAttributeFMModel xref
View Javadoc

1   /*
2    * $Id: InsertAttributeFMModel.java 765774 2009-04-16 21:43:00Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.tiles.freemarker.template;
23  
24  import java.io.IOException;
25  import java.util.Map;
26  
27  import org.apache.tiles.Attribute;
28  import org.apache.tiles.TilesContainer;
29  import org.apache.tiles.freemarker.context.FreeMarkerUtil;
30  import org.apache.tiles.template.InsertAttributeModel;
31  
32  import freemarker.core.Environment;
33  import freemarker.template.TemplateDirectiveBody;
34  import freemarker.template.TemplateDirectiveModel;
35  import freemarker.template.TemplateException;
36  import freemarker.template.TemplateModel;
37  
38  /***
39   * Wraps {@link InsertAttributeModel} to be used in FreeMarker. For the list of
40   * parameters, see
41   * {@link InsertAttributeModel
42   * #start(java.util.Stack, TilesContainer, boolean, String, String,
43   * Object, String, String, String, Attribute, Object...)}
44   * and
45   * {@link InsertAttributeModel
46   * #end(java.util.Stack, TilesContainer, boolean, Object...)}
47   * .
48   *
49   * @version $Rev: 765774 $ $Date: 2009-04-16 23:43:00 +0200 (gio, 16 apr 2009) $
50   * @since 2.2.0
51   */
52  public class InsertAttributeFMModel implements TemplateDirectiveModel {
53  
54      /***
55       * The template model.
56       */
57      private InsertAttributeModel model;
58  
59      /***
60       * Constructor.
61       *
62       * @param model The template model.
63       * @since 2.2.0
64       */
65      public InsertAttributeFMModel(InsertAttributeModel model) {
66          this.model = model;
67      }
68  
69      /*** {@inheritDoc} */
70      @SuppressWarnings("unchecked")
71      public void execute(Environment env, Map params, TemplateModel[] loopVars,
72              TemplateDirectiveBody body) throws TemplateException, IOException {
73          Map<String, TemplateModel> parms = (Map<String, TemplateModel>) params;
74          TilesContainer container = FreeMarkerUtil.getCurrentContainer(env);
75          model.start(
76                  FreeMarkerUtil.getComposeStack(env),
77                  container,
78                  FreeMarkerUtil.getAsBoolean(parms.get("ignore"), false),
79                  FreeMarkerUtil.getAsString(parms.get("preparer")),
80                  FreeMarkerUtil.getAsString(parms.get("role")),
81                  FreeMarkerUtil.getAsObject(parms.get("defaultValue")),
82                  FreeMarkerUtil.getAsString(parms
83                          .get("defaultValueRole")), FreeMarkerUtil
84                          .getAsString(parms.get("defaultValueType")),
85                  FreeMarkerUtil.getAsString(parms.get("name")),
86                  (Attribute) FreeMarkerUtil.getAsObject(parms
87                          .get("value")), env);
88          FreeMarkerUtil.evaluateBody(body);
89          model.end(FreeMarkerUtil.getComposeStack(env), container,
90                  FreeMarkerUtil.getAsBoolean(parms.get("ignore"), false), env);
91      }
92  
93  }