Package org.apache.tapestry5
Class CookieBuilder
- java.lang.Object
-
- org.apache.tapestry5.CookieBuilder
-
public abstract class CookieBuilder extends java.lang.Object
A fluent API to create and write cookies. Used by theCookiesservice.- Since:
- 5.4
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Stringcommentprotected java.lang.Stringdomainprotected java.lang.BooleanhttpOnlyprotected java.lang.IntegermaxAgeprotected java.lang.Stringnameprotected java.lang.Stringpathprotected java.lang.Booleansecureprotected java.lang.Stringvalueprotected intversion
-
Constructor Summary
Constructors Modifier Constructor Description protectedCookieBuilder(java.lang.String name, java.lang.String value)Initialize a new CookieBuilder
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voiddelete()Deletes the cookie.CookieBuildersetComment(java.lang.String comment)Comments are not supported by version 0 (the default) cookiesCookieBuildersetDomain(java.lang.String domain)Set the domain for the cookie to be created.CookieBuildersetHttpOnly(boolean httpOnly)Set the cookie's httpOnly mode.CookieBuildersetMaxAge(int maxAge)Set how long the cookie should live.CookieBuildersetMaxAge(java.time.Duration maxAge)Set how long the cookie should live.CookieBuildersetPath(java.lang.String path)Set the path for the cookie to be created.CookieBuildersetSecure(boolean secure)Set the cookie's secure mode.CookieBuildersetVersion(int version)Version 0 complies with the original Netscape cookie specification.abstract voidwrite()Sets defaults and writes the cookie to the client.
-
-
-
Field Detail
-
name
protected final java.lang.String name
-
value
protected final java.lang.String value
-
path
protected java.lang.String path
-
domain
protected java.lang.String domain
-
maxAge
protected java.lang.Integer maxAge
-
secure
protected java.lang.Boolean secure
-
httpOnly
protected java.lang.Boolean httpOnly
-
version
protected int version
-
comment
protected java.lang.String comment
-
-
Constructor Detail
-
CookieBuilder
protected CookieBuilder(java.lang.String name, java.lang.String value)
Initialize a new CookieBuilder- Parameters:
name- the name of the resulting cookievalue- the value of the resulting cookie
-
-
Method Detail
-
setPath
public CookieBuilder setPath(java.lang.String path)
Set the path for the cookie to be created. Defaults toRequest.getContextPath().- Parameters:
path- the path for the cookie- Returns:
- the modified
CookieBuilder
-
setDomain
public CookieBuilder setDomain(java.lang.String domain)
Set the domain for the cookie to be created. Will not be set by default.- Parameters:
domain- the domain for the cookie- Returns:
- the modified
CookieBuilder
-
setMaxAge
public CookieBuilder setMaxAge(int maxAge)
Set how long the cookie should live. A value of0deletes a cookie, a value of-1deletes a cookie upon closing the browser. The default is defined by the symbolorg.apache.tapestry5.default-cookie-max-age. The factory default for this value is the equivalent of one week.- Parameters:
maxAge- the cookie's maximum age in seconds- Returns:
- the modified
CookieBuilder
-
setMaxAge
public CookieBuilder setMaxAge(java.time.Duration maxAge)
Set how long the cookie should live. A value ofjava.time.Duration.ZEROdeletes a cookie, a negative value deletes a cookie upon closing the browser. The default is defined by the symbolorg.apache.tapestry5.default-cookie-max-age. The factory default for this value is the equivalent of one week.- Parameters:
maxAge- the cookie's maximum age in seconds- Returns:
- the modified
CookieBuilder - Since:
- 5.8.3
-
setSecure
public CookieBuilder setSecure(boolean secure)
Set the cookie's secure mode. Defaults toRequest.isSecure().- Parameters:
secure- whether to send the cookie over a secure channel only- Returns:
- the modified
CookieBuilder
-
setHttpOnly
public CookieBuilder setHttpOnly(boolean httpOnly)
Set the cookie's httpOnly mode.- Parameters:
httpOnly- prevents javascript access to this cookie- Returns:
- the modified
CookieBuilder
-
setVersion
public CookieBuilder setVersion(int version)
Version 0 complies with the original Netscape cookie specification. Version 1 complies with RFC 2109 (experimental)- Parameters:
version- number- Returns:
- the modified
CookieBuilder
-
setComment
public CookieBuilder setComment(java.lang.String comment)
Comments are not supported by version 0 (the default) cookies- Parameters:
comment- for cookie- Returns:
- the modified
CookieBuilder
-
write
public abstract void write()
Sets defaults and writes the cookie to the client.
-
delete
public abstract void delete()
Deletes the cookie.
-
-