Coverage Report - org.apache.turbine.pipeline.ExecutePageValve
 
Classes in this File Line Coverage Branch Coverage Complexity
ExecutePageValve
92%
13/14
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.turbine.TurbineConstants;
 27  
 import org.apache.turbine.annotation.TurbineConfiguration;
 28  
 import org.apache.turbine.annotation.TurbineLoader;
 29  
 import org.apache.turbine.annotation.TurbineService;
 30  
 import org.apache.turbine.modules.Page;
 31  
 import org.apache.turbine.modules.PageLoader;
 32  
 import org.apache.turbine.services.template.TemplateService;
 33  
 import org.apache.turbine.util.TurbineException;
 34  
 
 35  
 /**
 36  
  * Implements the Page Generation portion of the "Turbine classic"
 37  
  * processing pipeline (from the Turbine 2.x series).
 38  
  *
 39  
  * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
 40  
  * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
 41  
  * @version $Id: ExecutePageValve.java 1854797 2019-03-04 20:41:39Z tv $
 42  
  */
 43  138
 public class ExecutePageValve
 44  
     implements Valve
 45  
 {
 46  
     /** Injected service instance */
 47  
     @TurbineService
 48  
     private TemplateService templateService;
 49  
 
 50  
     /** Injected loader instance */
 51  
     @TurbineLoader( Page.class )
 52  
     private PageLoader pageLoader;
 53  
 
 54  138
     @TurbineConfiguration( TurbineConstants.PAGE_DEFAULT_KEY )
 55  
     private String pageDefault = TurbineConstants.PAGE_DEFAULT_DEFAULT;
 56  
 
 57  
     /**
 58  
      * @see org.apache.turbine.pipeline.Valve#invoke(PipelineData, ValveContext)
 59  
      */
 60  
     @Override
 61  
     public void invoke(PipelineData pipelineData, ValveContext context)
 62  
         throws IOException, TurbineException
 63  
     {
 64  
         try
 65  
         {
 66  9
             executePage(pipelineData);
 67  
         }
 68  3
         catch (Exception e)
 69  
         {
 70  3
             throw new TurbineException(e);
 71  6
         }
 72  
 
 73  
         // Pass control to the next Valve in the Pipeline
 74  6
         context.invokeNext(pipelineData);
 75  6
     }
 76  
 
 77  
     /**
 78  
      * execute the page generation.
 79  
      *
 80  
      * @param pipelineData The run-time data.
 81  
      *
 82  
      * @throws Exception if the page execution fails
 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  9
         String defaultPage = (templateService == null)
 100  9
         ? null : templateService.getDefaultPageName(pipelineData);
 101  
 
 102  9
         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 = pageDefault;
 116  
         }
 117  
 
 118  9
         pageLoader.exec(pipelineData, defaultPage);
 119  6
     }
 120  
 }