com.isti.util.gui
Class CookieAccess

java.lang.Object
  extended by com.isti.util.gui.CookieAccess

public class CookieAccess
extends java.lang.Object

Class CookieAccess contains utility methods for writing, reading and deleting browser cookies. Because of write-access limitations in Sun's browser plug-in, the following JavaScript code may be needed in the launching HTML document when using the plug-in for Java support:

    <SCRIPT LANGUAGE="JavaScript"><!--
        function setCookieValue(valStr)
        {
          document.cookie = valStr;
        }
    //--></SCRIPT>
 


Field Summary
protected  JSObject browserObj
           
protected  boolean DEBUG_FLAG
           
protected  JSObject documentObj
           
 
Constructor Summary
CookieAccess(java.applet.Applet appletObj)
          Constructs a cookie-access object.
 
Method Summary
static java.lang.String decodeString(java.lang.String sourceStr)
          Decodes the given string such that all occurrences of characters that are not letters, digits or the underscore character ('_') are changed back from their "%##" codes.
static java.lang.String encodeString(java.lang.String sourceStr)
          Encodes the given string such that all occurrences of characters that are not letters, digits or the underscore character ('_') are changed to "%##" codes.
 java.lang.String getAllRawCookies()
          Returns all the cookies, or null if an error occurs.
 java.lang.String getCookie(java.lang.String nameStr)
          Reads the data from the given cookie and decodes it out from plain ASCII format (decodes "%##" sequences into characters).
 java.lang.String getRawCookie(java.lang.String nameStr)
          Returns the cookie, or null if an error occurs.
static boolean isHexDigit(char ch)
          Returns true if the given character qualifies as a hexidecimal digit.
 java.lang.String removeCookie(java.lang.String name)
          Removes the cookie by setting its expiration date in the past.
 java.lang.String removeRawCookie(java.lang.String name)
          Removes the cookie by setting its expiration date in the past.
 boolean setCookie(java.lang.String nameStr, java.lang.String dataStr, java.util.Date expireDateObj)
          Encodes the name and data into plain ASCII format (using "%##" sequences) and sets the cookie data value and expiration date.
 boolean setCookie(java.lang.String nameStr, java.lang.String dataStr, java.util.Date expireDateObj, boolean verifyFlag)
          Encodes the name and data into plain ASCII format (using "%##" sequences) and sets the cookie data value and expiration date.
 boolean setRawCookie(java.lang.String nameStr, java.lang.String dataStr, java.util.Date expireDateObj)
          Sets the cookie to the given data value and expiration date.
 boolean setRawCookie(java.lang.String nameStr, java.lang.String dataStr, java.util.Date expireDateObj, boolean verifyFlag)
          Sets the cookie to the given data value and expiration date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG_FLAG

protected final boolean DEBUG_FLAG
See Also:
Constant Field Values

browserObj

protected final JSObject browserObj

documentObj

protected final JSObject documentObj
Constructor Detail

CookieAccess

public CookieAccess(java.applet.Applet appletObj)
Constructs a cookie-access object.

Parameters:
appletObj - applet object
Method Detail

setCookie

public boolean setCookie(java.lang.String nameStr,
                         java.lang.String dataStr,
                         java.util.Date expireDateObj,
                         boolean verifyFlag)
Encodes the name and data into plain ASCII format (using "%##" sequences) and sets the cookie data value and expiration date. The name and data strings may include any characters, including control codes.

Parameters:
nameStr - the name for the cookie.
dataStr - the data to save.
expireDateObj - the expiration date for the cookie, or null for current-session-only cookie.
verifyFlag - if true then the contents of the cookie are read back for verification with true returned if OK, false if mismatch.
Returns:
true if no errors were detected.

setCookie

public boolean setCookie(java.lang.String nameStr,
                         java.lang.String dataStr,
                         java.util.Date expireDateObj)
Encodes the name and data into plain ASCII format (using "%##" sequences) and sets the cookie data value and expiration date. The name and data strings may include any characters, including control codes. No read-back verification is performed.

Parameters:
nameStr - the name for the cookie.
dataStr - the data to save.
expireDateObj - the expiration date for the cookie, or null for current-session-only cookie.
Returns:
true if no errors were detected.

getCookie

public java.lang.String getCookie(java.lang.String nameStr)
Reads the data from the given cookie and decodes it out from plain ASCII format (decodes "%##" sequences into characters). The returned data string may include any characters, including control codes.

Parameters:
nameStr - the name of the cookie to be fetched, which is encoded into plain ASCII format (using "%##" sequences).
Returns:
The decoded data string, or null if an error occurs.

removeCookie

public java.lang.String removeCookie(java.lang.String name)
Removes the cookie by setting its expiration date in the past.

Parameters:
name - the name of the cookie to be removed, which is encoded into plain ASCII format (using "%##" sequences).
Returns:
the contents of the removed cookie, or null if the given cookie name could not be found or if an error was detected.

setRawCookie

public boolean setRawCookie(java.lang.String nameStr,
                            java.lang.String dataStr,
                            java.util.Date expireDateObj,
                            boolean verifyFlag)
Sets the cookie to the given data value and expiration date. No encoding of the name or data is performed.

Parameters:
nameStr - the name for the cookie.
dataStr - the data to save.
expireDateObj - the expiration date for the cookie, or null for current-session-only cookie.
verifyFlag - if true then the contents of the cookie are read back for verification with true returned if OK, false if mismatch.
Returns:
true if no errors were detected.

setRawCookie

public boolean setRawCookie(java.lang.String nameStr,
                            java.lang.String dataStr,
                            java.util.Date expireDateObj)
Sets the cookie to the given data value and expiration date. No encoding of the data value is performed and no read-back verification is performed.

Parameters:
nameStr - the name for the cookie.
dataStr - the data to save.
expireDateObj - the expiration date for the cookie, or null for current-session-only cookie.
Returns:
true if no errors were detected.

getRawCookie

public java.lang.String getRawCookie(java.lang.String nameStr)
Returns the cookie, or null if an error occurs. No decoding of the received data value is performed.

Parameters:
nameStr - the name of the cookie to be removed (no encoding is done to the name).
Returns:
the cookie or null if an error occurs.

getAllRawCookies

public java.lang.String getAllRawCookies()
Returns all the cookies, or null if an error occurs. No decoding of the received data is performed.

Returns:
all the cookies or null if an error occurs.

removeRawCookie

public java.lang.String removeRawCookie(java.lang.String name)
Removes the cookie by setting its expiration date in the past.

Parameters:
name - the name of the cookie to be removed (no encoding is done to the name).
Returns:
the contents of the removed cookie, or null if the given cookie name could not be found or if an error was detected.

encodeString

public static java.lang.String encodeString(java.lang.String sourceStr)
Encodes the given string such that all occurrences of characters that are not letters, digits or the underscore character ('_') are changed to "%##" codes.

Parameters:
sourceStr - source string
Returns:
A new encoded String.

decodeString

public static java.lang.String decodeString(java.lang.String sourceStr)
Decodes the given string such that all occurrences of characters that are not letters, digits or the underscore character ('_') are changed back from their "%##" codes.

Parameters:
sourceStr - source string
Returns:
A new decoded String.

isHexDigit

public static boolean isHexDigit(char ch)
Returns true if the given character qualifies as a hexidecimal digit.

Parameters:
ch - character
Returns:
true if the given character qualifies as a hexidecimal digit.