Package org.apache.wicket.util.cookies
Class CookieUtils
- java.lang.Object
-
- org.apache.wicket.util.cookies.CookieUtils
-
public class CookieUtils extends java.lang.ObjectHelper class to simplify Cookie handling.- Author:
- Juergen Donnerstag, Jonathan Locke
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_SESSIONID_COOKIE_NAME
-
Constructor Summary
Constructors Constructor Description CookieUtils()Construct.CookieUtils(CookieDefaults settings)Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.servlet.http.CookiegetCookie(java.lang.String name)Gets the cookie with 'name' attached to the latest WebRequest.protected java.lang.StringgetKey(FormComponent<?> component)This method gets used when a cookie key needs to be derived from a form component.protected java.lang.StringgetSaveKey(java.lang.String key)Make sure the 'key' does not contain any illegal chars.java.lang.StringgetSessionIdCookieName(WebApplication application)Gets the name of the cookie where the session id is stored.CookieDefaultsgetSettings()protected voidinitializeCookie(javax.servlet.http.Cookie cookie)Is called before the Cookie is saved.java.lang.Stringload(java.lang.String key)Retrieve the cookie value by means of its key.java.lang.Stringload(FormComponent<?> formComponent)Retrieve the cookie value associated with the formComponent and load the model object with the cookie value.voidremove(java.lang.String key)Remove the cookie identified by the keyvoidremove(FormComponent<?> formComponent)Remove the cookie identified by the form componentvoidsave(java.lang.String name, java.lang.String value)Create a Cookie with key and value and save it in the browser with the next responsevoidsave(FormComponent<?> formComponent)Save the form components model value in a cookie
-
-
-
Field Detail
-
DEFAULT_SESSIONID_COOKIE_NAME
public static final java.lang.String DEFAULT_SESSIONID_COOKIE_NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CookieUtils
public CookieUtils()
Construct.
-
CookieUtils
public CookieUtils(CookieDefaults settings)
Construct.- Parameters:
settings- the default settings for the saved cookies
-
-
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- The cookie name
-
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- The cookie name- 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
-
save
public final void save(java.lang.String name, java.lang.String value)Create a Cookie with key and value and save it in the browser with the next response- Parameters:
name- The cookie namevalue- The cookie value
-
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
-
getCookie
public javax.servlet.http.Cookie getCookie(java.lang.String name)
Gets the cookie with 'name' attached to the latest WebRequest.- Parameters:
name- The name of the cookie to be looked up- Returns:
- Any cookies for this request
-
getSessionIdCookieName
public java.lang.String getSessionIdCookieName(WebApplication application)
Gets the name of the cookie where the session id is stored.- Parameters:
application- The current we application holding theServletContext.- Returns:
- The name set in
SessionCookieConfigor the default value 'JSESSIONID' if not set
-
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 viaCookieDefaults.- Parameters:
cookie-
-
-