Clover coverage report - Code Coverage for tapestry release 4.0-rc-2
Coverage timestamp: Sat Dec 17 2005 09:39:46 PST
file stats: LOC: 90   Methods: 7
NCLOC: 52   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CookieSourceImpl.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.services.impl;
 16   
 17    import javax.servlet.http.Cookie;
 18    import javax.servlet.http.HttpServletRequest;
 19    import javax.servlet.http.HttpServletResponse;
 20   
 21    import org.apache.tapestry.services.CookieSource;
 22   
 23    /**
 24    * Implementation of the {@link org.apache.tapestry.services.CookieSource}service interface.
 25    *
 26    * @author Howard Lewis Ship
 27    * @since 4.0
 28    */
 29    public class CookieSourceImpl implements CookieSource
 30    {
 31    private HttpServletRequest _request;
 32   
 33    private HttpServletResponse _response;
 34   
 35    private int _defaultMaxAge;
 36   
 37  126 public String readCookieValue(String name)
 38    {
 39  126 Cookie[] cookies = _request.getCookies();
 40   
 41  126 if (cookies == null)
 42  1 return null;
 43   
 44  125 for (int i = 0; i < cookies.length; i++)
 45    {
 46  12 if (cookies[i].getName().equals(name))
 47  10 return cookies[i].getValue();
 48    }
 49   
 50  115 return null;
 51    }
 52   
 53  13 public void writeCookieValue(String name, String value)
 54    {
 55  13 writeCookieValue(name, value, _defaultMaxAge);
 56    }
 57   
 58  14 public void writeCookieValue(String name, String value, int maxAge)
 59    {
 60  14 Cookie cookie = new Cookie(name, value);
 61  14 cookie.setPath(_request.getContextPath() + "/");
 62  14 cookie.setMaxAge(maxAge);
 63   
 64  14 _response.addCookie(cookie);
 65    }
 66   
 67  1 public void removeCookieValue(String name)
 68    {
 69  1 Cookie cookie = new Cookie(name, null);
 70  1 cookie.setPath(_request.getContextPath() + "/");
 71  1 cookie.setMaxAge(0);
 72   
 73  1 _response.addCookie(cookie);
 74    }
 75   
 76  45 public void setRequest(HttpServletRequest request)
 77    {
 78  45 _request = request;
 79    }
 80   
 81  42 public void setResponse(HttpServletResponse response)
 82    {
 83  42 _response = response;
 84    }
 85   
 86  41 public void setDefaultMaxAge(int defaultMaxAge)
 87    {
 88  41 _defaultMaxAge = defaultMaxAge;
 89    }
 90    }