001package org.apache.turbine.util.velocity; 002 003 004/* 005 * Licensed to the Apache Software Foundation (ASF) under one 006 * or more contributor license agreements. See the NOTICE file 007 * distributed with this work for additional information 008 * regarding copyright ownership. The ASF licenses this file 009 * to you under the Apache License, Version 2.0 (the 010 * "License"); you may not use this file except in compliance 011 * with the License. You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, 016 * software distributed under the License is distributed on an 017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 018 * KIND, either express or implied. See the License for the 019 * specific language governing permissions and limitations 020 * under the License. 021 */ 022 023 024import org.apache.fulcrum.parser.ParameterParser; 025import org.apache.turbine.Turbine; 026import org.apache.turbine.modules.ActionEvent; 027import org.apache.turbine.pipeline.PipelineData; 028import org.apache.turbine.services.velocity.TurbineVelocity; 029import org.apache.velocity.context.Context; 030 031/** 032 * If you are using VelocitySite stuff, then your Action's should 033 * extend this class instead of extending the ActionEvent class. The 034 * difference between this class and the ActionEvent class is that 035 * this class will first attempt to execute one of your doMethod's 036 * with a constructor like this: 037 * 038 * <p><code>doEvent(RunData data, Context context)</code></p> 039 * 040 * <p>It gets the context from the TemplateInfo.getTemplateContext() 041 * method. If it can't find a method like that, then it will try to 042 * execute the method without the Context in it.</p> 043 * 044 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a> 045 * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a> 046 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 047 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 048 * @version $Id: VelocityActionEvent.java 1706425 2015-10-02 14:47:51Z tv $ 049 */ 050public abstract class VelocityActionEvent extends ActionEvent 051{ 052 /** Indicates whether or not this module has been initialized. */ 053 protected boolean initialized = false; 054 055 /** 056 * Provides a means of initializing the module. 057 * 058 * @throws Exception a generic exception. 059 */ 060 protected abstract void initialize() 061 throws Exception; 062 063 /** 064 * This overrides the default Action.doPerform() to execute the 065 * doEvent() method. If that fails, then it will execute the 066 * doPerform() method instead. 067 * 068 * @param pipelineData A Turbine RunData object. 069 * @exception Exception a generic exception. 070 */ 071 @Override 072 public void doPerform(PipelineData pipelineData) 073 throws Exception 074 { 075 if (!initialized) 076 { 077 initialize(); 078 } 079 080 ParameterParser pp = pipelineData.get(Turbine.class, ParameterParser.class); 081 Context context = TurbineVelocity.getContext(pipelineData); 082 executeEvents(pp, new Class<?>[]{ PipelineData.class, Context.class }, 083 new Object[]{ pipelineData, context }); 084 } 085}