public abstract class ParameterizedArgument extends CharacterSeparatedList
Generic parser for parameterized arguments.
Example:
text/xml ; charset=toto text/xml; q=0.2 gzip; q=0.2
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
argument
Current argument.
|
static char |
PARAMETER_SEP
Separator for the parameters: ';'.
|
static char |
TOKEN_SEP
Separator for the tokens: '='.
|
CR, currentString, HT, LF, separator, SP
Constructor and Description |
---|
ParameterizedArgument()
Creates a new instance of
ParameterizedArgument with the default separator character of semicolon (";"). |
Modifier and Type | Method and Description |
---|---|
java.lang.StringBuilder |
generate(java.lang.StringBuilder sb)
Appends the current argument to the
StringBuffer sb . |
java.lang.String |
getArgument()
Returns current argument.
|
protected abstract void |
initializeNbParameters(int nbParameters)
Initialize the number of parameters to read for this argument.
|
protected void |
initializeNbTokens(int nbTokens)
Initialize the number of tokens.
|
protected abstract void |
newParameter(int id,
int startKey,
int stopKey,
int startValue,
int stopValue)
Reads a new parameter.
|
protected void |
newToken(int id,
int start,
int stop)
Adds a new token to the array of tokens.
|
endParse, parse, parse
public static final char PARAMETER_SEP
Separator for the parameters: ';'.
public static final char TOKEN_SEP
Separator for the tokens: '='.
protected java.lang.String argument
Current argument.
public ParameterizedArgument()
Creates a new instance of ParameterizedArgument
with the default separator character of semicolon (";").
public java.lang.StringBuilder generate(java.lang.StringBuilder sb)
Appends the current argument to the StringBuffer
sb
.
generate
in class CharacterSeparatedList
sb
- the StringBuffer
to append the argumentStringBuffer
with the appended argument.public java.lang.String getArgument()
Returns current argument.
protected abstract void initializeNbParameters(int nbParameters)
Initialize the number of parameters to read for this argument. Subclasses should override this abstract method.
nbParameters
- the number of parametersprotected void initializeNbTokens(int nbTokens)
Initialize the number of tokens.
initializeNbTokens
in class CharacterSeparatedList
nbTokens
- the number of tokens this instance can handle.protected abstract void newParameter(int id, int startKey, int stopKey, int startValue, int stopValue)
Reads a new parameter. A key-value pair is parsed from the current string argument. The key part will be a substring from index startKey to index stopKey. The value part will be the substring from index startValue to index stopValue.
id
- id for this parameterstartKey
- the start index of searching the key substring in current argumentstopKey
- the stop index of searching the key substring in current argumentstartValue
- start index of searching the value substring in current argumentstopValue
- stop index of searching the value substring in current argumentContentType.newParameter(int, int, int, int, int)
,
QualityArgument.newParameter(int, int, int, int, int)
protected void newToken(int id, int start, int stop)
Adds a new token to the array of tokens. The search will begin from the index start to the index stop.
newToken
in class CharacterSeparatedList
id
- the ID of the tokenstart
- start index of parameter search in the current stringstop
- end index of parameter search in the current string