View Javadoc

1   package org.apache.turbine.util.parser;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 }