public class UrlHelper extends Object
Modifier and Type | Field and Description |
---|---|
static String |
UTF_8
The name of the UTF-8 encoding for
Charset.forName(String) . |
Constructor and Description |
---|
UrlHelper() |
Modifier and Type | Method and Description |
---|---|
static String |
appendQueryParameter(String q,
String key,
String value)
Append additional query parameters to the end of a given query string.
|
static String |
appendQueryParameterToUrl(String url,
String key,
String value)
Append additional query parameters to the end of a given URL.
|
static String |
decodeUtf8(String s)
Decodes a
application/x-www-form-urlencoded string using
UTF-8 encoding as stated in the
World Wide Web Consortium Recommendation. |
static String |
encodeUtf8(String s)
Translates a string into
application/x-www-form-urlencoded
format using UTF-8 encoding as stated in the
World Wide Web Consortium Recommendation. |
static Boolean |
getBooleanParameter(Map<String,List<String>> parameters,
String key)
Get the value of the query parameter
key and parse it
using Boolean.parseBoolean(String) if a value for this query parameter
has been found. |
static Boolean |
getBooleanParameter(String q,
String key)
Get the value of the query parameter
key and parse it
using Boolean.parseBoolean(String) if a value for this query parameter
has been found. |
static String |
getCompatibleContentDispositionAttachmentHeader(String fileName) |
static Double |
getDoubleParameter(Map<String,List<String>> parameters,
String key)
Get the value of the query parameter
key and parse it
using Double.parseDouble(String) if a value for this query parameter
has been found. |
static Double |
getDoubleParameter(String q,
String key)
Get the value of the query parameter
key and parse it
using Double.parseDouble(String) if a value for this query parameter
has been found. |
static Integer |
getIntegerParameter(Map<String,List<String>> parameters,
String key)
Get the value of the query parameter
key and parse it
using Integer.parseInt(String) if a value for this query parameter
has been found. |
static Integer |
getIntegerParameter(String q,
String key)
Get the value of the query parameter
key and parse it
using Integer.parseInt(String) if a value for this query parameter
has been found. |
static Long |
getLongParameter(Map<String,List<String>> parameters,
String key)
Get the value of the query parameter
key and parse it
using Long.parseLong(String) if a value for this query parameter
has been found. |
static Long |
getLongParameter(String q,
String key)
Get the value of the query parameter
key and parse it
using Long.parseLong(String) if a value for this query parameter
has been found. |
static String |
getStringParameter(Map<String,List<String>> parameters,
String key)
Get the first string value given in the specified map of
query parameters.
|
static String |
getStringParameter(String q,
String key)
Get the first string value given in the specified map of
query parameters.
|
static Map<String,List<String>> |
parseQuery(String q)
Parse a given query string in
application/x-www-form-urlencoded
format using UTF-8 encoding. |
static void |
parseQuery(String q,
UrlParameterConsumer consumer)
Parse a given query string in
application/x-www-form-urlencoded
format using UTF-8 encoding. |
public static final String UTF_8
Charset.forName(String)
.public static final String encodeUtf8(String s)
application/x-www-form-urlencoded
format using UTF-8 encoding as stated in the
World Wide Web Consortium Recommendation.
URLEncoder.encode(s,"UTF-8")
this function
does not throw any checked exception.s
- String
to be translated.String
.URLEncoder.encode(java.lang.String, java.lang.String)
public static final String decodeUtf8(String s)
application/x-www-form-urlencoded
string using
UTF-8 encoding as stated in the
World Wide Web Consortium Recommendation.
URLDecoder.decode(s,"UTF-8")
this function
does not throw any checked exception.s
- the String
to decode.String
URLDecoder.decode(String, String)
public static String getCompatibleContentDispositionAttachmentHeader(String fileName)
public static final String appendQueryParameterToUrl(String url, String key, String value)
url
- The base URL, which my already contain other query parameters.key
- The name of the parameter.value
- The value, which will be appended using encodeUtf8(String)
.public static final String appendQueryParameter(String q, String key, String value)
q
- The query part of an URL or URI as returned by URL.getQuery()
or URI.getQuery()
.key
- The name of the parameter.value
- The value, which will be appended using encodeUtf8(String)
.public static final Map<String,List<String>> parseQuery(String q)
application/x-www-form-urlencoded
format using UTF-8 encoding.q
- The query part of an URL or URI as returned by URL.getQuery()
or URI.getQuery()
.q==null
, the return value is also null
.getStringParameter(Map, String)
,
getDoubleParameter(Map, String)
,
getLongParameter(Map, String)
,
getIntegerParameter(Map, String)
,
getBooleanParameter(Map, String)
public static final void parseQuery(String q, UrlParameterConsumer consumer)
application/x-www-form-urlencoded
format using UTF-8 encoding.q
- The query part of an URL or URI as returned by URL.getQuery()
or URI.getQuery()
.consumer
- A callback for reporting parameters as they appear. A parameter value
may be manifold, so a parameter key may be reported multiple times.getStringParameter(String, String)
,
getDoubleParameter(String, String)
,
getLongParameter(String, String)
,
getIntegerParameter(String, String)
,
getBooleanParameter(String, String)
public static String getStringParameter(Map<String,List<String>> parameters, String key)
parameters
- A map of query parameters as returned by parseQuery(String)
.key
- The name of the parameter to query.null
,
if no such parameter is given.public static String getStringParameter(String q, String key)
parseQuery(String)
and getStringParameter(Map, String)
instead.q
- The query part of an URL or URI as returned by URL.getQuery()
or URI.getQuery()
.key
- The name of the parameter to query.null
,
if no such parameter is given.public static Double getDoubleParameter(Map<String,List<String>> parameters, String key) throws NumberFormatException
key
and parse it
using Double.parseDouble(String)
if a value for this query parameter
has been found.parameters
- A map of query parameters as returned by parseQuery(String)
.key
- The key of the double parameter to parse.null
if no query parameter with name key
is given.NumberFormatException
- If the value of the query parameter is
not a double value as per Double.parseDouble(String)
.public static Double getDoubleParameter(String q, String key) throws NumberFormatException
key
and parse it
using Double.parseDouble(String)
if a value for this query parameter
has been found.
If you a parsing multiple keys, use the more performing combination
of parseQuery(String)
and getDoubleParameter(Map, String)
instead.q
- The query part of an URL or URI as returned by URL.getQuery()
or URI.getQuery()
.key
- The key of the double parameter to parse.null
if no query parameter with name key
is given.NumberFormatException
- If the value of the query parameter is
not a double value as per Double.parseDouble(String)
.public static Long getLongParameter(Map<String,List<String>> parameters, String key) throws NumberFormatException
key
and parse it
using Long.parseLong(String)
if a value for this query parameter
has been found.parameters
- A map of query parameters as returned by parseQuery(String)
.key
- The key of the long parameter to parse.null
if no query parameter with name key
is given.NumberFormatException
- If the value of the query parameter is
not a long value as per Long.parseLong(String)
.public static Long getLongParameter(String q, String key) throws NumberFormatException
key
and parse it
using Long.parseLong(String)
if a value for this query parameter
has been found.
If you a parsing multiple keys, use the more performing combination
of parseQuery(String)
and getLongParameter(Map, String)
instead.q
- The query part of an URL or URI as returned by URL.getQuery()
or URI.getQuery()
.key
- The key of the long parameter to parse.null
if no query parameter with name key
is given.NumberFormatException
- If the value of the query parameter is
not a long value as per Long.parseLong(String)
.public static Integer getIntegerParameter(Map<String,List<String>> parameters, String key) throws NumberFormatException
key
and parse it
using Integer.parseInt(String)
if a value for this query parameter
has been found.parameters
- A map of query parameters as returned by parseQuery(String)
.key
- The key of the long parameter to parse.null
if no query parameter with name key
is given.NumberFormatException
- If the value of the query parameter is
not an integer value as per Integer.parseInt(String)
.public static Integer getIntegerParameter(String q, String key) throws NumberFormatException
key
and parse it
using Integer.parseInt(String)
if a value for this query parameter
has been found.
If you a parsing multiple keys, use the more performing combination
of parseQuery(String)
and getIntegerParameter(Map, String)
instead.q
- The query part of an URL or URI as returned by URL.getQuery()
or URI.getQuery()
.key
- The key of the long parameter to parse.null
if no query parameter with name key
is given.NumberFormatException
- If the value of the query parameter is
not an integer value as per Integer.parseInt(String)
.public static Boolean getBooleanParameter(Map<String,List<String>> parameters, String key)
key
and parse it
using Boolean.parseBoolean(String)
if a value for this query parameter
has been found.parameters
- A map of query parameters as returned by parseQuery(String)
.key
- The key of the long parameter to parse.null
if no query parameter with name key
is given.public static Boolean getBooleanParameter(String q, String key)
key
and parse it
using Boolean.parseBoolean(String)
if a value for this query parameter
has been found.
If you a parsing multiple keys, use the more performing combination
of parseQuery(String)
and getIntegerParameter(Map, String)
instead.q
- The query part of an URL or URI as returned by URL.getQuery()
or URI.getQuery()
.key
- The key of the long parameter to parse.null
if no query parameter with name key
is given.Copyright © 2018 Clazzes.org. All rights reserved.