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