CubeTwister 2.0alpha142 2012-02-11

ch.randelshofer.util
Class Cookies

java.lang.Object
  extended by ch.randelshofer.util.Cookies

public class Cookies
extends java.lang.Object

Usefull methods for cookies.

This class uses JSObject to access cookies of the browser through the Java-to-Javascript communication. This way the applet does not need to be signed. The applet tag must include a MAYSCRIPT attribute though.

For more information about JSObjbect see. http://java.sun.com/javase/6/docs/technotes/guides/plugin/developer_guide/java_js.html#jsobject

Version:
1.0 2009-04-11 Created.
Author:
Werner Randelshofer

Method Summary
static java.lang.String getCookie(java.applet.Applet applet, java.lang.String name, java.lang.String defaultValue)
          Gets the specified cookie.
static java.lang.String getEncodedCookie(java.applet.Applet applet)
          Gets the raw cookie string from the HTML document which contains the applet.
static void putCookie(java.applet.Applet applet, java.lang.String name, java.lang.String value, java.util.Date expires)
          Puts the specified cookie value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getEncodedCookie

public static java.lang.String getEncodedCookie(java.applet.Applet applet)
Gets the raw cookie string from the HTML document which contains the applet.

Parameters:
applet -
Returns:
All cookies as key, value pairs.

getCookie

public static java.lang.String getCookie(java.applet.Applet applet,
                                         java.lang.String name,
                                         java.lang.String defaultValue)
Gets the specified cookie.

Parameters:
applet - the applet
name - the name of the cookie
defaultValue - the default value is returned if the cookie does not exist.
Returns:
The value of the specified cookie or the default value.

putCookie

public static void putCookie(java.applet.Applet applet,
                             java.lang.String name,
                             java.lang.String value,
                             java.util.Date expires)
Puts the specified cookie value.

Parameters:
applet - the applet
name - the name of the cookie
value - the value of the cooke
expires - the expiration date, specify null, for a session cookie.

(c) Werner Randelshofer.
All rights reserved.