Clover coverage report - Code Coverage for tapestry release 3.1-alpha-1
Coverage timestamp: Mon Feb 21 2005 09:16:14 EST
file stats: LOC: 116   Methods: 4
NCLOC: 75   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
RedirectAnalyzer.java 100% 100% 100% 100%
coverage
 1   
 // Copyright 2004, 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.tapestry.engine;
 16   
 
 17   
 import java.io.IOException;
 18   
 
 19   
 import javax.servlet.RequestDispatcher;
 20   
 import javax.servlet.ServletException;
 21   
 import javax.servlet.http.HttpServletRequest;
 22   
 import javax.servlet.http.HttpServletResponse;
 23   
 
 24   
 import org.apache.hivemind.ApplicationRuntimeException;
 25   
 import org.apache.hivemind.HiveMind;
 26   
 import org.apache.tapestry.IRequestCycle;
 27   
 import org.apache.tapestry.Tapestry;
 28   
 import org.apache.tapestry.request.RequestContext;
 29   
 
 30   
 /**
 31   
  * Used by {@link org.apache.tapestry.engine.AbstractEngine}when processing a
 32   
  * {@link org.apache.tapestry.RedirectException}.
 33   
  * 
 34   
  * @author Howard Lewis Ship
 35   
  * @since 3.0
 36   
  */
 37   
 class RedirectAnalyzer
 38   
 {
 39   
     private boolean _internal;
 40   
 
 41   
     private String _location;
 42   
 
 43  7
     public RedirectAnalyzer(String location)
 44   
     {
 45  7
         if (HiveMind.isBlank(location))
 46   
         {
 47  1
             _location = "";
 48  1
             _internal = true;
 49   
 
 50  1
             return;
 51   
         }
 52   
 
 53  6
         _location = location;
 54   
 
 55  6
         _internal = !(location.startsWith("/") || location.indexOf("://") > 0);
 56   
     }
 57   
 
 58  7
     public void process(IRequestCycle cycle)
 59   
     {
 60  7
         RequestContext context = cycle.getRequestContext();
 61   
 
 62  7
         if (_internal)
 63  5
             forward(context);
 64   
         else
 65  2
             redirect(context);
 66   
     }
 67   
 
 68  5
     private void forward(RequestContext context)
 69   
     {
 70  5
         HttpServletRequest request = context.getRequest();
 71  5
         HttpServletResponse response = context.getResponse();
 72   
 
 73  5
         RequestDispatcher dispatcher = request.getRequestDispatcher("/" + _location);
 74   
 
 75  5
         if (dispatcher == null)
 76  1
             throw new ApplicationRuntimeException(Tapestry.format(
 77   
                     "AbstractEngine.unable-to-find-dispatcher",
 78   
                     _location));
 79   
 
 80  4
         try
 81   
         {
 82  4
             dispatcher.forward(request, response);
 83   
         }
 84   
         catch (ServletException ex)
 85   
         {
 86  1
             throw new ApplicationRuntimeException(Tapestry.format(
 87   
                     "AbstractEngine.unable-to-forward",
 88   
                     _location), ex);
 89   
         }
 90   
         catch (IOException ex)
 91   
         {
 92  1
             throw new ApplicationRuntimeException(Tapestry.format(
 93   
                     "AbstractEngine.unable-to-forward",
 94   
                     _location), ex);
 95   
         }
 96   
     }
 97   
 
 98  2
     private void redirect(RequestContext context)
 99   
     {
 100  2
         HttpServletResponse response = context.getResponse();
 101   
 
 102  2
         String finalURL = response.encodeRedirectURL(_location);
 103   
 
 104  2
         try
 105   
         {
 106  2
             response.sendRedirect(finalURL);
 107   
         }
 108   
         catch (IOException ex)
 109   
         {
 110  1
             throw new ApplicationRuntimeException(Tapestry.format(
 111   
                     "AbstractEngine.unable-to-redirect",
 112   
                     _location), ex);
 113   
         }
 114   
     }
 115   
 
 116   
 }