    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.turbine.TurbineConstants;
    027import org.apache.turbine.annotation.TurbineConfiguration;
    028import org.apache.turbine.annotation.TurbineLoader;
    029import org.apache.turbine.annotation.TurbineService;
    030import org.apache.turbine.modules.Page;
    031import org.apache.turbine.modules.PageLoader;
    032import org.apache.turbine.services.template.TemplateService;
    033import org.apache.turbine.util.TurbineException;
    034
    035/**
    036 * Implements the Page Generation portion of the "Turbine classic"
    037 * processing pipeline (from the Turbine 2.x series).
    038 *
    039 * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
    040 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    041 * @version $Id: ExecutePageValve.java 1773378 2016-12-09 13:19:59Z tv $
    042 */
    043public class ExecutePageValve
    044    extends AbstractValve
    045{
    046    /** Injected service instance */
    047    @TurbineService
    048    private TemplateService templateService;
    049
    050    /** Injected loader instance */
    051    @TurbineLoader( Page.class )
    052    private PageLoader pageLoader;
    053
    054    @TurbineConfiguration( TurbineConstants.PAGE_DEFAULT_KEY )
    055    private String pageDefault = TurbineConstants.PAGE_DEFAULT_DEFAULT;
    056
    057    /**
    058     * @see org.apache.turbine.pipeline.Valve#invoke(PipelineData, ValveContext)
    059     */
    060    @Override
    061    public void invoke(PipelineData pipelineData, ValveContext context)
    062        throws IOException, TurbineException
    063    {
    064        try
    065        {
    066            executePage(pipelineData);
    067        }
    068        catch (Exception e)
    069        {
    070            throw new TurbineException(e);
    071        }
    072
    073        // Pass control to the next Valve in the Pipeline
    074        context.invokeNext(pipelineData);
    075    }
    076
    077    /**
    078     * execute the page generation.
    079     *
    080     * @param pipelineData The run-time data.
    081     *
    082     * @throws Exception if the page execution fails
    083     */
    084    protected void executePage(PipelineData pipelineData)
    085        throws Exception
    086    {
    087        // Start the execution phase. DefaultPage will execute the
    088        // appropriate action as well as get the Layout from the
    089        // Screen and then execute that. The Layout is then
    090        // responsible for executing the Navigation and Screen
    091        // modules.
    092        //
    093        // Note that by default, this cannot be overridden from
    094        // parameters passed in via post/query data. This is for
    095        // security purposes.  You should really never need more
    096        // than just the default page.  If you do, add logic to
    097        // DefaultPage to do what you want.
    098
    099        String defaultPage = (templateService == null)
    100        ? null : templateService.getDefaultPageName(pipelineData);
    101
    102        if (defaultPage == null)
    103        {
    104            /*
    105             * In this case none of the template services are running.
    106             * The application may be using ECS for views, or a
    107             * decendent of RawScreen is trying to produce output.
    108             * If there is a 'page.default' property in the TR.props
    109             * then use that, otherwise return DefaultPage which will
    110             * handle ECS view scenarios and RawScreen scenarios. The
    111             * app developer can still specify the 'page.default'
    112             * if they wish but the DefaultPage should work in
    113             * most cases.
    114             */
    115            defaultPage = pageDefault;
    116        }
    117
    118        pageLoader.exec(pipelineData, defaultPage);
    119    }
    120}