pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.service.request
Class Cookie

java.lang.Object
  extended by org.torweg.pulse.service.request.Cookie
All Implemented Interfaces:
INamed

public final class Cookie
extends java.lang.Object
implements INamed

is a small amount of information stored by the client's browser.

A Cookie may for example be used to store a users personal preferences for an application, if they need to be available without requiring the user to log in. The use of Cookies to store session data is strongly discuraged. Use the ServiceSession instead.

This class is a facade to the javax.servlet.http.Cookie implementation of the Servlet-API.

Attention: Cookies are immutable and cannot be re-added to the ServiceRequest.

Version:
$Revision: 1395 $
Author:
Thomas Weber
See Also:
Cookie, ServiceSession

Nested Class Summary
static class Cookie.ImmutableException
          an exception to be thrown upon attempts to make modifications to a Cookie which is read from the ServiceRequest.
 
Constructor Summary
protected Cookie(javax.servlet.http.Cookie c)
          used by ServiceRequest.
  Cookie(java.lang.String name, java.lang.String value, java.lang.String path)
          constructs a Cookie with a specified name, value and path according to the Netscape Cookie specification with a maximum age of -1.
  Cookie(java.lang.String name, java.lang.String value, java.lang.String path, java.lang.String domain)
          constructs a Cookie with a specifiedname, value, path and domain according to the Netscape Cookie specification with a maximum age of -1.
 
Method Summary
protected  javax.servlet.http.Cookie getCookie()
          returns the underlying cookie.
 java.lang.String getName()
          get the name of the Cookie.
 Cookie getNewCookie(java.lang.String path)
          returns a new Cookie with the same values for name and value as the current Cookie and the given path.
 Cookie getNewCookie(java.lang.String path, java.lang.String domain)
          returns a new Cookie with the same values for name and value as the current Cookie and the given path.
 java.lang.String getValue()
          get the value of the Cookie.
 void invalidate(ServiceRequest request)
          invalidates the Cookie.
 boolean isReadOnly()
          returns whether the Cookie is read-only.
 Cookie setDomain(java.lang.String domain)
          set the domain of the Cookie.
 Cookie setMaxAge(int maxAge)
          get the maximum age of the Cookie.
 void setPath(java.lang.String uri)
          sets the path of the Cookie.
 Cookie setSecure(boolean secure)
          indicate to the browser whether the Cookie shall only be sent using a secure protocol (true).
 void setSessionCookie()
          sets the Cookie to be a session-cookie.
 Cookie setValue(java.lang.String value)
          set the value of the Cookie.
 java.lang.String toString()
          returns a string representation of the cookie.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Cookie

protected Cookie(javax.servlet.http.Cookie c)
used by ServiceRequest.

Parameters:
c - the http cookie.

Cookie

public Cookie(java.lang.String name,
              java.lang.String value,
              java.lang.String path)
constructs a Cookie with a specified name, value and path according to the Netscape Cookie specification with a maximum age of -1.

If you need a Cookie that lasts longer than the current browser session, change the maximum age with setMaxAge(int).

Parameters:
name - the name of the cookie
value - the value of the cookie
path - the cookie path
See Also:
setMaxAge(int)

Cookie

public Cookie(java.lang.String name,
              java.lang.String value,
              java.lang.String path,
              java.lang.String domain)
constructs a Cookie with a specifiedname, value, path and domain according to the Netscape Cookie specification with a maximum age of -1.

If you need a Cookie that lasts longer than the current browser session, change the maximum age with setMaxAge(int).

Parameters:
name - the name of the cookie
value - the value of the cookie
path - the cookie path
domain - the cookie domain
See Also:
setMaxAge(int)
Method Detail

getNewCookie

public Cookie getNewCookie(java.lang.String path)
returns a new Cookie with the same values for name and value as the current Cookie and the given path.

Parameters:
path - the path for the new Cookie
Returns:
a new Cookie

getNewCookie

public Cookie getNewCookie(java.lang.String path,
                           java.lang.String domain)
returns a new Cookie with the same values for name and value as the current Cookie and the given path.

Parameters:
path - the path for the new Cookie
domain - the domain for the new Cookie
Returns:
a new Cookie

getName

public java.lang.String getName()
get the name of the Cookie.

Specified by:
getName in interface INamed
Returns:
the name of the Cookie

getValue

public java.lang.String getValue()
get the value of the Cookie.

Returns:
the value of the Cookie

setDomain

public Cookie setDomain(java.lang.String domain)
set the domain of the Cookie.

Parameters:
domain - the domain to be set
Returns:
this Cookie modified
See Also:
Cookie.setDomain(java.lang.String)

setPath

public void setPath(java.lang.String uri)
sets the path of the Cookie.

Parameters:
uri - the path
See Also:
Cookie.setPath(String)

setMaxAge

public Cookie setMaxAge(int maxAge)
get the maximum age of the Cookie.

Parameters:
maxAge - the maximum age to be set
Returns:
this Cookie modified
See Also:
Cookie.setMaxAge(int)

setSecure

public Cookie setSecure(boolean secure)
indicate to the browser whether the Cookie shall only be sent using a secure protocol (true).

Parameters:
secure - the security flag to be set
Returns:
this Cookie modified
See Also:
Cookie.setSecure(boolean)

setValue

public Cookie setValue(java.lang.String value)
set the value of the Cookie.

Parameters:
value - the value to be set
Returns:
this Cookie modified
See Also:
Cookie.setValue(java.lang.String)

invalidate

public void invalidate(ServiceRequest request)
invalidates the Cookie.

This is a convenience method which acutally combines setMaxAge(int) with a value of 0 (zero) and ServiceRequest.addCookie(Cookie) with this instance being the added cookie.

Parameters:
request - the current request to send the invalidation to the client

setSessionCookie

public void setSessionCookie()
sets the Cookie to be a session-cookie.

Actually this is just a more readable substitution for setMaxAge(int) with a value of -1.


getCookie

protected javax.servlet.http.Cookie getCookie()
returns the underlying cookie.

Returns:
the cookie

isReadOnly

public boolean isReadOnly()
returns whether the Cookie is read-only.

Returns:
true, if and only if the Cookie is from the underlying request and thus cannot be modified. Otherwise false.

toString

public java.lang.String toString()
returns a string representation of the cookie.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the cookie