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

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