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.fulcrum.parser.ParameterParser;
023import org.apache.turbine.Turbine;
024import org.apache.turbine.pipeline.PipelineData;
025import org.apache.turbine.services.velocity.TurbineVelocity;
026import org.apache.turbine.util.RunData;
027import org.apache.velocity.context.Context;
028
029/**
030 * This class provides a methods for Turbine2 Velocity Actions to use. Since
031 * this class is abstract, it should only be extended and not used directly.
032 *
033 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
034 * @deprecated Use VelocityAction directly
035 */
036@Deprecated
037public abstract class LegacyVelocityAction extends VelocityAction
038{
039    /**
040     * You SHOULD override this method and implement it in your action.
041     *
042     * @param data Turbine information.
043     * @param context Context for web pages.
044     * @throws Exception a generic exception.
045     */
046    public abstract void doPerform(RunData data, Context context)
047            throws Exception;
048
049    /**
050     * Adapter method for legacy signature
051     *
052     * @param pipelineData Turbine information.
053     * @param context Context for web pages.
054     * @throws Exception a generic exception.
055     */
056    @Override
057    public void doPerform(PipelineData pipelineData, Context context)
058            throws Exception
059    {
060        doPerform(getRunData(pipelineData), context);
061    }
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        RunData data = getRunData(pipelineData);
081        ParameterParser pp = pipelineData.get(Turbine.class, ParameterParser.class);
082        Context context = TurbineVelocity.getContext(pipelineData);
083        executeEvents(pp, new Class<?>[]{ RunData.class, Context.class },
084                new Object[]{ data, context });
085    }
086}