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

1   /*
2    * $Id: GetAsStringDirective.java 902403 2010-01-23 13:31:17Z 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.velocity.template;
23  
24  import java.io.IOException;
25  import java.io.Writer;
26  import java.util.Map;
27  
28  import javax.servlet.ServletContext;
29  import javax.servlet.http.HttpServletRequest;
30  import javax.servlet.http.HttpServletResponse;
31  
32  import org.apache.tiles.Attribute;
33  import org.apache.tiles.servlet.context.ServletUtil;
34  import org.apache.tiles.template.DefaultAttributeResolver;
35  import org.apache.tiles.template.GetAsStringModel;
36  import org.apache.tiles.velocity.context.VelocityUtil;
37  import org.apache.velocity.context.InternalContextAdapter;
38  
39  /***
40   * Wraps {@link GetAsStringModel} to be used in Velocity. For the list of
41   * parameters, see
42   * {@link GetAsStringModel#start(java.util.Stack, org.apache.tiles.TilesContainer, boolean,
43   * String, String, Object, String, String, String, Attribute, Object...)}
44   * , {@link GetAsStringModel#end(java.util.Stack, org.apache.tiles.TilesContainer, Writer, boolean, Object...)} and
45   * {@link GetAsStringModel#execute(TilesContainer, Writer, boolean, String,
46   * String, Object, String, String, String, Attribute, Object...)}.
47   *
48   * @version $Rev: 902403 $ $Date: 2010-01-23 14:31:17 +0100 (sab, 23 gen 2010) $
49   * @since 2.2.2
50   */
51  public class GetAsStringDirective extends BlockDirective {
52  
53      /***
54       * The template model.
55       */
56      private GetAsStringModel model = new GetAsStringModel(
57              new DefaultAttributeResolver());
58  
59      /***
60       * Default constructor.
61       *
62       * @since 2.2.2
63       */
64      public GetAsStringDirective() {
65          // Does nothing.
66      }
67  
68      /***
69       * Constructor.
70       *
71       * @param model The used model.
72       * @since 2.2.2
73       */
74      public GetAsStringDirective(GetAsStringModel model) {
75          this.model = model;
76      }
77  
78      /*** {@inheritDoc} */
79      @Override
80      public String getName() {
81          return "tiles_getAsString";
82      }
83  
84      /*** {@inheritDoc} */
85      @Override
86      protected void end(InternalContextAdapter context, Writer writer,
87              Map<String, Object> params, HttpServletRequest request,
88              HttpServletResponse response, ServletContext servletContext)
89              throws IOException {
90          model.end(ServletUtil.getComposeStack(request), ServletUtil
91                  .getCurrentContainer(request, servletContext), writer,
92                  VelocityUtil.toSimpleBoolean((Boolean) params.get("ignore"),
93                          false), context, request, response, writer);
94      }
95  
96      /*** {@inheritDoc} */
97      @Override
98      protected void start(InternalContextAdapter context, Writer writer,
99              Map<String, Object> params, HttpServletRequest request,
100             HttpServletResponse response, ServletContext servletContext) {
101         model.start(ServletUtil.getComposeStack(request), ServletUtil
102                 .getCurrentContainer(request, servletContext), VelocityUtil
103                 .toSimpleBoolean((Boolean) params.get("ignore"), false),
104                 (String) params.get("preparer"), (String) params.get("role"),
105                 params.get("defaultValue"), (String) params
106                         .get("defaultValueRole"), (String) params
107                         .get("defaultValueType"), (String) params.get("name"),
108                 (Attribute) params.get("value"), context, request, response,
109                 writer);
110     }
111 
112 }