KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > modules > actions > VelocityAction


1 package org.apache.turbine.modules.actions;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.turbine.modules.screens.TemplateScreen;
20 import org.apache.turbine.services.velocity.TurbineVelocity;
21 import org.apache.turbine.util.RunData;
22 import org.apache.turbine.util.velocity.VelocityActionEvent;
23 import org.apache.velocity.context.Context;
24
25 /**
26  * This class provides a convenience methods for Velocity Actions
27  * to use. Since this class is abstract, it should only be extended
28  * and not used directly.
29  *
30  * @author <a HREF="mailto:jon@latchkey.com">Jon S. Stevens</a>
31  * @author <a HREF="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
32  * @version $Id: VelocityAction.java,v 1.5.2.2 2004/05/20 03:03:53 seade Exp $
33  */

34 public abstract class VelocityAction extends VelocityActionEvent
35 {
36     /**
37      * You SHOULD NOT override this method and implement it in your
38      * action.
39      *
40      * @param data Turbine information.
41      * @throws Exception a generic exception.
42      */

43     public void doPerform(RunData data)
44             throws Exception JavaDoc
45     {
46         doPerform(data, getContext(data));
47     }
48
49     /**
50      * You SHOULD override this method and implement it in your
51      * action.
52      *
53      * @param data Turbine information.
54      * @param context Context for web pages.
55      * @throws Exception a generic exception.
56      */

57     public abstract void doPerform(RunData data,
58                                    Context context)
59             throws Exception JavaDoc;
60
61     /**
62      * Sets up the context and then calls super.perform(); thus,
63      * subclasses don't have to worry about getting a context
64      * themselves!
65      *
66      * @param data Turbine information.
67      * @throws Exception a generic exception.
68      */

69     protected void perform(RunData data)
70             throws Exception JavaDoc
71     {
72         super.perform(data);
73     }
74
75     /**
76      * This method is used when you want to short circuit an Action
77      * and change the template that will be executed next.
78      *
79      * @param data Turbine information.
80      * @param template The template that will be executed next.
81      */

82     public void setTemplate(RunData data,
83                             String JavaDoc template)
84     {
85         TemplateScreen.setTemplate(data, template);
86     }
87
88     /**
89      * Return the Context needed by Velocity.
90      *
91      * @param data Turbine information.
92      * @return Context, a context for web pages.
93      */

94     protected Context getContext(RunData data)
95     {
96         return TurbineVelocity.getContext(data);
97     }
98 }
99
Popular Tags