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.turbine.Turbine;
027 import org.apache.turbine.TurbineConstants;
028 import org.apache.turbine.modules.Page;
029 import org.apache.turbine.modules.PageLoader;
030 import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
031 import org.apache.turbine.services.template.TemplateService;
032 import org.apache.turbine.services.template.TurbineTemplate;
033 import org.apache.turbine.util.RunData;
034 import 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 757213 2009-03-22 16:43:31Z tv $
043 */
044 public class ExecutePageValve
045 extends AbstractValve
046 {
047 private TemplateService templateService;
048 private PageLoader pageLoader;
049
050 /**
051 * Creates a new instance.
052 */
053 public ExecutePageValve()
054 {
055 // empty constructor
056 }
057
058 /**
059 * Initialize this valve for use in a pipeline.
060 *
061 * @see org.apache.turbine.pipeline.AbstractValve#initialize()
062 */
063 public void initialize() throws Exception
064 {
065 super.initialize();
066
067 this.templateService = TurbineTemplate.getService();
068 this.pageLoader = (PageLoader)TurbineAssemblerBroker.getLoader(Page.NAME);
069 }
070
071 /**
072 * @see org.apache.turbine.Valve#invoke(RunData, ValveContext)
073 */
074 public void invoke(PipelineData pipelineData, ValveContext context)
075 throws IOException, TurbineException
076 {
077 try
078 {
079 executePage(pipelineData);
080 }
081 catch (Exception e)
082 {
083 throw new TurbineException(e);
084 }
085
086 // Pass control to the next Valve in the Pipeline
087 context.invokeNext(pipelineData);
088 }
089
090 /**
091 * execute the page generation.
092 *
093 * @param data The run-time data.
094 */
095 protected void executePage(PipelineData pipelineData)
096 throws Exception
097 {
098 RunData data = getRunData(pipelineData);
099
100 // Start the execution phase. DefaultPage will execute the
101 // appropriate action as well as get the Layout from the
102 // Screen and then execute that. The Layout is then
103 // responsible for executing the Navigation and Screen
104 // modules.
105 //
106 // Note that by default, this cannot be overridden from
107 // parameters passed in via post/query data. This is for
108 // security purposes. You should really never need more
109 // than just the default page. If you do, add logic to
110 // DefaultPage to do what you want.
111
112 String defaultPage = (templateService == null)
113 ? null :templateService.getDefaultPageName(data);
114
115 if (defaultPage == null)
116 {
117 /*
118 * In this case none of the template services are running.
119 * The application may be using ECS for views, or a
120 * decendent of RawScreen is trying to produce output.
121 * If there is a 'page.default' property in the TR.props
122 * then use that, otherwise return DefaultPage which will
123 * handle ECS view scenerios and RawScreen scenerios. The
124 * app developer can still specify the 'page.default'
125 * if they wish but the DefaultPage should work in
126 * most cases.
127 */
128 defaultPage = Turbine.getConfiguration().getString(TurbineConstants.PAGE_DEFAULT_KEY,
129 TurbineConstants.PAGE_DEFAULT_DEFAULT);
130 }
131
132 pageLoader.exec(pipelineData, defaultPage);
133 }
134 }