1 package org.apache.turbine.util.velocity; 2 3 4 /* 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 */ 22 23 24 import org.apache.fulcrum.parser.ParameterParser; 25 import org.apache.turbine.Turbine; 26 import org.apache.turbine.modules.ActionEvent; 27 import org.apache.turbine.pipeline.PipelineData; 28 import org.apache.turbine.services.velocity.TurbineVelocity; 29 import org.apache.velocity.context.Context; 30 31 /** 32 * If you are using VelocitySite stuff, then your Action's should 33 * extend this class instead of extending the ActionEvent class. The 34 * difference between this class and the ActionEvent class is that 35 * this class will first attempt to execute one of your doMethod's 36 * with a constructor like this: 37 * 38 * <p><code>doEvent(RunData data, Context context)</code></p> 39 * 40 * <p>It gets the context from the TemplateInfo.getTemplateContext() 41 * method. If it can't find a method like that, then it will try to 42 * execute the method without the Context in it.</p> 43 * 44 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a> 45 * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a> 46 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 47 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 48 * @version $Id: VelocityActionEvent.java 1706425 2015-10-02 14:47:51Z tv $ 49 */ 50 public abstract class VelocityActionEvent extends ActionEvent 51 { 52 /** Indicates whether or not this module has been initialized. */ 53 protected boolean initialized = false; 54 55 /** 56 * Provides a means of initializing the module. 57 * 58 * @throws Exception a generic exception. 59 */ 60 protected abstract void initialize() 61 throws Exception; 62 63 /** 64 * This overrides the default Action.doPerform() to execute the 65 * doEvent() method. If that fails, then it will execute the 66 * doPerform() method instead. 67 * 68 * @param pipelineData A Turbine RunData object. 69 * @exception Exception a generic exception. 70 */ 71 @Override 72 public void doPerform(PipelineData pipelineData) 73 throws Exception 74 { 75 if (!initialized) 76 { 77 initialize(); 78 } 79 80 ParameterParser pp = pipelineData.get(Turbine.class, ParameterParser.class); 81 Context context = TurbineVelocity.getContext(pipelineData); 82 executeEvents(pp, new Class<?>[]{ PipelineData.class, Context.class }, 83 new Object[]{ pipelineData, context }); 84 } 85 }