Top Description Fields Constructors Methods
org.apache.tomcat.util.http.fileupload

public Class ParameterParser

extends Object
Class Inheritance
Imports
java.io.UnsupportedEncodingException, java.util.HashMap, .Locale, .Map, org.apache.tomcat.util.http.fileupload.util.mime.MimeUtility, .RFC2231Utility

A simple parser intended to parse sequences of name/value pairs. Parameter values are expected to be enclosed in quotes if they contain unsafe characters, such as '=' characters or separators. Parameter values are optional and can be omitted.

param1 = value; param2 = "anything goes; really"; param3

Field Summary

Modifier and TypeField and Description
private char[]
chars

String to be parsed.

private int
i1

Start of a token.

private int
i2

End of a token.

private int
len

Maximum position in the string.

private boolean
lowerCaseNames

Whether names stored in the map should be converted to lower case.

private int
pos

Current position in the string.

Constructor Summary

AccessConstructor and Description
public
ParameterParser()

Default ParameterParser constructor.

Method Summary

Modifier and TypeMethod and Description
private String

Returns:

the token
getToken
(final boolean
true if quotation marks are expected, false otherwise.
quoted
)

A helper method to process the parsed token.

private boolean

Returns:

true if there are unparsed characters, false otherwise.
hasChar
()

Are there any characters left to parse?

public boolean

Returns:

true if parameter names are to be converted to lower case when name/value pairs are parsed. Otherwise returns false
isLowerCaseNames
()

Returns true if parameter names are to be converted to lower case when name/value pairs are parsed.

private boolean

Returns:

true if the character is present in the array of characters, false otherwise.
isOneOf
(final char
the character to test for presence in the array of characters
ch
,
final char[]
the array of characters to test against
charray
)

Tests if the given character is present in the array of characters.

public Map<String, String>

Returns:

a map of name/value pairs
parse
(final String
the string that contains a sequence of name/value pairs
str
,
final char[]
the name/value pairs separators
separators
)

Extracts a map of name/value pairs from the given string.

public Map<String, String>

Returns:

a map of name/value pairs
parse
(final String
the string that contains a sequence of name/value pairs
str
,
final char
the name/value pairs separator
separator
)

Extracts a map of name/value pairs from the given string.

public Map<String, String>

Returns:

a map of name/value pairs
parse
(final char[]
the array of characters that contains a sequence of name/value pairs
charArray
,
final char
the name/value pairs separator
separator
)

Extracts a map of name/value pairs from the given array of characters.

public Map<String, String>

Returns:

a map of name/value pairs
parse
(final char[]
the array of characters that contains a sequence of name/value pairs
charArray
,
final int
- the initial offset.
offset
,
final int
- the length.
length
,
final char
the name/value pairs separator
separator
)

Extracts a map of name/value pairs from the given array of characters.

private String

Returns:

the token
parseQuotedToken
(final char[]
the array of terminating characters. Any of these characters when encountered outside the quotation marks signify the end of the token
terminators
)

Parses out a token until any of the given terminators is encountered outside the quotation marks.

private String

Returns:

the token
parseToken
(final char[]
the array of terminating characters. Any of these characters when encountered signify the end of the token
terminators
)

Parses out a token until any of the given terminators is encountered.

public void
setLowerCaseNames(final boolean
true if parameter names are to be converted to lower case when name/value pairs are parsed. false otherwise.
b
)

Sets the flag if parameter names are to be converted to lower case when name/value pairs are parsed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

charsback to summary
private char[] chars

String to be parsed.

i1back to summary
private int i1

Start of a token.

i2back to summary
private int i2

End of a token.

lenback to summary
private int len

Maximum position in the string.

lowerCaseNamesback to summary
private boolean lowerCaseNames

Whether names stored in the map should be converted to lower case.

posback to summary
private int pos

Current position in the string.

Constructor Detail

ParameterParserback to summary
public ParameterParser()

Default ParameterParser constructor.

Method Detail

getTokenback to summary
private String getToken(final boolean quoted)

A helper method to process the parsed token. This method removes leading and trailing blanks as well as enclosing quotation marks, when necessary.

Parameters
quoted:boolean

true if quotation marks are expected, false otherwise.

Returns:String

the token

hasCharback to summary
private boolean hasChar()

Are there any characters left to parse?

Returns:boolean

true if there are unparsed characters, false otherwise.

isLowerCaseNamesback to summary
public boolean isLowerCaseNames()

Returns true if parameter names are to be converted to lower case when name/value pairs are parsed.

Returns:boolean

true if parameter names are to be converted to lower case when name/value pairs are parsed. Otherwise returns false

isOneOfback to summary
private boolean isOneOf(final char ch, final char[] charray)

Tests if the given character is present in the array of characters.

Parameters
ch:char

the character to test for presence in the array of characters

charray:char[]

the array of characters to test against

Returns:boolean

true if the character is present in the array of characters, false otherwise.

parseback to summary
public Map<String, String> parse(final String str, final char[] separators)

Extracts a map of name/value pairs from the given string. Names are expected to be unique. Multiple separators may be specified and the earliest found in the input string is used.

Parameters
str:String

the string that contains a sequence of name/value pairs

separators:char[]

the name/value pairs separators

Returns:Map<String, String>

a map of name/value pairs

parseback to summary
public Map<String, String> parse(final String str, final char separator)

Extracts a map of name/value pairs from the given string. Names are expected to be unique.

Parameters
str:String

the string that contains a sequence of name/value pairs

separator:char

the name/value pairs separator

Returns:Map<String, String>

a map of name/value pairs

parseback to summary
public Map<String, String> parse(final char[] charArray, final char separator)

Extracts a map of name/value pairs from the given array of characters. Names are expected to be unique.

Parameters
charArray:char[]

the array of characters that contains a sequence of name/value pairs

separator:char

the name/value pairs separator

Returns:Map<String, String>

a map of name/value pairs

parseback to summary
public Map<String, String> parse(final char[] charArray, final int offset, final int length, final char separator)

Extracts a map of name/value pairs from the given array of characters. Names are expected to be unique.

Parameters
charArray:char[]

the array of characters that contains a sequence of name/value pairs

offset:int

- the initial offset.

length:int

- the length.

separator:char

the name/value pairs separator

Returns:Map<String, String>

a map of name/value pairs

parseQuotedTokenback to summary
private String parseQuotedToken(final char[] terminators)

Parses out a token until any of the given terminators is encountered outside the quotation marks.

Parameters
terminators:char[]

the array of terminating characters. Any of these characters when encountered outside the quotation marks signify the end of the token

Returns:String

the token

parseTokenback to summary
private String parseToken(final char[] terminators)

Parses out a token until any of the given terminators is encountered.

Parameters
terminators:char[]

the array of terminating characters. Any of these characters when encountered signify the end of the token

Returns:String

the token

setLowerCaseNamesback to summary
public void setLowerCaseNames(final boolean b)

Sets the flag if parameter names are to be converted to lower case when name/value pairs are parsed.

Parameters
b:boolean

true if parameter names are to be converted to lower case when name/value pairs are parsed. false otherwise.