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

1   /*
2    * $Id: InsertAttributeDirective.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.InsertAttributeModel;
36  import org.apache.tiles.velocity.context.VelocityUtil;
37  import org.apache.velocity.context.InternalContextAdapter;
38  
39  /***
40   * Wraps {@link InsertAttributeModel} to be used in Velocity. For the list of
41   * parameters, see
42   * {@link InsertAttributeModel#start(java.util.Stack, org.apache.tiles.TilesContainer, boolean,
43   * String, String, Object, String, String, String, Attribute, Object...)}
44   * , {@link InsertAttributeModel#end(java.util.Stack, org.apache.tiles.TilesContainer, boolean, Object...)} and
45   * {@link InsertAttributeModel#execute(org.apache.tiles.TilesContainer, boolean, String, String,
46   * 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 InsertAttributeDirective extends BlockDirective {
52  
53      /***
54       * The template model.
55       */
56      private InsertAttributeModel model = new InsertAttributeModel(
57              new DefaultAttributeResolver());
58  
59      /***
60       * Default constructor.
61       *
62       * @since 2.2.2
63       */
64      public InsertAttributeDirective() {
65          // Does nothing.
66      }
67  
68      /***
69       * Constructor.
70       *
71       * @param model The used model.
72       * @since 2.2.2
73       */
74      public InsertAttributeDirective(InsertAttributeModel model) {
75          this.model = model;
76      }
77  
78      /*** {@inheritDoc} */
79      @Override
80      public String getName() {
81          return "tiles_insertAttribute";
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.getCurrentContainer(request,
91                  servletContext), VelocityUtil.toSimpleBoolean((Boolean) params
92                          .get("ignore"), false), context, request, response,
93                  writer);
94      }
95  
96      /*** {@inheritDoc} */
97      @Override
98      protected void start(InternalContextAdapter context,
99              Writer writer, Map<String, Object> params,
100             HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) {
101         model.start(ServletUtil.getComposeStack(request), ServletUtil.getCurrentContainer(request,
102                 servletContext), VelocityUtil.toSimpleBoolean((Boolean) params
103                         .get("ignore"), false), (String) params
104                 .get("preparer"), (String) params.get("role"), params
105                 .get("defaultValue"), (String) params.get("defaultValueRole"),
106                 (String) params.get("defaultValueType"), (String) params
107                         .get("name"), (Attribute) params.get("value"), context,
108                 request, response, writer);
109     }
110 
111 }