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

Classes in this File | Line Coverage | Branch Coverage | Complexity
DetermineTargetValve |
100% | 13/13
66% | 4/6
| 4.0;4

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.logging.Log;
27 |  |
     import org.apache.commons.logging.LogFactory;
28 |  |
     import org.apache.turbine.util.RunData;
29 |  |
     import org.apache.turbine.util.TurbineException;
30 |  |
     import org.apache.turbine.util.uri.URIConstants;
31 |  |
32 |  |
     /**
33 |  |
      * This valve is responsible for setting the 'target' property of the RunData.
34 |  |
      * If it is not already set it attempts to get the target from the request
35 |  |
      * parameter 'template'. If the parameter is not set, we use the homepage
36 |  |
      * specified by the configuration property Turbine.TEMPLATE_HOMEPAGE.
37 |  |
      *
38 |  |
      * FIXME: The request parameter which determines the template should be
39 |  |
      *        configurable.
40 |  |
      *
41 |  |
      * @author <a href="mailto:james@jamestaylor.org">James Taylor</a>
42 |  |
      * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
43 |  |
      */
44 | 2 |
     public class DetermineTargetValve
45 |  |
         extends AbstractValve
46 |  |
     {
47 | 31 |
         private static final Log log
48 |  |
             = LogFactory.getLog(DetermineTargetValve.class);
49 |  |
50 |  |
         /**
51 |  |
          * @see org.apache.turbine.pipeline.Valve#invoke(PipelineData, ValveContext)
52 |  |
          */
53 |  |
         public void invoke(PipelineData pipelineData, ValveContext context)
54 |  |
             throws IOException, TurbineException
55 |  |
         {
56 | 3 |
             RunData runData = getRunData(pipelineData);
57 | 3 |
             if (! runData.hasScreen())
58 |  |
             {
59 | 3 |
                 String target = runData.getParameters().getString(URIConstants.CGI_SCREEN_PARAM);
60 |  |
61 | 3 |
                 if (target != null)
62 |  |
                 {
63 | 1 |
                     runData.setScreen(target);
64 |  |
65 | 1 |
                     log.debug("Set screen target from request parameter");
66 |  |
                 }
67 |  |
                 else
68 |  |
                 {
69 |  |
                 /*    data.setScreen(Turbine.getConfiguration().getString(
70 |  |
                         Turbine.TEMPLATE_HOMEPAGE));
71 |  |
72 |  |
                     log.debug("Set target using default value");
73 |  |
                     */
74 | 2 |
                                     log.debug("No target screen");
75 |  |
                 }
76 |  |
77 |  |
             }
78 |  |
79 | 3 |
             if (log.isDebugEnabled())
80 |  |
             {
81 | 3 |
                 log.debug("Screen Target is now: " + runData.getScreen());
82 |  |
             }
83 |  |
84 |  |
             // Pass control to the next Valve in the Pipeline
85 | 3 |
             context.invokeNext(pipelineData);
86 | 2 |
         }
87 |  |
     }