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.configuration.Configuration;
027import org.apache.turbine.TurbineConstants;
028import org.apache.turbine.annotation.TurbineConfiguration;
029import org.apache.turbine.annotation.TurbineLoader;
030import org.apache.turbine.annotation.TurbineService;
031import org.apache.turbine.modules.Page;
032import org.apache.turbine.modules.PageLoader;
033import org.apache.turbine.services.template.TemplateService;
034import org.apache.turbine.util.TurbineException;
035
036/**
037 * Implements the Page Generation portion of the "Turbine classic"
038 * processing pipeline (from the Turbine 2.x series).
039 *
040 * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
041 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
042 * @version $Id: ExecutePageValve.java 1709648 2015-10-20 17:08:10Z tv $
043 */
044public class ExecutePageValve
045    extends AbstractValve
046{
047    /** Injected service instance */
048    @TurbineService
049    private TemplateService templateService;
050
051    /** Injected loader instance */
052    @TurbineLoader( Page.class )
053    private PageLoader pageLoader;
054
055    /** Injected configuration instance */
056    @TurbineConfiguration
057    private Configuration config;
058
059    /**
060     * @see org.apache.turbine.pipeline.Valve#invoke(PipelineData, ValveContext)
061     */
062    @Override
063    public void invoke(PipelineData pipelineData, ValveContext context)
064        throws IOException, TurbineException
065    {
066        try
067        {
068            executePage(pipelineData);
069        }
070        catch (Exception e)
071        {
072            throw new TurbineException(e);
073        }
074
075        // Pass control to the next Valve in the Pipeline
076        context.invokeNext(pipelineData);
077    }
078
079    /**
080     * execute the page generation.
081     *
082     * @param pipelineData The run-time data.
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 = config.getString(TurbineConstants.PAGE_DEFAULT_KEY,
116                    TurbineConstants.PAGE_DEFAULT_DEFAULT);
117        }
118
119        pageLoader.exec(pipelineData, defaultPage);
120    }
121}