org.apache.wicket.util.cookies
Class CookieUtils

java.lang.Object
  extended by org.apache.wicket.util.cookies.CookieUtils

public class CookieUtils
extends java.lang.Object

Helper class to simplify Cookie handling.

Author:
Juergen Donnerstag, Jonathan Locke

Constructor Summary
CookieUtils()
          Construct.
CookieUtils(CookieDefaults settings)
          Construct.
 
Method Summary
protected  java.lang.String getKey(FormComponent<?> component)
          This method gets used when a cookie key needs to be derived from a form component.
protected  java.lang.String getSaveKey(java.lang.String key)
          Make sure the 'key' does not contain any illegal chars.
 CookieDefaults getSettings()
           
protected  void initializeCookie(javax.servlet.http.Cookie cookie)
          Is called before the Cookie is saved.
protected  java.lang.String joinValues(java.lang.String... values)
          Join all fragments into one Cookie value
 java.lang.String load(FormComponent<?> formComponent)
          Retrieve the cookie value associated with the formComponent and load the model object with the cookie value.
 java.lang.String load(java.lang.String key)
          Retrieve the cookie value by means of its key.
 void remove(FormComponent<?> formComponent)
          Remove the cookie identified by the form component
 void remove(java.lang.String key)
          Remove the cookie identified by the key
 void save(FormComponent<?> formComponent)
          Save the form components model value in a cookie
 void save(java.lang.String key, java.lang.String... values)
          Create a Cookie with key and value and save it in the browser with the next response
protected  java.lang.String[] splitValue(java.lang.String value)
          Split the loaded Cookie value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CookieUtils

public CookieUtils()
Construct.


CookieUtils

public CookieUtils(CookieDefaults settings)
Construct.

Parameters:
settings -
Method Detail

getSettings

public final CookieDefaults getSettings()
Returns:
Gets the settings for these utils

remove

public final void remove(java.lang.String key)
Remove the cookie identified by the key

Parameters:
key -

remove

public final void remove(FormComponent<?> formComponent)
Remove the cookie identified by the form component

Parameters:
formComponent -

getKey

protected java.lang.String getKey(FormComponent<?> component)
This method gets used when a cookie key needs to be derived from a form component. By default the component's page relative path is used.

Parameters:
component -
Returns:
cookie key

load

public final java.lang.String load(java.lang.String key)
Retrieve the cookie value by means of its key.

Parameters:
key -
Returns:
The cookie value associated with the key

load

public final java.lang.String load(FormComponent<?> formComponent)
Retrieve the cookie value associated with the formComponent and load the model object with the cookie value.

Parameters:
formComponent -
Returns:
The Cookie value which has also been used to set the component's model value

splitValue

protected java.lang.String[] splitValue(java.lang.String value)
Split the loaded Cookie value

Parameters:
value -
Returns:
The cookie's value split into fragments

joinValues

protected java.lang.String joinValues(java.lang.String... values)
Join all fragments into one Cookie value

Parameters:
values -
Returns:
The cookie's value splitted into its constituent parts

save

public final void save(java.lang.String key,
                       java.lang.String... values)
Create a Cookie with key and value and save it in the browser with the next response

Parameters:
key -
values -

save

public final void save(FormComponent<?> formComponent)
Save the form components model value in a cookie

Parameters:
formComponent -

getSaveKey

protected java.lang.String getSaveKey(java.lang.String key)
Make sure the 'key' does not contain any illegal chars. E.g. for cookies ':' is not allowed.

Parameters:
key - The key to be validated
Returns:
The save key

initializeCookie

protected void initializeCookie(javax.servlet.http.Cookie cookie)
Is called before the Cookie is saved. May be subclassed for different (dynamic) Cookie parameters. Static parameters can also be changed via CookieDefaults.

Parameters:
cookie -


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.