1 package org.apache.turbine.util.parser;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25 import org.apache.turbine.util.RunData;
26 import org.apache.turbine.util.uri.URI;
27
28 /***
29 * CookieParser is an interface to a utility to to get and set values
30 * of Cookies on the Client Browser. You can use CookieParser to convert
31 * Cookie values to various types or to set Bean values with setParameters().
32 * Servlet Spec for more information on Cookies.
33 * <p>
34 * Use set() or unset() to Create or Destroy Cookies.
35 * <p>
36 * NOTE: The name= portion of a name=value pair may be converted
37 * to lowercase or uppercase when the object is initialized and when
38 * new data is added. This behaviour is determined by the url.case.folding
39 * property in TurbineResources.properties. Adding a name/value pair may
40 * overwrite existing name=value pairs if the names match:
41 *
42 * <pre>
43 * CookieParser cp = data.getCookies();
44 * cp.add("ERROR",1);
45 * cp.add("eRrOr",2);
46 * int result = cp.getInt("ERROR");
47 * </pre>
48 *
49 * In the above example, result is 2.
50 *
51 * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
52 * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
53 * @version $Id: CookieParser.java 534527 2007-05-02 16:10:59Z tv $
54 */
55 public interface CookieParser
56 extends ValueParser
57 {
58 int AGE_SESSION = -1;
59 int AGE_DELETE = 0;
60
61 /***
62 * Gets the parsed RunData.
63 *
64 * @return the parsed RunData object or null.
65 * @deprecated. Don't use the Run Data object. use getRequest().
66 */
67 RunData getRunData();
68
69 /***
70 * Gets the Request Object for this parser.
71 *
72 * @return the HttpServletRequest or null.
73 */
74 HttpServletRequest getRequest();
75
76 /***
77 * Sets the RunData to be parsed.
78 * All previous cookies will be cleared.
79 *
80 * @param data the RunData object.
81 * @deprecated. Use setData (HttpServletRequest request, HttpServletResponse response) instead
82 */
83 void setRunData(RunData data);
84
85 /***
86 * Sets Request and Response to be parsed.
87 *
88 * All previous cookies will be cleared.
89 *
90 * @param request The http request from the servlet
91 * @param response The http reponse from the servlet
92 */
93 void setData(HttpServletRequest request,
94 HttpServletResponse response);
95
96 /***
97 * Get the Path where cookies will be stored
98 */
99 URI getCookiePath();
100
101 /***
102 * Set the path for cookie storage
103 */
104 void setCookiePath(URI path);
105
106 /***
107 * Set a cookie that will be stored on the client for
108 * the duration of the session.
109 */
110 void set(String name, String value);
111
112 /***
113 * Set a persisten cookie on the client that will expire
114 * after a maximum age (given in seconds).
115 */
116 void set(String name, String value, int seconds_age);
117
118 /***
119 * Remove a previously set cookie from the client machine.
120 */
121 void unset(String name);
122 }