001package org.apache.turbine.pipeline;
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 java.io.IOException;
025
026import org.apache.commons.logging.Log;
027import org.apache.commons.logging.LogFactory;
028import org.apache.turbine.util.RunData;
029import org.apache.turbine.util.TurbineException;
030import org.apache.turbine.util.uri.URIConstants;
031
032/**
033 * This valve is responsible for setting the 'action' property of RunData based
034 * on request parameter. There is no default action, since a null action is
035 * perfectly valid.
036 *
037 * @author <a href="mailto:james@jamestaylor.org">James Taylor</a>
038 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
039 */
040public class DetermineActionValve
041    extends AbstractValve
042{
043    private static final Log log
044        = LogFactory.getLog(DetermineActionValve.class);
045
046    /**
047     * @see org.apache.turbine.pipeline.Valve#invoke(PipelineData, ValveContext)
048     */
049    public void invoke(PipelineData pipelineData, ValveContext context)
050        throws IOException, TurbineException
051    {
052        RunData data = getRunData(pipelineData);
053        if (! data.hasAction())
054        {
055            String action =
056                data.getParameters().getString(URIConstants.CGI_ACTION_PARAM);
057
058            if (action != null)
059            {
060                data.setAction(action);
061
062                log.debug("Set action from request parameter");
063            }
064            else
065            {
066                log.debug("No action");
067            }
068        }
069
070        if (log.isDebugEnabled())
071        {
072            log.debug("Action is now: " + data.getAction());
073        }
074
075        // Pass control to the next Valve in the Pipeline
076        context.invokeNext(pipelineData);
077    }
078}