Coverage Report - org.apache.turbine.util.velocity.VelocityActionEvent
 
Classes in this File Line Coverage Branch Coverage Complexity
VelocityActionEvent
100%
8/8
50%
1/2
1,5
 
 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.annotation.TurbineService;
 27  
 import org.apache.turbine.modules.ActionEvent;
 28  
 import org.apache.turbine.pipeline.PipelineData;
 29  
 import org.apache.turbine.services.velocity.VelocityService;
 30  
 import org.apache.velocity.context.Context;
 31  
 
 32  
 /**
 33  
  * If you are using VelocitySite stuff, then your Action's should
 34  
  * extend this class instead of extending the ActionEvent class.  The
 35  
  * difference between this class and the ActionEvent class is that
 36  
  * this class will first attempt to execute one of your doMethod's
 37  
  * with a constructor like this:
 38  
  *
 39  
  * <p><code>doEvent(RunData data, Context context)</code></p>
 40  
  *
 41  
  * <p>It gets the context from the TemplateInfo.getTemplateContext()
 42  
  * method. If it can't find a method like that, then it will try to
 43  
  * execute the method without the Context in it.</p>
 44  
  *
 45  
  * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
 46  
  * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
 47  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 48  
  * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
 49  
  * @version $Id: VelocityActionEvent.java 1773378 2016-12-09 13:19:59Z tv $
 50  
  */
 51  11
 public abstract class VelocityActionEvent extends ActionEvent
 52  
 {
 53  
     /** Injected velocity service */
 54  
     @TurbineService
 55  
     protected VelocityService velocity;
 56  
 
 57  
     /** Indicates whether or not this module has been initialized. */
 58  11
     protected boolean initialized = false;
 59  
 
 60  
     /**
 61  
      * Provides a means of initializing the module.
 62  
      *
 63  
      * @throws Exception a generic exception.
 64  
      */
 65  
     protected abstract void initialize()
 66  
         throws Exception;
 67  
 
 68  
     /**
 69  
      * This overrides the default Action.doPerform() to execute the
 70  
      * doEvent() method.  If that fails, then it will execute the
 71  
      * doPerform() method instead.
 72  
      *
 73  
      * @param pipelineData A Turbine RunData object.
 74  
      * @throws Exception a generic exception.
 75  
      */
 76  
     @Override
 77  
     public void doPerform(PipelineData pipelineData)
 78  
             throws Exception
 79  
     {
 80  11
         if (!initialized)
 81  
         {
 82  11
             initialize();
 83  
         }
 84  
 
 85  11
         ParameterParser pp = pipelineData.get(Turbine.class, ParameterParser.class);
 86  11
         Context context = velocity.getContext(pipelineData);
 87  8
         executeEvents(pp, new Class<?>[]{ PipelineData.class, Context.class },
 88  
                 new Object[]{ pipelineData, context });
 89  7
     }
 90  
 }