01: package org.apache.turbine.modules.actions;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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: * You SHOULD NOT override this method and implement it in your
40: * action.
41: *
42: * @param data Turbine information.
43: * @throws Exception a generic exception.
44: */
45: public void doPerform(RunData data) throws Exception {
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, Context context)
58: throws Exception;
59:
60: /**
61: * Sets up the context and then calls super.perform(); thus,
62: * subclasses don't have to worry about getting a context
63: * themselves!
64: *
65: * @param data Turbine information.
66: * @throws Exception a generic exception.
67: */
68: protected void perform(RunData data) throws Exception {
69: super .perform(data);
70: }
71:
72: /**
73: * This method is used when you want to short circuit an Action
74: * and change the template that will be executed next.
75: *
76: * @param data Turbine information.
77: * @param template The template that will be executed next.
78: */
79: public void setTemplate(RunData data, String template) {
80: TemplateScreen.setTemplate(data, template);
81: }
82:
83: /**
84: * Return the Context needed by Velocity.
85: *
86: * @param data Turbine information.
87: * @return Context, a context for web pages.
88: */
89: protected Context getContext(RunData data) {
90: return TurbineVelocity.getContext(data);
91: }
92: }
|