1 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 29 public class CookieSourceImpl implements CookieSource 30 { 31 private HttpServletRequest _request; 32 33 private HttpServletResponse _response; 34 35 public String readCookieValue(String name) 36 { 37 Cookie [] cookies = _request.getCookies(); 38 39 if (cookies == null) 40 return null; 41 42 for (int i = 0; i < cookies.length; i++) 43 { 44 if (cookies[i].getName().equals(name)) 45 return cookies[i].getValue(); 46 } 47 48 return null; 49 } 50 51 public void writeCookieValue(String name, String value) 52 { 53 Cookie cookie = new Cookie (name, value); 54 cookie.setPath(_request.getContextPath()); 55 56 _response.addCookie(cookie); 57 } 58 59 public void removeCookieValue(String name) 60 { 61 Cookie cookie = new Cookie (name, null); 62 cookie.setPath(_request.getContextPath()); 63 cookie.setMaxAge(0); 64 65 _response.addCookie(cookie); 66 } 67 68 public void setRequest(HttpServletRequest request) 69 { 70 _request = request; 71 } 72 73 public void setResponse(HttpServletResponse response) 74 { 75 _response = response; 76 } 77 } | Popular Tags |