public class UrlQueryFilter extends Object
A simple example is as follows:
UrlQueryFilter urlFilter = new UrlQueryFilter(); String url = "http://www.xxx:port/xxxx/xxxx?name=tom&name=lily&age=20"; urlFilter.parseUrl(url);
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
UrlQueryFilter.ValueFilter |
Represents a filter used to filter out invalid characters in a query string and replace them with spaces or
underscores (_).
|
| 构造器 | 说明 |
|---|---|
UrlQueryFilter() |
A constructor used to create a
UrlQueryFilter instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
protected void |
addParams(Pair<String,String> entry) |
Adds a filtered parameter key-value pair to the internal
List and Map objects. |
void |
allowUnregisteredParameters(boolean allow) |
Sets whether to allow query of unregistered parameters.
|
boolean |
containParameter(String paramName) |
Checks whether a query parameter pair exists based on the specified key.
|
static UrlQueryFilter.ValueFilter |
filterEncodedUrl() |
Obtains a
ValueFilter that allows all possible characters in an encoded URL. |
static UrlQueryFilter.ValueFilter |
filterNulWithSpace() |
Obtains a
ValueFilter object that can replace /0 with a space. |
boolean |
getFirstPriority() |
Checks whether the value matching the first one of duplicate keys in the parameter pair has the top priority.
|
UrlQueryFilter.ValueFilter |
getParameterFilter(String name) |
Obtains the
ValueFilter of a specified parameter key. |
List<Pair<String,String>> |
getParamsListFiltered() |
Obtains the
List<Pair<String,String>> value of all query parameters in the sequence they appear in the
URL. |
Set<String> |
getParamsSetFiltered() |
Obtains the
Set<String> object that contains the keys of all query parameters. |
String |
getParamValue(String paramName) |
Obtains the value matching a specified key in the URL query parameter.
|
UrlQueryFilter.ValueFilter |
getUnregisteredParamFilter() |
Obtains the
ValueFilter that is used to filter out unregistered parameters. |
boolean |
isAllowUnregisteredParameters() |
Checks whether to allow query of unregistered parameters.
|
protected void |
parseParamPair(String name,
String value) |
Parses an escaped query parameter pair.
|
void |
parseUrl(String url) |
Parses a specified URL.
|
void |
parseUrlQuery(String query) |
Parses the specified query string of a URL.
|
void |
registerParameterFilter(String name,
UrlQueryFilter.ValueFilter filter) |
Specifies a
ValueFilter for a parameter key to filter out invalid characters of the value for this key. |
void |
setFirstPriority(boolean value) |
Sets the value priority for duplicate keys in a query parameter pair.
|
void |
setUnregisteredParamFilter(UrlQueryFilter.ValueFilter filter) |
Sets a
ValueFilter for unregistered parameter keys. |
String |
unescapeString(String str) |
Unescapes a specified string.
|
public UrlQueryFilter()
UrlQueryFilter instance.public static final UrlQueryFilter.ValueFilter filterNulWithSpace()
ValueFilter object that can replace /0 with a space.ValueFilter object.public static final UrlQueryFilter.ValueFilter filterEncodedUrl()
ValueFilter that allows all possible characters in an encoded URL.
This method is not supported by script URLs.
ValueFilter.public List<Pair<String,String>> getParamsListFiltered()
List<Pair<String,String>> value of all query parameters in the sequence they appear in the
URL.
You should call this method after the parseUrl(java.lang.String) method is executed.
List<Pair<String, String>> object, which contains all URL query parameter pairs after
filtering.public Set<String> getParamsSetFiltered()
Set<String> object that contains the keys of all query parameters.
You should call this method after the parseUrl(java.lang.String) method is executed.
The Set<String> object does not contain duplicate keys.
Set<String> object that contains the keys of all query parameters.public void setFirstPriority(boolean value)
If value is set to true, the value matching the first key has the top priority.
If value is false (default setting), the value matching the last key has the top priority.
value - Specifies whether the value matching the first key has the top priority if there are duplicate keys
in the parameter pair.public boolean getFirstPriority()
true if the value of the first key has the top priority; returns false otherwise.public String getParamValue(String paramName)
If the key does not exist, null is returned.
paramName - Indicates the key to match in the query parameter.null otherwise.public boolean containParameter(String paramName)
paramName - Indicates the key of the query parameter pair to check.true if the query parameter pair exists; returns false otherwise.public void parseUrl(String url)
This method extracts the query string in the URL and then calls parseUrlQuery(java.lang.String)
to parse the query string.
url - Indicates the URL to be parsed.NullPointerException - Throws this exception if the specific url is null.public void parseUrlQuery(String query)
If no value is assigned to the key, the key-value pair of the query parameter will be parsed
as an empty String.
query - Indicates the URL query string to be parsed.NullPointerException - Throws this exception if the specific query is null.public void registerParameterFilter(String name, UrlQueryFilter.ValueFilter filter)
ValueFilter for a parameter key to filter out invalid characters of the value for this key.name - Indicates the key of the parameter.filter - Indicates the ValueFilter to specify for the key. If the value is null, the
ValueFilter of the key that is registered will be removed.public UrlQueryFilter.ValueFilter getParameterFilter(String name)
ValueFilter of a specified parameter key.
If the parameter key is not registered, null is returned.
name - Indicates the key to obtain its ValueFilter.ValueFilter if the parameter key has been registered; returns null if the key
cannot be found.public void setUnregisteredParamFilter(UrlQueryFilter.ValueFilter filter)
ValueFilter for unregistered parameter keys.
If no ValueFilter is set but unregistered parameters are allowed,
the default ValueFilter will be used to filter out all special characters.
filter - Indicates the ValueFilter used to filter unregistered parameter values.public UrlQueryFilter.ValueFilter getUnregisteredParamFilter()
ValueFilter that is used to filter out unregistered parameters.ValueFilter.public void allowUnregisteredParameters(boolean allow)
By default, unregistered parameters cannot be used for query.
allow - Specifies whether to allow query of unregistered parameters. The value true indicates that
unregistered parameters are allowed, and false indicates the opposite.public boolean isAllowUnregisteredParameters()
By default, unregistered parameters cannot be used for query.
true if unregistered parameters are allowed; returns false otherwise.public String unescapeString(String str)
This method replaces '+' in the string with ' ' and replaces escape characters '%xx'
with the corresponding characters. Invalid escape characters will not be replaced.
str - Indicates the string to unescape.protected void parseParamPair(String name, String value)
This method can be overloaded. By default, the escaped parameter pair
uses the ValueFilter of its key to filter its value.
The filtered parameter pair is stored in the internal Map and List objects.
name - Indicates the key of the query parameter pair to parse.value - Indicates the value of the query parameter pair to parse.protected void addParams(Pair<String,String> entry)
List and Map objects.
If the value parameter passed to the setFirstPriority(boolean) method is set to true,
the value matching the first added key is used in the event of duplicate keys;
otherwise, the value matching the last added key takes effect.
entry - Indicates the parameter key-value pair to add after filtering.