API Overview API Index Package Overview Direct link to this page
JavaOnTracks 0.1.2
  net.jot.web.util. JOTCookiesHelper View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

/*
 * Thibaut Colar Mar 8, 2010
 */

package net.jot.web.util;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * Helps reading cookies
 * @author thibautc
 */
public class JOTCookiesHelper {
	List cookies;

	public JOTCookiesHelper(HttpServletRequest request)
	{
		cookies = Arrays.asList(request.getCookies());
	}

	/**
	 * Find the first cookie with matching name
	 * In theory there can be multiple (!= paths)
	 * @return
	 */
	public Cookie findFirstByName(String name)
	{
		for(int i = 0; i!= cookies.size(); i++)
		{
			Cookie c = (Cookie)cookies.get(i);
			if(c.getName().equals(name))
				return c;
		}
		return null;
	}

	/**
	 * Find unique cookie by name & path
	 * @return
	 */
	public Cookie findByNameAndPath(String name, String path)
	{
		for(int i = 0; i!= cookies.size(); i++)
		{
			Cookie c = (Cookie) cookies.get(i);
			if(c.getName().equals(name) && c.getPath().equals(path))
				return c;
		}
		return null;
	}

}

Generated By: JavaOnTracks Doclet 0.1.5     ©Thibaut Colar