public abstract class ListParser<T> extends Parser
ListParser
is used to extract a comma separated
list of HTTP header values. This will extract values without
any leading or trailing spaces, which enables the values to be
used. Listing the values that appear in the header also requires
that the values are ordered. This orders the values using the
values that appear with any quality parameter associated with it.
The quality value is a special parameter that often found in a
comma separated value list to specify the client preference.
image/gif, image/jpeg, text/html image/gif;q=1.0, image/jpeg;q=0.8, image/png; q=1.0,*;q=0.1 gzip;q=1.0, identity; q=0.5, *;q=0The above lists taken from RFC 2616 provides an example of the common form comma separated values take. The first illustrates a simple comma delimited list, here the ordering of values is determined from left to right. The second and third list have quality values associated with them, these are used to specify a preference and thus order.
Each value within a list has an implicit quality value of 1.0.
If the value is explicitly set with a the "q" parameter, then
the values can range from 1.0 to 0.001. This parser ensures
that the order of values returned from the list
method adheres to the optional quality parameters and ensures
that the quality parameters a removed from the resulting text.
Constructor and Description |
---|
ListParser()
Constructor for the
ListParser . |
ListParser(List<String> list)
Constructor for the
ListParser . |
ListParser(String text)
Constructor for the
ListParser . |
Modifier and Type | Method and Description |
---|---|
protected abstract T |
create(char[] text,
int start,
int len)
This creates an value object using the range of characters
that have been parsed as an item within the list of values.
|
protected void |
init()
Initializes the parser so that tokens can be extracted from
the list.
|
List<T> |
list()
This will build an ordered list of values extracted from the
comma separated header value.
|
protected void |
parse()
This ensures that tokens are taken from the comma separated
list as long as there bytes left to be examined within the
source text.
|
void |
parse(List<String> list)
This allows multiple header values to be represented as one
single comma separated list.
|
public ListParser()
ListParser
. This creates a
parser with no initial parse data, if there are headers to
be parsed then the parse(String)
method or
parse(List)
method can be used. This will
parse a delimited list according so RFC 2616 section 4.2.public ListParser(String text)
ListParser
. This creates a
parser with the text supplied. This will parse the comma
separated list according to RFC 2616 section 2.1 and 4.2.
The tokens can be extracted using the list
method, which will also sort and trim the tokens.text
- this is the comma separated list to be parsedpublic ListParser(List<String> list)
ListParser
. This creates a
parser with the text supplied. This will parse the comma
separated list according to RFC 2616 section 2.1 and 4.2.
The tokens can be extracted using the list
method, which will also sort and trim the tokens.list
- a list of comma separated lists to be parsedpublic void parse(List<String> list)
list
- this is a list of header values to be combinedpublic List<T> list()
protected void parse()
protected void init()
One thing that should be noted is that this will not empty the priority queue on each string parsed. This ensures that if there are multiple strings they can be parsed quickly and also contribute to the final result.
protected abstract T create(char[] text, int start, int len)
text
- this is the text buffer to acquire the value fromstart
- the offset within the array to take characterslen
- this is the number of characters within the tokenCopyright © 2022. All rights reserved.