public class CookieGenerator
extends java.lang.Object
Can serve as base class for components that generate specific cookies, such as CookieLocaleResolver and CookieThemeResolver.
addCookie(javax.servlet.http.HttpServletResponse, java.lang.String)
,
removeCookie(javax.servlet.http.HttpServletResponse)
,
CookieLocaleResolver
,
CookieThemeResolver
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_COOKIE_PATH
Default path that cookies will be visible to: "/", i.e.
|
protected Log |
logger |
Constructor and Description |
---|
CookieGenerator() |
Modifier and Type | Method and Description |
---|---|
void |
addCookie(HttpServletResponse response,
java.lang.String cookieValue)
Add a cookie with the given value to the response,
using the cookie descriptor settings of this generator.
|
protected Cookie |
createCookie(java.lang.String cookieValue)
Create a cookie with the given value, using the cookie descriptor
settings of this generator (except for "cookieMaxAge").
|
java.lang.String |
getCookieDomain()
Return the domain for cookies created by this generator, if any.
|
java.lang.Integer |
getCookieMaxAge()
Return the maximum age for cookies created by this generator.
|
java.lang.String |
getCookieName()
Return the given name for cookies created by this generator.
|
java.lang.String |
getCookiePath()
Return the path for cookies created by this generator.
|
boolean |
isCookieHttpOnly()
Return whether the cookie is supposed to be marked with the "HttpOnly" attribute.
|
boolean |
isCookieSecure()
Return whether the cookie should only be sent using a secure protocol,
such as HTTPS (SSL).
|
void |
removeCookie(HttpServletResponse response)
Remove the cookie that this generator describes from the response.
|
void |
setCookieDomain(java.lang.String cookieDomain)
Use the given domain for cookies created by this generator.
|
void |
setCookieHttpOnly(boolean cookieHttpOnly)
Set whether the cookie is supposed to be marked with the "HttpOnly" attribute.
|
void |
setCookieMaxAge(java.lang.Integer cookieMaxAge)
Use the given maximum age (in seconds) for cookies created by this generator.
|
void |
setCookieName(java.lang.String cookieName)
Use the given name for cookies created by this generator.
|
void |
setCookiePath(java.lang.String cookiePath)
Use the given path for cookies created by this generator.
|
void |
setCookieSecure(boolean cookieSecure)
Set whether the cookie should only be sent using a secure protocol,
such as HTTPS (SSL).
|
public static final java.lang.String DEFAULT_COOKIE_PATH
protected final Log logger
public void setCookieName(java.lang.String cookieName)
Cookie.getName()
public java.lang.String getCookieName()
public void setCookieDomain(java.lang.String cookieDomain)
Cookie.setDomain(java.lang.String)
public java.lang.String getCookieDomain()
public void setCookiePath(java.lang.String cookiePath)
Cookie.setPath(java.lang.String)
public java.lang.String getCookiePath()
public void setCookieMaxAge(java.lang.Integer cookieMaxAge)
Default is no specific maximum age at all, using the Servlet container's default.
Cookie.setMaxAge(int)
public java.lang.Integer getCookieMaxAge()
public void setCookieSecure(boolean cookieSecure)
Default is "false".
Cookie.setSecure(boolean)
public boolean isCookieSecure()
public void setCookieHttpOnly(boolean cookieHttpOnly)
Default is "false".
Cookie.setHttpOnly(boolean)
public boolean isCookieHttpOnly()
public void addCookie(HttpServletResponse response, java.lang.String cookieValue)
Delegates to createCookie(java.lang.String)
for cookie creation.
response
- the HTTP response to add the cookie tocookieValue
- the value of the cookie to addsetCookieName(java.lang.String)
,
setCookieDomain(java.lang.String)
,
setCookiePath(java.lang.String)
,
setCookieMaxAge(java.lang.Integer)
public void removeCookie(HttpServletResponse response)
Delegates to createCookie(java.lang.String)
for cookie creation.
response
- the HTTP response to remove the cookie fromsetCookieName(java.lang.String)
,
setCookieDomain(java.lang.String)
,
setCookiePath(java.lang.String)
protected Cookie createCookie(java.lang.String cookieValue)
cookieValue
- the value of the cookie to cratesetCookieName(java.lang.String)
,
setCookieDomain(java.lang.String)
,
setCookiePath(java.lang.String)