Clover coverage report - Cactus 1.4 for J2EE API 12
Coverage timestamp: Sun Aug 25 2002 18:00:03 BST
file stats: LOC: 67   Methods: 2
NCLOC: 31   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ServletUtil.java 87.5% 82.4% 50% 81.5%
 1   
 /*   Generated by AspectJ version 1.0.5 */
 2   
 package org.apache.cactus.server;
 3   
 import java.net.URLDecoder;
 4   
 import org.apache.cactus.util.ChainedRuntimeException;
 5   
 
 6   
 /** 
 7   
  * All prupose utility methods for manipulating the Servlet API. 
 8   
  * 
 9   
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 10   
  * 
 11   
  * @version $Id: ServletUtil.java,v 1.2 2002/07/21 12:09:16 vmassol Exp $ 
 12   
  */
 13   
 public class ServletUtil {
 14   
   /** 
 15   
        * A substitute method for <code>HttpServletRequest.getParameter()</code>. 
 16   
        * Contrary to <code>getParameter()</code>, this method does not 
 17   
        * access the request input stream (only the query string of the url). 
 18   
        * 
 19   
        * Note: We use this method internally to retrieve Cactus parameters passed 
 20   
        * by the client side. The issue with <code>getParameter()</code> is that 
 21   
        * if you use it, then you cannot call <code>getReader()</code> or 
 22   
        * <code>getInputStream()</code> (see the Servlet spec). However, if we 
 23   
        * want to allow for testing code that uses these 2 methods (and we do !) 
 24   
        * we need to use this method to get the internal Cactus parameters. 
 25   
        * 
 26   
        * @param theQueryString the query string to parse 
 27   
        * @param theParameter the name of the parameter to locate 
 28   
        * @return the value for theParameter in theQueryString, null if 
 29   
        *         theParameter does not exist and "" if the parameter exists but 
 30   
        *         has no value defined in the query string 
 31   
        */
 32  2063
   public static String getQueryStringParameter(String theQueryString, String theParameter) {
 33  2063
     if (theQueryString == null) {
 34  0
       return ((String)(null));
 35   
     } 
 36  2063
     String value = null;
 37  2063
     int startIndex = theQueryString.indexOf(theParameter + "=");
 38  2063
     if (startIndex >= 0) {
 39  1007
       startIndex += theParameter.length() + 1;
 40  1007
       int endIndex = theQueryString.indexOf('&', startIndex);
 41  1007
       if (endIndex > startIndex) {
 42  645
         value = theQueryString.substring(startIndex, endIndex);
 43  362
       } else if (endIndex == startIndex) {
 44  4
         value = "";
 45   
       } else {
 46  358
         value = theQueryString.substring(startIndex);
 47   
       } 
 48  1007
       try {
 49  1007
         value = URLDecoder.decode(value);
 50   
       } catch (Exception e) {
 51  0
         throw new ChainedRuntimeException("Error URL decoding [" + value + "]", e);
 52   
       } 
 53   
     } 
 54  2063
     return value;
 55   
   } 
 56   
 
 57   
   /** 
 58   
    * All prupose utility methods for manipulating the Servlet API. 
 59   
    * 
 60   
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 61   
    * 
 62   
    * @version $Id: ServletUtil.java,v 1.2 2002/07/21 12:09:16 vmassol Exp $ 
 63   
    */
 64  0
   public ServletUtil() {
 65  0
     super();
 66   
   } 
 67   
 }