    001    package 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
    024    import java.io.IOException;
    025
    026    import org.apache.commons.logging.Log;
    027    import org.apache.commons.logging.LogFactory;
    028    import org.apache.turbine.util.RunData;
    029    import org.apache.turbine.util.TurbineException;
    030    import org.apache.turbine.util.uri.URIConstants;
    031
    032    /**
    033     * This valve is responsible for setting the 'target' property of the RunData.
    034     * If it is not already set it attempts to get the target from the request
    035     * parameter 'template'. If the parameter is not set, we use the homepage
    036     * specified by the configuration property Turbine.TEMPLATE_HOMEPAGE.
    037     *
    038     * FIXME: The request parameter which determines the template should be
    039     *        configurable.
    040     *
    041     * @author <a href="mailto:james@jamestaylor.org">James Taylor</a>
    042     * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    043     */
    044    public class DetermineTargetValve
    045        extends AbstractValve
    046    {
    047        private static final Log log
    048            = LogFactory.getLog(DetermineTargetValve.class);
    049
    050        /**
    051         * @see org.apache.turbine.Valve#invoke(RunData, ValveContext)
    052         */
    053        public void invoke(PipelineData pipelineData, ValveContext context)
    054            throws IOException, TurbineException
    055        {
    056            RunData runData = getRunData(pipelineData);
    057            if (! runData.hasScreen())
    058            {
    059                String target = runData.getParameters().getString(URIConstants.CGI_SCREEN_PARAM);
    060
    061                if (target != null)
    062                {
    063                    runData.setScreen(target);
    064
    065                    log.debug("Set screen target from request parameter");
    066                }
    067                else
    068                {
    069                /*    data.setScreen(Turbine.getConfiguration().getString(
    070                        Turbine.TEMPLATE_HOMEPAGE));
    071
    072                    log.debug("Set target using default value");
    073                    */
    074                                    log.debug("No target screen");
    075                }
    076
    077            }
    078
    079            if (log.isDebugEnabled())
    080            {
    081                log.debug("Screen Target is now: " + runData.getScreen());
    082            }
    083
    084            // Pass control to the next Valve in the Pipeline
    085            context.invokeNext(pipelineData);
    086        }
    087    }