org.clazzes.util.http
Class UrlHelper

java.lang.Object
  extended by org.clazzes.util.http.UrlHelper

public class UrlHelper
extends Object

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 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

UTF_8

public static final String UTF_8
The name of the UTF-8 encoding for Charset.forName(String).

See Also:
Constant Field Values
Constructor Detail

UrlHelper

public UrlHelper()
Method Detail

encodeUtf8

public static final 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.

In contrast to URLEncoder.encode(s,"UTF-8") this function does not throw any checked exception.

Parameters:
s - String to be translated.
Returns:
the translated String.
See Also:
URLEncoder.encode(java.lang.String, java.lang.String)

decodeUtf8

public static final 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.

In contrast to URLDecoder.decode(s,"UTF-8") this function does not throw any checked exception.

Parameters:
s - the String to decode.
Returns:
the newly decoded String
See Also:
URLDecoder.decode(String, String)

appendQueryParameterToUrl

public static final String appendQueryParameterToUrl(String url,
                                                     String key,
                                                     String value)
Append additional query parameters to the end of a given URL.

Parameters:
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).
Returns:
The base URL extended by an additional query parameter.

appendQueryParameter

public static final String appendQueryParameter(String q,
                                                String key,
                                                String value)
Append additional query parameters to the end of a given query string.

Parameters:
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).
Returns:
The query extended by an additional query parameter.

parseQuery

public static final Map<String,List<String>> parseQuery(String q)
Parse a given query string in application/x-www-form-urlencoded format using UTF-8 encoding.

Parameters:
q - The query part of an URL or URI as returned by URL.getQuery() or URI.getQuery().
Returns:
A map of query parameters with their values. A parameter value may be manifold, so the value is represented by a list of strings.


Copyright © 2012. All Rights Reserved.