Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 143   Methods: 9
NCLOC: 54   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RequestContext.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.request;
 16   
 17    import java.util.ArrayList;
 18    import java.util.Enumeration;
 19    import java.util.List;
 20   
 21    import javax.servlet.http.HttpServletRequest;
 22    import javax.servlet.http.HttpServletResponse;
 23    import javax.servlet.http.HttpSession;
 24   
 25    /**
 26    * This class encapsulates all the relevant data for one request cycle of an
 27    * {@link ApplicationServlet}. This includes:
 28    * <ul>
 29    * <li>{@link HttpServletRequest}
 30    * <li>{@link HttpServletResponse}
 31    * <li>{@link HttpSession}
 32    * </ul>
 33    * <p>
 34    * This is a limited and crippled version of the RequestContext as it was available in release 3.0,
 35    * that exists as a bridge for compatibility only. This saves developers from having to modify their
 36    * classes to have the {@link javax.servlet.http.HttpServletRequest} or (preferrably)
 37    * {@link org.apache.tapestry.web.WebRequest} injected into their pages, components, or services. It
 38    * will be removed in the next release of Tapestry.
 39    *
 40    * @author Howard Lewis Ship
 41    * @deprecated To be removed in 4.1. Use injection to gain access to the necessary objects.
 42    */
 43   
 44    public class RequestContext
 45    {
 46    private final HttpServletRequest _request;
 47   
 48    private final HttpServletResponse _response;
 49   
 50  264 public RequestContext(HttpServletRequest request, HttpServletResponse response)
 51    {
 52  264 _request = request;
 53  264 _response = response;
 54    }
 55   
 56    /**
 57    * Returns the named parameter from the {@link HttpServletRequest}.
 58    * <p>
 59    * Use {@link #getParameters(String)}for parameters that may include multiple values.
 60    */
 61   
 62  2 public String getParameter(String name)
 63    {
 64  2 return _request.getParameter(name);
 65    }
 66   
 67    /**
 68    * Convienience method for getting a {@link HttpServletRequest}attribute.
 69    *
 70    * @since 2.3
 71    */
 72   
 73  2 public Object getAttribute(String name)
 74    {
 75  2 return _request.getAttribute(name);
 76    }
 77   
 78    /**
 79    * For parameters that are, or are possibly, multi-valued, this method returns all the values as
 80    * an array of Strings.
 81    *
 82    * @see #getParameter(String)
 83    */
 84   
 85  2 public String[] getParameters(String name)
 86    {
 87  2 return _request.getParameterValues(name);
 88    }
 89   
 90  2 public String[] getParameterNames()
 91    {
 92  2 Enumeration e = _request.getParameterNames();
 93  2 List names = new ArrayList();
 94   
 95  2 while (e.hasMoreElements())
 96  4 names.add(e.nextElement());
 97   
 98  2 int count = names.size();
 99   
 100  2 String[] result = new String[count];
 101   
 102  2 return (String[]) names.toArray(result);
 103    }
 104   
 105    /**
 106    * Returns the request which initiated the current request cycle. Note that the methods
 107    * {@link #getParameter(String)}and {@link #getParameters(String)}should be used, rather than
 108    * obtaining parameters directly from the request (since the RequestContext handles the
 109    * differences between normal and multipart/form requests).
 110    */
 111   
 112  2 public HttpServletRequest getRequest()
 113    {
 114  2 return _request;
 115    }
 116   
 117  2 public HttpServletResponse getResponse()
 118    {
 119  2 return _response;
 120    }
 121   
 122    /**
 123    * Returns the {@link HttpSession}, if necessary, invoking
 124    * {@link HttpServletRequest#getSession(boolean)}. However, this method will <em>not</em>
 125    * create a session.
 126    */
 127   
 128  2 public HttpSession getSession()
 129    {
 130  2 return _request.getSession(false);
 131    }
 132   
 133    /**
 134    * Like {@link #getSession()}, but forces the creation of the {@link HttpSession}, if
 135    * necessary.
 136    */
 137   
 138  2 public HttpSession createSession()
 139    {
 140  2 return _request.getSession(true);
 141    }
 142   
 143    }