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

1   /*
2    * $Id: GetAsStringFMModel.java 765386 2009-04-15 21:56:54Z 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.GetAsStringModel;
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 GetAsStringModel} to be used in FreeMarker. For the list of
40   * parameters, see
41   * {@link GetAsStringModel
42   * #start(java.util.Stack, TilesContainer, boolean, String, String, Object, String, String, String,
43   * Attribute, Object...)}
44   * and
45   * {@link GetAsStringModel#end(java.util.Stack, TilesContainer, java.io.Writer, boolean, Object...)}
46   * .
47   *
48   * @version $Rev: 765386 $ $Date: 2009-04-15 23:56:54 +0200 (mer, 15 apr 2009) $
49   * @since 2.2.0
50   */
51  public class GetAsStringFMModel implements TemplateDirectiveModel {
52  
53      /***
54       * The template model.
55       */
56      private GetAsStringModel model;
57  
58      /***
59       * Constructor.
60       *
61       * @param model The template model.
62       * @since 2.2.0
63       */
64      public GetAsStringFMModel(GetAsStringModel model) {
65          this.model = model;
66      }
67  
68      /*** {@inheritDoc} */
69      @SuppressWarnings("unchecked")
70      public void execute(Environment env, Map params, TemplateModel[] loopVars,
71              TemplateDirectiveBody body) throws TemplateException, IOException {
72          Map<String, TemplateModel> parms = (Map<String, TemplateModel>) params;
73          TilesContainer container = FreeMarkerUtil.getCurrentContainer(env);
74          model.start(
75                  FreeMarkerUtil.getComposeStack(env),
76                  container,
77                  FreeMarkerUtil.getAsBoolean(parms.get("ignore"), false),
78                  FreeMarkerUtil.getAsString(parms.get("preparer")),
79                  FreeMarkerUtil.getAsString(parms.get("role")),
80                  FreeMarkerUtil.getAsObject(parms.get("defaultValue")),
81                  FreeMarkerUtil.getAsString(parms
82                          .get("defaultValueRole")), FreeMarkerUtil
83                          .getAsString(parms.get("defaultValueType")),
84                  FreeMarkerUtil.getAsString(parms.get("name")),
85                  (Attribute) FreeMarkerUtil.getAsObject(parms
86                          .get("value")), env);
87          FreeMarkerUtil.evaluateBody(body);
88          model.end(FreeMarkerUtil.getComposeStack(env), container, env.getOut(),
89                  FreeMarkerUtil.getAsBoolean(parms.get("ignore"), false), env);
90      }
91  
92  }