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.pipeline.PipelineData;
24  import org.apache.turbine.services.velocity.TurbineVelocity;
25  import org.apache.turbine.util.RunData;
26  import org.apache.turbine.util.velocity.VelocityActionEvent;
27  import org.apache.velocity.context.Context;
28  
29  /**
30   * This class provides a convenience methods for Velocity Actions to use. Since
31   * this class is abstract, it should only be extended 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   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
36   * @version $Id: VelocityAction.java 1066529 2011-02-02 17:01:46Z ludwig $
37   */
38  public abstract class VelocityAction extends VelocityActionEvent
39  {
40      /**
41       * You SHOULD NOT override this method and implement it in your action.
42       * 
43       * @deprecated Use PipelineData version instead.
44       * @param data Turbine information.
45       * @throws Exception a generic exception.
46       */
47      @Override
48      @Deprecated
49      public void doPerform(RunData data) throws Exception
50      {
51          doPerform(data, getContext(data));
52      }
53  
54      /**
55       * You SHOULD NOT override this method and implement it in your action.
56       * 
57       * @param data Turbine information.
58       * @throws Exception a generic exception.
59       */
60      @Override
61      public void doPerform(PipelineData pipelineData) throws Exception
62      {
63          doPerform(pipelineData, getContext(pipelineData));
64      }
65  
66      /**
67       * Initialize the module.
68       * 
69       * @throws Exception a generic exception.
70       */
71      @Override
72      public void initialize() throws Exception
73      {
74          initialized = true;
75      }
76  
77      /**
78       * You SHOULD override this method and implement it in your action.
79       * 
80       * @deprecated Use PipelineData version instead.
81       * @param data Turbine information.
82       * @param context Context for web pages.
83       * @throws Exception a generic exception.
84       */
85      @Deprecated
86      public abstract void doPerform(RunData data, Context context)
87              throws Exception;
88  
89      /**
90       * You SHOULD override this method and implement it in your action.
91       * 
92       * This should become abstract when the RunData version is removed. For
93       * compatibility reasons this method will default to using the RunData
94       * method unles it is overidden, which it should be.
95       * 
96       * @param data Turbine information.
97       * @param context Context for web pages.
98       * @throws Exception a generic exception.
99       */
100     public void doPerform(PipelineData pipelineData, Context context)
101             throws Exception
102     {
103         RunData data = getRunData(pipelineData);
104         doPerform(data, context);
105     }
106 
107     /**
108      * Sets up the context and then calls super.perform(); thus, subclasses
109      * don't have to worry about getting a context themselves! If a subclass
110      * throws an exception then depending on whether
111      * action.event.bubbleexception is true, then it bubbles it farther up, or
112      * traps it there.
113      * 
114      * @deprecated Use PipelineData version instead.
115      * @param data Turbine information.
116      * @throws Exception a generic exception.
117      */
118     @Deprecated
119     @Override
120     protected void perform(RunData data) throws Exception
121     {
122         try
123         {
124             super.perform(data);
125         } catch (Exception e)
126         {
127             if (bubbleUpException)
128             {
129                 throw e;
130             }
131 
132         }
133     }
134 
135     /**
136      * Sets up the context and then calls super.perform(); thus, subclasses
137      * don't have to worry about getting a context themselves! If a subclass
138      * throws an exception then depending on whether
139      * action.event.bubbleexception is true, then it bubbles it farther up, or
140      * traps it there.
141      * 
142      * @param data Turbine information.
143      * @throws Exception a generic exception.
144      */
145     @Override
146     protected void perform(PipelineData pipelineData) throws Exception
147     {
148         try
149         {
150             super.perform(pipelineData);
151         } catch (Exception e)
152         {
153             if (bubbleUpException)
154             {
155                 throw e;
156             }
157 
158         }
159     }
160 
161     /**
162      * This method is used when you want to short circuit an Action and change
163      * the template that will be executed next.
164      * 
165      * @deprecated Use PipelineData version instead.
166      * @param data Turbine information.
167      * @param template The template that will be executed next.
168      */
169     @Deprecated
170     public void setTemplate(RunData data, String template)
171     {
172         TemplateScreen.setTemplate(data, template);
173     }
174 
175     /**
176      * This method is used when you want to short circuit an Action and change
177      * the template that will be executed next.
178      * 
179      * @param data Turbine information.
180      * @param template The template that will be executed next.
181      */
182     public void setTemplate(PipelineData pipelineData, String template)
183     {
184         TemplateScreen.setTemplate(pipelineData, template);
185     }
186 
187     /**
188      * Return the Context needed by Velocity.
189      * 
190      * @deprecated Use PipelineData version instead.
191      * @param data Turbine information.
192      * @return Context, a context for web pages.
193      */
194     @Deprecated
195     protected Context getContext(RunData data)
196     {
197         return TurbineVelocity.getContext(data);
198     }
199 
200     /**
201      * Return the Context needed by Velocity.
202      * 
203      * @param data Turbine information.
204      * @return Context, a context for web pages.
205      */
206     protected Context getContext(PipelineData pipelineData)
207     {
208         return TurbineVelocity.getContext(pipelineData);
209     }
210 
211 }