|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.clazzes.util.http.UrlHelper
public class UrlHelper
Static helpers for manipulating URLs and URIs.
Field Summary | |
---|---|
static String |
UTF_8
The name of the UTF-8 encoding for Charset.forName(String) . |
Constructor Summary | |
---|---|
UrlHelper()
|
Method Summary | |
---|---|
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 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 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 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 String |
getStringParameter(Map<String,List<String>> parameters,
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String UTF_8
Charset.forName(String)
.
Constructor Detail |
---|
public UrlHelper()
Method Detail |
---|
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 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 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 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 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 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 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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |