org.norther.tammi.acorn.net
Class URLEncoder

java.lang.Object
  extended by org.norther.tammi.acorn.net.URLEncoder

public abstract class URLEncoder
extends Object

A static URL encoder. It encodes strings as specified in RFC1738 Unified Resource Locators.

Unreserved characters include 'a'-'z', 'A' - 'Z', '0' - '9', '-', '.', '_', and '~' in RFC3986. All others are decoded as character triplets consisting of the character '%' followed by the two hexadecimal digits, which form the hexadecimal value of the octet.

Encoded characters that are longer than 8-bits can be decoded back to UTF strings reliably only with the UTF-8 character encoding.

The encoder uses the platform's default character encoding if nothing else is specified.

Author:
Ilkka Priha

Field Summary
static String AMPERSAND
          XML references (old WML browsers required an XML entity references, newer ones don't work with it!?) We apply the one required by the HTML DTD.
 
Constructor Summary
URLEncoder()
           
 
Method Summary
static String encode(Map map)
          Encodes a map of URL parameters using the default encoding.
static String encode(Map map, int offset, int count)
          Encodes part of a map of URL parameters using the default encoding.
static String encode(Map map, int offset, int count, String encoding)
          Encodes part of a map of URL parameters using the specified encoding.
static String encode(Map map, String encoding)
          Encodes a map of URL parameters using the specified encoding.
static String encode(String param)
          Encodes a URL parameter using the default encoding.
protected static String encode(String str, char[] chars, int offset, int count, String encoding, boolean ispath, StringBuilder buffer)
          Encodes a URL parameter.
static String encode(String param, String encoding)
          Encodes a URL parameter using the specified encoding.
static String encodePath(String path)
          Encodes a URL path using the default encoding.
static String encodePath(String path, String encoding)
          Encodes a URL path using the specified encoding.
static String encodePathInfo(Map map)
          Encodes a map of URL path parameters using the default encoding.
static String encodePathInfo(Map map, int offset, int count)
          Encodes part of a map of URL path parameters using the default encoding.
static String encodePathInfo(Map map, int offset, int count, String encoding)
          Encodes part of a map of URL path parameters using the specified encoding.
static String encodePathInfo(Map map, String encoding)
          Encodes a map of URL path parameters using the specified encoding.
static String encodePathInfo(String name, String value)
          Encodes a URL path parameter using the default encoding.
static String encodePathInfo(String name, String[] value)
          Encodes URL path parameters using the default encoding.
static String encodePathInfo(String name, String[] value, String encoding)
          Encodes a URL path parameters using the specified encoding.
static String encodePathInfo(String name, String value, String encoding)
          Encodes a URL path parameter using the specified encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AMPERSAND

public static final String AMPERSAND
XML references (old WML browsers required an XML entity references, newer ones don't work with it!?) We apply the one required by the HTML DTD.

See Also:
Constant Field Values
Constructor Detail

URLEncoder

public URLEncoder()
Method Detail

encode

public static final String encode(String param)
Encodes a URL parameter using the default encoding.

Parameters:
param - a URL parameter.
Returns:
the encoded parameter.

encode

public static final String encode(String param,
                                  String encoding)
Encodes a URL parameter using the specified encoding.

Parameters:
param - a URL parameter.
encoding - the encoding.
Returns:
the encoded parameter.

encode

public static final String encode(Map map)
Encodes a map of URL parameters using the default encoding. The keys in the map must be strings and values either strings or string arrays.

Parameters:
map - a map of URL parameters.
Returns:
encoded parameters without the leading '?' or null.

encode

public static final String encode(Map map,
                                  String encoding)
Encodes a map of URL parameters using the specified encoding. The keys in the map must be strings and values either strings or string arrays.

Parameters:
map - a map of URL parameters.
encoding - the encoding.
Returns:
encoded parameters without the leading '?' or an empty string.

encode

public static final String encode(Map map,
                                  int offset,
                                  int count)
Encodes part of a map of URL parameters using the default encoding. The keys in the map must be strings and values either strings or string arrays.

Parameters:
map - a map of URL parameters.
offset - the initial offset.
count - the number of keys to process (-1 = all).
Returns:
encoded parameters without the leading '?' or null.

encode

public static final String encode(Map map,
                                  int offset,
                                  int count,
                                  String encoding)
Encodes part of a map of URL parameters using the specified encoding. The keys in the map must be strings and values either strings or string arrays.

Parameters:
map - a map of URL parameters.
offset - the initial offset.
count - the number keys to process (-1 = all).
encoding - the encoding.
Returns:
encoded parameters without the leading '?' or an empty string.

encodePath

public static final String encodePath(String path)
Encodes a URL path using the default encoding.

Parameters:
path - a URL path.
Returns:
the encoded path.

encodePath

public static final String encodePath(String path,
                                      String encoding)
Encodes a URL path using the specified encoding.

Parameters:
path - a URL path.
encoding - the encoding.
Returns:
the encoded path.

encodePathInfo

public static final String encodePathInfo(String name,
                                          String value)
Encodes a URL path parameter using the default encoding.

Parameters:
name - the parameter name.
value - the parameter value.
Returns:
the encoded path parameter.

encodePathInfo

public static final String encodePathInfo(String name,
                                          String value,
                                          String encoding)
Encodes a URL path parameter using the specified encoding.

Parameters:
name - the parameter name.
value - the parameter value.
encoding - the encoding.
Returns:
the encoded path parameter.

encodePathInfo

public static final String encodePathInfo(String name,
                                          String[] value)
Encodes URL path parameters using the default encoding.

Parameters:
name - the parameter name.
value - the parameter values.
Returns:
the encoded path parameter.

encodePathInfo

public static final String encodePathInfo(String name,
                                          String[] value,
                                          String encoding)
Encodes a URL path parameters using the specified encoding.

Parameters:
name - the parameter name.
value - the parameter values.
encoding - the encoding.
Returns:
the encoded path parameter.

encodePathInfo

public static final String encodePathInfo(Map map)
Encodes a map of URL path parameters using the default encoding. The keys in the map must be strings and values either strings or string arrays.

Parameters:
map - a map of path components.
Returns:
the encoded path with the leading '/' or null.

encodePathInfo

public static final String encodePathInfo(Map map,
                                          String encoding)
Encodes a map of URL path parameters using the specified encoding. The keys in the map must be strings and values either strings or string arrays.

Parameters:
map - a map of path components.
encoding - the encoding.
Returns:
the encoded path with the leading '/' or null.

encodePathInfo

public static final String encodePathInfo(Map map,
                                          int offset,
                                          int count)
Encodes part of a map of URL path parameters using the default encoding. The keys in the map must be strings and values either strings or string arrays.

Parameters:
map - a map of path components.
offset - the initial offset.
count - the number keys to process (-1 = all).
Returns:
the encoded path with the leading '/' or null.

encodePathInfo

public static final String encodePathInfo(Map map,
                                          int offset,
                                          int count,
                                          String encoding)
Encodes part of a map of URL path parameters using the specified encoding. The keys in the map must be strings and values either strings or string arrays.

Parameters:
map - a map of path components.
offset - the initial offset.
count - the number keys to process (-1 = all).
encoding - the encoding.
Returns:
the encoded path with the leading '/' or null.

encode

protected static final String encode(String str,
                                     char[] chars,
                                     int offset,
                                     int count,
                                     String encoding,
                                     boolean ispath,
                                     StringBuilder buffer)
Encodes a URL parameter.

Parameters:
str - a URL parameter as a string.
chars - a URL parameter as a char array.
offset - the start offset in the array.
count - the number of characters to decode.
encoding - the encoding.
ispath - true for path parameters.
buffer - an optional temporary buffer.
Returns:
the encoded parameter.


Copyright © 2004 The Norther Organization. All rights reserved.