View Javadoc

1   package org.apache.turbine.modules.pages;
2   
3   
4   /*
5    * Licensed to the Apache Software Foundation (ASF) under one
6    * or more contributor license agreements.  See the NOTICE file
7    * distributed with this work for additional information
8    * regarding copyright ownership.  The ASF licenses this file
9    * to you under the Apache License, Version 2.0 (the
10   * "License"); you may not use this file except in compliance
11   * with the License.  You may obtain a copy of the License at
12   *
13   *   http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing,
16   * software distributed under the License is distributed on an
17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   * KIND, either express or implied.  See the License for the
19   * specific language governing permissions and limitations
20   * under the License.
21   */
22  
23  
24  import org.apache.turbine.pipeline.PipelineData;
25  import org.apache.turbine.services.velocity.TurbineVelocity;
26  import org.apache.turbine.services.velocity.VelocityService;
27  import org.apache.turbine.util.RunData;
28  import org.apache.velocity.context.Context;
29  
30  /**
31   * Extends TemplatePage to set the template Context.
32   *
33   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
34   * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
35   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
36   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
37   * @version $Id: VelocityPage.java 1078552 2011-03-06 19:58:46Z tv $
38   */
39  public class VelocityPage
40      extends TemplatePage
41  {
42      /**
43       * Stuffs the Context into the RunData so that it is available to
44       * the Action module and the Screen module via getContext().
45       * @deprecated Use PipelineData version instead.
46       * @param data Turbine information.
47       * @exception Exception, a generic exception.
48       */
49      @Deprecated
50      @Override
51      protected void doBuildBeforeAction(RunData data)
52          throws Exception
53      {
54          Context context = TurbineVelocity.getContext(data);
55          data.getTemplateInfo()
56              .setTemplateContext(VelocityService.CONTEXT, context);
57      }
58  
59      /**
60       * Allows the VelocityService to peform post-request actions.
61       * (releases the (non-global) tools in the context for reuse later)
62       * @deprecated. Use PipelineData version instead.
63       *
64       */
65      @Override
66      protected void doPostBuild(RunData data)
67          throws Exception
68      {
69          Context context = TurbineVelocity.getContext(data);
70          TurbineVelocity.requestFinished(context);
71      }
72  
73  
74      /**
75       * Stuffs the Context into the RunData so that it is available to
76       * the Action module and the Screen module via getContext().
77       *
78       * @param data Turbine information.
79       * @exception Exception, a generic exception.
80       */
81      @Override
82      protected void doBuildBeforeAction(PipelineData pipelineData)
83          throws Exception
84      {
85          RunData data = getRunData(pipelineData);
86          Context context = TurbineVelocity.getContext(pipelineData);
87          data.getTemplateInfo()
88              .setTemplateContext(VelocityService.CONTEXT, context);
89      }
90  
91      /**
92       * Allows the VelocityService to peform post-request actions.
93       * (releases the (non-global) tools in the context for reuse later)
94       */
95      @Override
96      protected void doPostBuild(PipelineData pipelineData)
97          throws Exception
98      {
99          Context context = TurbineVelocity.getContext(pipelineData);
100         TurbineVelocity.requestFinished(context);
101     }
102 
103 }