Package org.simpleframework.http.parse
Class CookieParser
- java.lang.Object
-
- org.simpleframework.common.parse.Parser
-
- org.simpleframework.http.parse.CookieParser
-
- All Implemented Interfaces:
java.lang.Iterable<Cookie>
public class CookieParser extends org.simpleframework.common.parse.Parser implements java.lang.Iterable<Cookie>
CookieParser is used to parse the cookie header. The cookie header is one of the headers that is used by the HTTP state management mechanism. The Cookie header is the header that is sent from the client to the server in response to a Set-Cookie header. The syntax of the Cookie header as taken from RFC 2109, HTTP State Management Mechanism.cookie = "Cookie:" cookie-version 1*((";" | ",") cookie-value) cookie-value = NAME "=" VALUE [";" path] [";" domain] cookie-version = "$Version" "=" value NAME = attr VALUE = value path = "$Path" "=" value domain = "$Domain" "=" valueThe cookie header may consist of several cookies. Each cookie can be extracted from the header by examining the it syntax of the cookie header. The syntax of the cookie header is defined in RFC 2109.Each cookie has a
$Versionattribute followed by multiple cookies. Each contains a name and a value, followed by an optional$Pathand$Domainattribute. This will parse a given cookie header and return each cookie extracted as aCookieobject.- Author:
- Niall Gallagher
-
-
Constructor Summary
Constructors Constructor Description CookieParser()Create aCookieParserthat contains no cookies.CookieParser(java.lang.String header)This is primarily a convineance constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidinit()Resets the cookie and the buffer variables for thisCookieParser.java.util.Iterator<Cookie>iterator()This is used to acquire the cookie values from the provided the provided source text.protected voidparse()This will extract the nextCookiefrom the buffer.voidreset()This is used so that the collection ofCookiescan be reiterated.protected booleanskip(java.lang.String text)This is used to skip an arbitraryStringwithin thecharbuf.-
Methods inherited from class org.simpleframework.common.parse.Parser
digit, ensureCapacity, parse, space, toLower
-
-
-
-
Constructor Detail
-
CookieParser
public CookieParser()
Create aCookieParserthat contains no cookies. the instance will returnfalsefor thehasNextmethod. cookies may be parsed using this instance by using theparsemethod.
-
CookieParser
public CookieParser(java.lang.String header)
This is primarily a convineance constructor. This will parse theStringgiven to extract the cookies. This could be achived by calling the default no-arg constructor and then using the instance to invoke theparsemethod on thatString.- Parameters:
header- aStringcontaining a cookie value
-
-
Method Detail
-
init
protected void init()
Resets the cookie and the buffer variables for thisCookieParser. It is used to set the state of the parser to start parsing a new cookie.- Specified by:
initin classorg.simpleframework.common.parse.Parser
-
parse
protected void parse()
This will extract the nextCookiefrom the buffer. If all the characters in the buffer have already been examined then this method will simply do nothing. Otherwise this will parse the remainder of the buffer and (if it follows RFC 2109) produce aCookie.- Specified by:
parsein classorg.simpleframework.common.parse.Parser
-
skip
protected boolean skip(java.lang.String text)
This is used to skip an arbitraryStringwithin thecharbuf. It checks the length of theStringfirst to ensure that it will not go out of bounds. A comparison is then made with the buffers contents and theStringif the reigon in the buffer matched theStringthen the offset within the buffer is increased by theString's length so that it has effectively skipped it.This
skipmethod will ignore all of the whitespace text. This will also skip trailing spaces within the the input text and all spaces within the source text. For example if the input was the string "s omete xt" and the source was "some text to skip" then the result of a skip ignoring spaces would be "to skip" in the source string, as the trailing spaces are also eaten by this.- Overrides:
skipin classorg.simpleframework.common.parse.Parser- Parameters:
text- this is theStringvalue to be skipped- Returns:
- true if the
Stringwas skipped
-
iterator
public java.util.Iterator<Cookie> iterator()
This is used to acquire the cookie values from the provided the provided source text. This allows the cookie parser to be used within a for each loop to parse out the values of a cookie one by one so that they may be used or stored.- Specified by:
iteratorin interfacejava.lang.Iterable<Cookie>- Returns:
- this returns an iterator for extracting cookie value
-
reset
public void reset()
This is used so that the collection ofCookiescan be reiterated. This allows the collection to be reused. Theresetmethod will invoke the super classesinitmethod. This will reinitialize thisParserso the cookie will be reparsed.
-
-