| Prev Class | Next Class | Frames | No Frames |
| Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Objectgov.llnl.babel.url.cookie.Cookiepublic class Cookieextends java.lang.Objectimplements SerializableConstructor Summary | |
| |
Method Summary | |
static String |
|
static String |
|
static String |
|
boolean | |
String |
|
String |
|
Date |
|
int |
|
String |
|
String |
|
String |
|
String |
|
String |
|
String |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
String |
|
static boolean |
|
static boolean |
|
static boolean |
|
public Cookie(String name,
String value)
throws CookieCrumbleExceptionThe basic cookie constructor (or should I say cutter?).
- Parameters:
name- The cookie's name. This should be a sequence of non-special, non-whitespace characters (according to the spec.value- The cookie's value. This should be encoded as it does into a HTTP/1.1 header.
- Throws:
CookieCrumbleException- indicates that name or value is illegal.
public static String decodeValue(String value)
Unquote special characters invalue. When you take a value field from a HTTP/1.1 header, you must remove the backslash quoting to get the real value.
- Parameters:
value- a string of text.
- Returns:
- value with any
"or\characters encoded.
public static String effectiveHostname(String hostname)
Return the effective host name of a host name. Ifhostnamedoesn't have any periods in it, ".local" is appended.
- Parameters:
hostname- the original host name
- Returns:
- if
hostnamedoesn't have any periods in it, hostname with ".local" appended is returned; otherwise, hostname is return unmodified.
public static String encodeValue(String value)
Quote special characters invalue. When you're putting certain value fields into a HTTP/1.1 header, the double quote and backslash characters must be quoted with a backslash.
- Parameters:
value- a string of text.
- Returns:
- value with any
"or\characters encoded.
public String getComment()
Return the comment attribute of the cookie. Note this may benullindicating that the cookie contains no comment.
- Returns:
nullor a valid string containing the comment attribute.
public String getDomain()
Return the domain of this cookie.
- Returns:
- The domain of this cookie. If the client doesn't provide the domain, this will be
null.
public Date getExpiration()
Return the expiration date of the cookie. If the cookie has a maximum age attribute, it should have an expiration date based on the cookie's creation time and maximum age attribute.
- Returns:
nullif no maximum age setting; otherwise, the date and time that the cookie should cease to exist.
public int getMaxAge()
Return the maximum age attribute for the cookie. A negative return value indicates that the cookie has no maximum age setting. A non-negative value is the maximum age in seconds from when it was created.
- Returns:
- the maximum age attribute of the cookie or a negative value (indicates no maximum age setting). This attribute is not useful unless you know when the cookie began.
public String getName()
Return the name of the cookie.
- Returns:
- the name of the cookie
public String getPath()
Return the path attribute of the cookie.
- Returns:
- a path on a particular server.
public String getPorts()
Return the ports that the cookie is for.
- Returns:
null(means no restriction on ports) or a comma separated list of ports.
public String getUrlComment()
Return the URL comment attribute of the cookie. Note this may benullindicating that the cookie contains no URL comment.
- Returns:
nullor a valid string containing the URL comment attribute.
public String getValue()
Return the value of the cookie.
- Returns:
- value of the cookie
public String getVersion()
Return the cookie specification version number.
- Returns:
nullif the client hasn't specified the cookie specification version; otherwise a string holding the cookie spec. version.
public boolean hasExpired(long currentTime)
Check if the cookie has expired.
- Parameters:
currentTime- use this as the current time in milliseconds since January 1, 1970.
- Returns:
truemeans the cookie's expiration time has past;falsemeans the cookie has not expired.
public boolean hasValidDomain(String hostname)
Check whether the domain name can be used by a particular host.
public boolean isDiscardable()
Indicate whether the cookie should be discarded when the user agent exits.
- Returns:
truemeans that the cookie should be discarded when the user agent exits;falsemeans that the cookie should be persisted until it expires.
public boolean isPortAllowed(int port)
Returntrueiffportis allowed to send/receive this cookie.
- Parameters:
port- the port whose access should be checked.
- Returns:
truemeans thatportmay receive the cookie;falsemeansportmust not receive the cookie.
public boolean isRelevant(String hostname,
String path,
int port)Check if the cookie should be sent with a particular request.
- Parameters:
hostname- The hostname the sent or may receive the cookie.path- The filename of the request.port- The port number of the request.
- Returns:
truemeans the cookie should be sent to the server;falsemeans the cookie must not be sent to the server.
public boolean isSecure()
Indicate whether the cookie is intended for secure connections only.
- Returns:
truemeans the cookie should only be sent on a secure channel;falsemeans the cookie can be sent on secure on unsecured channels.
public void setComment(String comment)
throws CookieCrumbleExceptionChange the comment attribute of the cookie. The specification requires the comment to be UTF-8 encoded.
- Parameters:
comment- This is the cookie's comment. If the comment is coming from an incomming HTTP/1.1 header, it should be run throughdecodeValuebefore passing it into here.
- Throws:
CookieCrumbleException- indicates that the comment is not a legal value
public void setDiscardable(boolean discard)
Conditionally set the discard attribute of the cookie.
- Parameters:
discard-truewill mark the cookie to be discarded while the user agent exits;falsewill mark the cookie to be persisted by its environment.
public void setDomain(String domain)
throws CookieCrumbleExceptionSet the domain of the request. This limits which machines will be sent the cookie.
- Parameters:
domain- this should be a domain name, a hostname or .local.
- Throws:
CookieCrumbleException- indicates that the domain is not acceptable
public void setMaxAge(int maxAge,
Date created)
throws CookieCrumbleExceptionSet the maximum age and expiration date of the cookie.
- Parameters:
maxAge- a non-negative integer value indicating the maximum age in secondscreated- best estimate of when the cookie was created
- Throws:
CookieCrumbleException- indicates that maxAge or created was invalid
public void setPath(String path)
throws CookieCrumbleExceptionSet the path.
- Parameters:
path- the leading elements of a URL path that limits the scope of the cookie
- Throws:
CookieCrumbleException- indicates that the path is invalid
public void setPorts(String ports)
throws CookieCrumbleExceptionSet the ports that are allowed to get the cookie.
- Parameters:
ports- a list of ports that are allowed to send/receive the cookie.
- Throws:
CookieCrumbleException- indicates that the path is invalid
public void setSecure(boolean secure)
Conditionally set the secure attribute of the cookie.
- Parameters:
secure-truewill make the cookie require a secure channel;falsewill allow the cookie to be communicated via unsecure channels.
public void setUrlComment(String comment)
throws CookieCrumbleExceptionChange the URL comment attribute of the cookie.
- Parameters:
comment- This is the cookie's URL comment. If the comment is coming from an incomming HTTP/1.1 header, it should be run throughdecodeValuebefore passing it into here.
- Throws:
CookieCrumbleException- The URL is not valid.
public void setValue(String value)
throws CookieCrumbleExceptionChange the value of the cookie.
- Parameters:
value- This is the value of the cookie. If the value is coming from an incomming HTTP/1.1 header, it should be run throughdecodeValuebefore passing it into here.
- Throws:
CookieCrumbleException- indicates that the value is not legal
public void setVersion(String version)
Set the version of the cookie protocol.
- Parameters:
version- Set the version of the protocol used by this cookie.
public String toString()
Create a string suitable for including in a HTTP "Cookie:" header. This assumes that the version has already been inserted.
- Returns:
- a string suitable to include in a "Cookie:" header
public static boolean validPortList(String ports)
Returnstrueiff the port list is a valid list of comma separated integers.
- Returns:
truemeans that the attribute value is acceptable.
public static boolean validToken(String tok)
Check iftokis a valid token as defined by the HTTP/1.1 spec.
- Parameters:
tok- a string that may or may not be a valid token.
- Returns:
truemeanstokis a valid HTTP/1.1 token;falsemeanstokis not a valid token.
public static boolean validValue(String value)
Return true if the string is valid as a cookie attribute value. Specifically, this returns true if value satisfies the definition forTEXTin RFC 2616 (the HTTP/1.1 spec).
- Returns:
truemeans that the attribute value is acceptable.