001package org.apache.turbine.modules.actions; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.turbine.modules.screens.TemplateScreen; 023import org.apache.turbine.pipeline.PipelineData; 024import org.apache.turbine.util.velocity.VelocityActionEvent; 025import org.apache.velocity.context.Context; 026 027/** 028 * This class provides a convenience methods for Velocity Actions to use. Since 029 * this class is abstract, it should only be extended and not used directly. 030 * 031 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a> 032 * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a> 033 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 034 * @version $Id$ 035 */ 036public abstract class VelocityAction extends VelocityActionEvent 037{ 038 /** 039 * Initialize the module. 040 * 041 * @throws Exception a generic exception. 042 */ 043 @Override 044 public void initialize() throws Exception 045 { 046 initialized = true; 047 } 048 049 /** 050 * You SHOULD override this method and implement it in your action. 051 * 052 * @param pipelineData Turbine information. 053 * @param context Context for web pages. 054 * @throws Exception a generic exception. 055 */ 056 public abstract void doPerform(PipelineData pipelineData, Context context) 057 throws Exception; 058 059 /** 060 * Sets up the context and then calls super.perform(); thus, subclasses 061 * don't have to worry about getting a context themselves! If a subclass 062 * throws an exception then depending on whether 063 * action.event.bubbleexception is true, then it bubbles it farther up, or 064 * traps it there. 065 * 066 * @param pipelineData Turbine information. 067 * @throws Exception a generic exception. 068 */ 069 @Override 070 public void perform(PipelineData pipelineData) throws Exception 071 { 072 try 073 { 074 super.perform(pipelineData); 075 } 076 catch (Exception e) 077 { 078 if (bubbleUpException) 079 { 080 throw e; 081 } 082 } 083 } 084 085 /** 086 * This method is used when you want to short circuit an Action and change 087 * the template that will be executed next. 088 * 089 * @param pipelineData Turbine information. 090 * @param template The template that will be executed next. 091 */ 092 public void setTemplate(PipelineData pipelineData, String template) 093 { 094 TemplateScreen.setTemplate(pipelineData, template); 095 } 096}