Coverage Report - org.apache.turbine.pipeline.ExecutePageValve
 
Classes in this File Line Coverage Branch Coverage Complexity
ExecutePageValve
91%
11/12
50%
2/4
3
 
 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.commons.configuration.Configuration;
 27  
 import org.apache.turbine.TurbineConstants;
 28  
 import org.apache.turbine.annotation.TurbineConfiguration;
 29  
 import org.apache.turbine.annotation.TurbineLoader;
 30  
 import org.apache.turbine.annotation.TurbineService;
 31  
 import org.apache.turbine.modules.Page;
 32  
 import org.apache.turbine.modules.PageLoader;
 33  
 import org.apache.turbine.services.template.TemplateService;
 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 1709648 2015-10-20 17:08:10Z tv $
 43  
  */
 44  2
 public class ExecutePageValve
 45  
     extends AbstractValve
 46  
 {
 47  
     /** Injected service instance */
 48  
     @TurbineService
 49  
     private TemplateService templateService;
 50  
 
 51  
     /** Injected loader instance */
 52  
     @TurbineLoader( Page.class )
 53  
     private PageLoader pageLoader;
 54  
 
 55  
     /** Injected configuration instance */
 56  
     @TurbineConfiguration
 57  
     private Configuration config;
 58  
 
 59  
     /**
 60  
      * @see org.apache.turbine.pipeline.Valve#invoke(PipelineData, ValveContext)
 61  
      */
 62  
     @Override
 63  
     public void invoke(PipelineData pipelineData, ValveContext context)
 64  
         throws IOException, TurbineException
 65  
     {
 66  
         try
 67  
         {
 68  3
             executePage(pipelineData);
 69  
         }
 70  1
         catch (Exception e)
 71  
         {
 72  1
             throw new TurbineException(e);
 73  2
         }
 74  
 
 75  
         // Pass control to the next Valve in the Pipeline
 76  2
         context.invokeNext(pipelineData);
 77  2
     }
 78  
 
 79  
     /**
 80  
      * execute the page generation.
 81  
      *
 82  
      * @param pipelineData The run-time data.
 83  
      */
 84  
     protected void executePage(PipelineData pipelineData)
 85  
         throws Exception
 86  
     {
 87  
         // Start the execution phase. DefaultPage will execute the
 88  
         // appropriate action as well as get the Layout from the
 89  
         // Screen and then execute that. The Layout is then
 90  
         // responsible for executing the Navigation and Screen
 91  
         // modules.
 92  
         //
 93  
         // Note that by default, this cannot be overridden from
 94  
         // parameters passed in via post/query data. This is for
 95  
         // security purposes.  You should really never need more
 96  
         // than just the default page.  If you do, add logic to
 97  
         // DefaultPage to do what you want.
 98  
 
 99  3
         String defaultPage = (templateService == null)
 100  
         ? null : templateService.getDefaultPageName(pipelineData);
 101  
 
 102  3
         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  0
             defaultPage = config.getString(TurbineConstants.PAGE_DEFAULT_KEY,
 116  
                     TurbineConstants.PAGE_DEFAULT_DEFAULT);
 117  
         }
 118  
 
 119  3
         pageLoader.exec(pipelineData, defaultPage);
 120  2
     }
 121  
 }