##### Coverage Report - org.apache.turbine.pipeline.ExecutePageValve

Classes in this File | Line Coverage | Branch Coverage | Complexity
ExecutePageValve |
94% | 17/18
50% | 2/4
| 2.0;2

1 |  |
     package org.apache.turbine.pipeline;
2 |  |
3 |  |
4 |  |
     /*
5 |  |
      * Licensed to the Apache Software Foundation (ASF) under one
6 |  |
      * or more contributor license agreements.  See the NOTICE file
7 |  |
      * distributed with this work for additional information
8 |  |
      * regarding copyright ownership.  The ASF licenses this file
9 |  |
      * to you under the Apache License, Version 2.0 (the
10 |  |
      * "License"); you may not use this file except in compliance
11 |  |
      * with the License.  You may obtain a copy of the License at
12 |  |
      *
13 |  |
      *   http://www.apache.org/licenses/LICENSE-2.0
14 |  |
      *
15 |  |
      * Unless required by applicable law or agreed to in writing,
16 |  |
      * software distributed under the License is distributed on an
17 |  |
      * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 |  |
      * KIND, either express or implied.  See the License for the
19 |  |
      * specific language governing permissions and limitations
20 |  |
      * under the License.
21 |  |
      */
22 |  |
23 |  |
24 |  |
     import java.io.IOException;
25 |  |
26 |  |
     import org.apache.turbine.Turbine;
27 |  |
     import org.apache.turbine.TurbineConstants;
28 |  |
     import org.apache.turbine.modules.Page;
29 |  |
     import org.apache.turbine.modules.PageLoader;
30 |  |
     import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
31 |  |
     import org.apache.turbine.services.template.TemplateService;
32 |  |
     import org.apache.turbine.services.template.TurbineTemplate;
33 |  |
     import org.apache.turbine.util.RunData;
34 |  |
     import org.apache.turbine.util.TurbineException;
35 |  |
36 |  |
     /**
37 |  |
      * Implements the Page Generation portion of the "Turbine classic"
38 |  |
      * processing pipeline (from the Turbine 2.x series).
39 |  |
      *
40 |  |
      * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
41 |  |
      * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
42 |  |
      * @version $Id: ExecutePageValve.java 757213 2009-03-22 16:43:31Z tv $
43 |  |
      */
44 |  |
     public class ExecutePageValve
45 |  |
         extends AbstractValve
46 |  |
     {
47 |  |
         private TemplateService templateService;
48 |  |
         private PageLoader pageLoader;
49 |  |
50 |  |
         /**
51 |  |
          * Creates a new instance.
52 |  |
          */
53 |  |
         public ExecutePageValve()
54 | 2 |
         {
55 |  |
             // empty constructor
56 | 2 |
         }
57 |  |
58 |  |
         /**
59 |  |
          * Initialize this valve for use in a pipeline.
60 |  |
          *
61 |  |
          * @see org.apache.turbine.pipeline.AbstractValve#initialize()
62 |  |
          */
63 |  |
         public void initialize() throws Exception
64 |  |
         {
65 | 96 |
             super.initialize();
66 |  |
67 | 96 |
             this.templateService = TurbineTemplate.getService();
68 | 96 |
             this.pageLoader = (PageLoader)TurbineAssemblerBroker.getLoader(Page.NAME);
69 | 96 |
         }
70 |  |
71 |  |
         /**
72 |  |
          * @see org.apache.turbine.Valve#invoke(RunData, ValveContext)
73 |  |
          */
74 |  |
         public void invoke(PipelineData pipelineData, ValveContext context)
75 |  |
             throws IOException, TurbineException
76 |  |
         {
77 |  |
             try
78 |  |
             {
79 | 4 |
                 executePage(pipelineData);
80 |  |
             }
81 | 2 |
             catch (Exception e)
82 |  |
             {
83 | 2 |
                 throw new TurbineException(e);
84 | 2 |
             }
85 |  |
86 |  |
             // Pass control to the next Valve in the Pipeline
87 | 2 |
             context.invokeNext(pipelineData);
88 | 2 |
         }
89 |  |
90 |  |
         /**
91 |  |
          * execute the page generation.
92 |  |
          *
93 |  |
          * @param data The run-time data.
94 |  |
          */
95 |  |
         protected void executePage(PipelineData pipelineData)
96 |  |
             throws Exception
97 |  |
         {
98 | 4 |
             RunData data = getRunData(pipelineData);
99 |  |
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 | 4 |
             String defaultPage = (templateService == null)
113 |  |
             ? null :templateService.getDefaultPageName(data);
114 |  |
115 | 4 |
             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 | 0 |
                 defaultPage = Turbine.getConfiguration().getString(TurbineConstants.PAGE_DEFAULT_KEY,
129 |  |
                         TurbineConstants.PAGE_DEFAULT_DEFAULT);
130 |  |
             }
131 |  |
132 | 4 |
             pageLoader.exec(pipelineData, defaultPage);
133 | 2 |
         }
134 |  |
     }