Package com.restfb.util
Class UrlUtils
java.lang.Object
com.restfb.util.UrlUtils
- Since:
- 1.6.10
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionextractParametersFromQueryString
(String queryString) For the givenqueryString
, extract a mapping of query string parameter names to values.For the givenurl
, extract a mapping of query string parameter names to values.static String
removeQueryParameter
(String url, String key) Remove the given key from the url query string and return the new URL as String.static String
replaceOrAddQueryParameter
(String url, String key, String value) Modify the query string in the givenurl
and return the new url as String.static String
URL-decodes a string.static String
URL-encodes a string.
-
Method Details
-
urlEncode
URL-encodes a string.Assumes
string
is inStandardCharsets.UTF_8
format.- Parameters:
string
- The string to URL-encode.- Returns:
- The URL-encoded version of the input string, or
null
ifstring
isnull
. - Throws:
IllegalStateException
- If unable to URL-encode because the JVM doesn't supportStandardCharsets.UTF_8
.
-
urlDecode
URL-decodes a string.Assumes
string
is inStandardCharsets.UTF_8
format.- Parameters:
string
- The string to URL-decode.- Returns:
- The URL-decoded version of the input string, or
null
ifstring
isnull
. - Throws:
IllegalStateException
- If unable to URL-decode because the JVM doesn't supportStandardCharsets.UTF_8
.- Since:
- 1.6.5
-
extractParametersFromQueryString
For the givenqueryString
, extract a mapping of query string parameter names to values.Example of a
queryString
isaccessToken=123&expires=345
.- Parameters:
queryString
- The URL query string from which parameters are extracted.- Returns:
- A mapping of query string parameter names to values. If
queryString
isnull
, an emptyMap
is returned. - Throws:
IllegalStateException
- If unable to URL-decode because the JVM doesn't supportStandardCharsets.UTF_8
.
-
extractParametersFromUrl
For the givenurl
, extract a mapping of query string parameter names to values.Adapted from an implementation by BalusC and dfrankow, available at http://stackoverflow.com/questions/1667278/parsing-query-strings-in-java.
- Parameters:
url
- The URL from which parameters are extracted.- Returns:
- A mapping of query string parameter names to values. If
url
isnull
, an emptyMap
is returned. - Throws:
IllegalStateException
- If unable to URL-decode because the JVM doesn't supportStandardCharsets.UTF_8
.
-
replaceOrAddQueryParameter
Modify the query string in the givenurl
and return the new url as String.The given key/value pair is added to the url. If the key is already present, it is replaced with the new value.
- Parameters:
url
- The URL which parameters should be modified.key
- the key, that should be modified or addedvalue
- the value of the key/value pair- Returns:
- the modified URL as String
-
removeQueryParameter
Remove the given key from the url query string and return the new URL as String.- Parameters:
url
- The URL from which parameters are extracted.key
- the key, that should be removed- Returns:
- the modified URL as String
-