public final class RequestQuery extends LinkedHashMap<String,String[]>
Similar in functionality to the ServletRequest.getParameter(String)
except only looks in the URL string, not parameters from
URL-Encoded FORM posts.
This can be useful in cases where you're using GET parameters on FORM POSTs, and you don't want the body of the request to be read.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
RequestQuery() |
Modifier and Type | Method and Description |
---|---|
RequestQuery |
addDefault(Map<String,Object> defaultEntries)
Adds default entries to these query parameters.
|
RequestQuery |
addDefault(String name,
Object value)
Adds a default entries to these query parameters.
|
boolean |
containsAnyKeys(String... params)
Returns
|
<T> T |
get(HttpPartParser parser,
String name,
Class<T> type)
Same as
get(String, Class) but allows you to override the part parser. |
<T> T |
get(HttpPartParser parser,
String name,
Object def,
Type type,
Type... args)
Same as
get(String, Object, Type, Type...) but allows you to override the part parser. |
<T> T |
get(HttpPartParser parser,
String name,
T def,
Class<T> type)
Same as
get(String, Object, Class) but allows you to override the part parser. |
<T> T |
get(HttpPartParser parser,
String name,
Type type,
Type... args)
Same as
get(String, Type, Type...) but allows you to override the part parser. |
<T> T |
get(String name,
Class<T> type)
Returns the specified query parameter value converted to a POJO using the
HttpPartParser registered with the resource. |
<T> T |
get(String name,
Object def,
Type type,
Type... args)
Same as
get(String, Class) except returns a default value if not found. |
<T> T |
get(String name,
T def,
Class<T> type)
Same as
get(String, Class) except returns a default value if not found. |
<T> T |
get(String name,
Type type,
Type... args)
Returns the specified query parameter value converted to a POJO using the
HttpPartParser registered with the resource. |
<T> T |
getAll(HttpPartParser parser,
String name,
Type type,
Type... args)
Same as
getAll(String, Type, Type...) but allows you to override the part parser. |
<T> T |
getAll(String name,
Class<T> c)
Same as
get(String, Class) except for use on multi-part parameters
(e.g. |
<T> T |
getAll(String name,
Type type,
Type... args)
Same as
get(String, Type, Type...) except for use on multi-part parameters
(e.g. |
boolean |
getBoolean(String name)
Same as
getString(String) but converts the value to a boolean. |
boolean |
getBoolean(String name,
boolean def)
Same as
getString(String,String) but converts the value to a boolean. |
int |
getInt(String name)
Same as
getString(String) but converts the value to an integer. |
int |
getInt(String name,
int def)
Same as
getString(String,String) but converts the value to an integer. |
SearchArgs |
getSearchArgs()
Locates the special search query arguments in the query and returns them as a
SearchArgs object. |
String |
getString(String name)
Returns a query parameter value as a string.
|
String |
getString(String name,
String def)
Same as
getString(String) but returns the specified default value if the query parameter was not
specified. |
boolean |
hasAny(String... paramNames)
Returns
|
void |
put(String name,
Object value)
Sets a request query parameter value.
|
String |
toQueryString()
Converts this object to a query string.
|
String |
toString() |
String |
toString(boolean sorted)
Converts the query parameters to a readable string.
|
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
equals, hashCode
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
public RequestQuery()
public RequestQuery addDefault(Map<String,Object> defaultEntries)
This includes the default queries defined at the resource and method levels.
defaultEntries
- The default entries.
public RequestQuery addDefault(String name, Object value)
Similar to put(String, Object)
but doesn't override existing values.
name
- The query parameter name.value
- The query parameter value.
toString()
.
public void put(String name, Object value)
This overwrites any existing value.
name
- The parameter name.value
- The parameter value.
public String getString(String name)
If multiple query parameters have the same name, this returns only the first instance.
name
- The URL parameter name.public String getString(String name, String def)
getString(String)
but returns the specified default value if the query parameter was not
specified.name
- The URL parameter name.def
- The default value.public int getInt(String name)
getString(String)
but converts the value to an integer.name
- The URL parameter name.0
if parameter not specified or has no value (e.g. public int getInt(String name, int def)
getString(String,String)
but converts the value to an integer.name
- The URL parameter name.def
- The default value.public boolean getBoolean(String name)
getString(String)
but converts the value to a boolean.name
- The URL parameter name.public boolean getBoolean(String name, boolean def)
getString(String,String)
but converts the value to a boolean.name
- The URL parameter name.def
- The default value.public <T> T get(String name, Class<T> type) throws ParseException
HttpPartParser
registered with the resource.
T
- The class type to convert the parameter value to.name
- The parameter name.type
- The class type to convert the parameter value to.ParseException
public <T> T get(HttpPartParser parser, String name, Class<T> type) throws ParseException
get(String, Class)
but allows you to override the part parser.T
- The class type to convert the parameter value to.parser
- The parser to use for parsing the string value.
name
- The parameter name.type
- The class type to convert the parameter value to.ParseException
public <T> T get(String name, T def, Class<T> type) throws ParseException
get(String, Class)
except returns a default value if not found.T
- The class type to convert the parameter value to.name
- The parameter name.def
- The default value if the parameter was not specified or is type
- The class type to convert the parameter value to.ParseException
public <T> T get(HttpPartParser parser, String name, T def, Class<T> type) throws ParseException
get(String, Object, Class)
but allows you to override the part parser.T
- The class type to convert the parameter value to.parser
- The parser to use for parsing the string value.
name
- The parameter name.def
- The default value if the parameter was not specified or is type
- The class type to convert the parameter value to.ParseException
public <T> T get(String name, Type type, Type... args) throws ParseException
HttpPartParser
registered with the resource.
Similar to get(String,Class)
but allows for complex collections of POJOs to be created.
Collections
must be followed by zero or one parameter representing the value type.
Maps
must be followed by zero or two parameters representing the key and value types.
T
- The class type to convert the parameter value to.name
- The parameter name.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
ParseException
public <T> T get(HttpPartParser parser, String name, Type type, Type... args) throws ParseException
get(String, Type, Type...)
but allows you to override the part parser.T
- The class type to convert the parameter value to.parser
- The parser to use for parsing the string value.
name
- The parameter name.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
ParseException
public <T> T get(String name, Object def, Type type, Type... args) throws ParseException
get(String, Class)
except returns a default value if not found.T
- The class type to convert the parameter value to.name
- The parameter name.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
def
- The default value if the parameter was not specified or is ParseException
public <T> T get(HttpPartParser parser, String name, Object def, Type type, Type... args) throws ParseException
get(String, Object, Type, Type...)
but allows you to override the part parser.T
- The class type to convert the parameter value to.parser
- The parser to use for parsing the string value.
name
- The parameter name.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
def
- The default value if the parameter was not specified or is ParseException
public <T> T getAll(String name, Class<T> c) throws ParseException
get(String, Class)
except for use on multi-part parameters
(e.g. This method must only be called when parsing into classes of type Collection or array.
T
- The class type to convert the parameter value to.name
- The query parameter name.c
- The class type to convert the parameter value to.ParseException
public <T> T getAll(String name, Type type, Type... args) throws ParseException
get(String, Type, Type...)
except for use on multi-part parameters
(e.g. This method must only be called when parsing into classes of type Collection or array.
T
- The class type to convert the parameter value to.name
- The query parameter name.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
ParseException
public <T> T getAll(HttpPartParser parser, String name, Type type, Type... args) throws ParseException
getAll(String, Type, Type...)
but allows you to override the part parser.T
- The class type to convert the parameter value to.parser
- The parser to use for parsing the string value.
name
- The query parameter name.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
ParseException
public boolean containsAnyKeys(String... params)
params
- The list of parameters to check for.public SearchArgs getSearchArgs()
SearchArgs
object.
The query arguments are as follows:
0
implies return all rows.
SearchArgs
object initialized with the special search query arguments.
public boolean hasAny(String... paramNames)
paramNames
- The parameter names to check for.public String toString(boolean sorted)
sorted
- Sort the query parameters by name.public String toQueryString()
Returned query string does not start with
Copyright © 2018 Apache. All rights reserved.