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 StringremoveQueryParameter(String url, String key) Remove the given key from the url query string and return the new URL as String.static StringreplaceOrAddQueryParameter(String url, String key, String value) Modify the query string in the givenurland return the new url as String.static StringURL-decodes a string.static StringURL-encodes a string.
-
Method Details
-
urlEncode
URL-encodes a string.Assumes
stringis inStandardCharsets.UTF_8format.- Parameters:
string- The string to URL-encode.- Returns:
- The URL-encoded version of the input string, or
nullifstringisnull. - Throws:
IllegalStateException- If unable to URL-encode because the JVM doesn't supportStandardCharsets.UTF_8.
-
urlDecode
URL-decodes a string.Assumes
stringis inStandardCharsets.UTF_8format.- Parameters:
string- The string to URL-decode.- Returns:
- The URL-decoded version of the input string, or
nullifstringisnull. - 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
queryStringisaccessToken=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
queryStringisnull, an emptyMapis 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
urlisnull, an emptyMapis returned. - Throws:
IllegalStateException- If unable to URL-decode because the JVM doesn't supportStandardCharsets.UTF_8.
-
replaceOrAddQueryParameter
Modify the query string in the givenurland 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
-