View Javadoc

1   package org.apache.turbine.modules.actions;
2   
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  import org.apache.turbine.modules.screens.TemplateScreen;
23  import org.apache.turbine.services.velocity.TurbineVelocity;
24  import org.apache.turbine.util.RunData;
25  import org.apache.turbine.util.velocity.VelocityActionEvent;
26  import org.apache.velocity.context.Context;
27  
28  /***
29   * This class provides a convenience methods for Velocity Actions
30   * to use. Since this class is abstract, it should only be extended
31   * and not used directly.
32   *
33   * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
34   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
35   * @version $Id: VelocityAction.java 534527 2007-05-02 16:10:59Z tv $
36   */
37  public abstract class VelocityAction extends VelocityActionEvent
38  {
39      /***
40       * You SHOULD NOT override this method and implement it in your
41       * action.
42       *
43       * @param data Turbine information.
44       * @throws Exception a generic exception.
45       */
46      public void doPerform(RunData data)
47              throws Exception
48      {
49          doPerform(data, getContext(data));
50      }
51  
52      /***
53       * You SHOULD override this method and implement it in your
54       * action.
55       *
56       * @param data Turbine information.
57       * @param context Context for web pages.
58       * @throws Exception a generic exception.
59       */
60      public abstract void doPerform(RunData data,
61                                     Context context)
62              throws Exception;
63  
64      /***
65       * Sets up the context and then calls super.perform(); thus,
66       * subclasses don't have to worry about getting a context
67       * themselves!
68       *
69       * @param data Turbine information.
70       * @throws Exception a generic exception.
71       */
72      protected void perform(RunData data)
73              throws Exception
74      {
75          super.perform(data);
76      }
77  
78      /***
79       * This method is used when you want to short circuit an Action
80       * and change the template that will be executed next.
81       *
82       * @param data Turbine information.
83       * @param template The template that will be executed next.
84       */
85      public void setTemplate(RunData data,
86                              String template)
87      {
88          TemplateScreen.setTemplate(data, template);
89      }
90  
91      /***
92       * Return the Context needed by Velocity.
93       *
94       * @param data Turbine information.
95       * @return Context, a context for web pages.
96       */
97      protected Context getContext(RunData data)
98      {
99          return TurbineVelocity.getContext(data);
100     }
101 }