001: package org.apache.turbine.util.parser;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: import org.apache.turbine.util.RunData;
026: import org.apache.turbine.util.uri.URI;
027:
028: /**
029: * CookieParser is an interface to a utility to to get and set values
030: * of Cookies on the Client Browser. You can use CookieParser to convert
031: * Cookie values to various types or to set Bean values with setParameters().
032: * Servlet Spec for more information on Cookies.
033: * <p>
034: * Use set() or unset() to Create or Destroy Cookies.
035: * <p>
036: * NOTE: The name= portion of a name=value pair may be converted
037: * to lowercase or uppercase when the object is initialized and when
038: * new data is added. This behaviour is determined by the url.case.folding
039: * property in TurbineResources.properties. Adding a name/value pair may
040: * overwrite existing name=value pairs if the names match:
041: *
042: * <pre>
043: * CookieParser cp = data.getCookies();
044: * cp.add("ERROR",1);
045: * cp.add("eRrOr",2);
046: * int result = cp.getInt("ERROR");
047: * </pre>
048: *
049: * In the above example, result is 2.
050: *
051: * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
052: * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
053: * @version $Id: CookieParser.java 534527 2007-05-02 16:10:59Z tv $
054: */
055: public interface CookieParser extends ValueParser {
056: int AGE_SESSION = -1;
057: int AGE_DELETE = 0;
058:
059: /**
060: * Gets the parsed RunData.
061: *
062: * @return the parsed RunData object or null.
063: * @deprecated. Don't use the Run Data object. use getRequest().
064: */
065: RunData getRunData();
066:
067: /**
068: * Gets the Request Object for this parser.
069: *
070: * @return the HttpServletRequest or null.
071: */
072: HttpServletRequest getRequest();
073:
074: /**
075: * Sets the RunData to be parsed.
076: * All previous cookies will be cleared.
077: *
078: * @param data the RunData object.
079: * @deprecated. Use setData (HttpServletRequest request, HttpServletResponse response) instead
080: */
081: void setRunData(RunData data);
082:
083: /**
084: * Sets Request and Response to be parsed.
085: *
086: * All previous cookies will be cleared.
087: *
088: * @param request The http request from the servlet
089: * @param response The http reponse from the servlet
090: */
091: void setData(HttpServletRequest request,
092: HttpServletResponse response);
093:
094: /**
095: * Get the Path where cookies will be stored
096: */
097: URI getCookiePath();
098:
099: /**
100: * Set the path for cookie storage
101: */
102: void setCookiePath(URI path);
103:
104: /**
105: * Set a cookie that will be stored on the client for
106: * the duration of the session.
107: */
108: void set(String name, String value);
109:
110: /**
111: * Set a persisten cookie on the client that will expire
112: * after a maximum age (given in seconds).
113: */
114: void set(String name, String value, int seconds_age);
115:
116: /**
117: * Remove a previously set cookie from the client machine.
118: */
119: void unset(String name);
120: }
|