Package ej.hoka.http.support
Class ParameterizedArgument
- java.lang.Object
-
- ej.hoka.http.support.CharacterSeparatedList
-
- ej.hoka.http.support.ParameterizedArgument
-
- Direct Known Subclasses:
ContentType,QualityArgument
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
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringargumentCurrent argument.static charPARAMETER_SEPSeparator for the parameters: ';'.static charTOKEN_SEPSeparator for the tokens: '='.-
Fields inherited from class ej.hoka.http.support.CharacterSeparatedList
CR, currentString, HT, LF, separator, SP
-
-
Constructor Summary
Constructors Constructor Description ParameterizedArgument()Creates a new instance ofParameterizedArgumentwith the default separator character of semicolon (";").
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.StringBuildergenerate(java.lang.StringBuilder sb)Appends the current argument to theStringBuffersb.java.lang.StringgetArgument()Returns current argument.protected abstract voidinitializeNbParameters(int nbParameters)Initialize the number of parameters to read for this argument.protected voidinitializeNbTokens(int nbTokens)Initialize the number of tokens.protected abstract voidnewParameter(int id, int startKey, int stopKey, int startValue, int stopValue)Reads a new parameter.protected voidnewToken(int id, int start, int stop)Adds a new token to the array of tokens.-
Methods inherited from class ej.hoka.http.support.CharacterSeparatedList
endParse, parse, parse
-
-
-
-
Field Detail
-
PARAMETER_SEP
public static final char PARAMETER_SEP
Separator for the parameters: ';'.- See Also:
- Constant Field Values
-
TOKEN_SEP
public static final char TOKEN_SEP
Separator for the tokens: '='.- See Also:
- Constant Field Values
-
argument
@Nullable protected java.lang.String argument
Current argument.
-
-
Constructor Detail
-
ParameterizedArgument
public ParameterizedArgument()
Creates a new instance ofParameterizedArgumentwith the default separator character of semicolon (";").
-
-
Method Detail
-
generate
public java.lang.StringBuilder generate(java.lang.StringBuilder sb)
Appends the current argument to theStringBuffersb.- Specified by:
generatein classCharacterSeparatedList- Parameters:
sb- theStringBufferto append the argument- Returns:
- the
StringBufferwith the appended argument.
-
getArgument
@Nullable public java.lang.String getArgument()
Returns current argument.- Returns:
- current argument
-
initializeNbParameters
protected abstract void initializeNbParameters(int nbParameters)
Initialize the number of parameters to read for this argument. Subclasses should override this abstract method.- Parameters:
nbParameters- the number of parameters
-
initializeNbTokens
protected void initializeNbTokens(int nbTokens)
Initialize the number of tokens.- Specified by:
initializeNbTokensin classCharacterSeparatedList- Parameters:
nbTokens- the number of tokens this instance can handle.
-
newParameter
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.- Parameters:
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 argument- See Also:
ContentType.newParameter(int, int, int, int, int),QualityArgument.newParameter(int, int, int, int, int)
-
newToken
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.- Specified by:
newTokenin classCharacterSeparatedList- Parameters:
id- the ID of the tokenstart- start index of parameter search in the current stringstop- end index of parameter search in the current string
-
-