org.norther.tammi.acorn.net
Class URLDecoder

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

public abstract class URLDecoder
extends Object

A static URL decoder. It decodes strings as specified in RFC1738 Unified Resource Locators.

Unreserved characters include 'a'-'z', 'A' - 'Z', '0' - '9', '-', '_', '.', '*', '!', '~', ''', '(' and ')' in RFC2396. 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 decoder uses the platforms's default character encoding if nothing else is specified.

Author:
Ilkka Priha

Field Summary
static String FILE_PROTOCOL
          The file protocol.
static String FILE_PROTOCOL_PREFIX
          The file protocol prefix.
static String HTTP_PROTOCOL
          The http protocol.
static String HTTP_PROTOCOL_PREFIX
          The http protocol prefix.
 
Constructor Summary
URLDecoder()
           
 
Method Summary
static String canonicalizePath(String path)
          Canonicalizes a URI path using the default encoding.
static String canonicalizePath(String path, String encoding)
          Canonicalizes a URI path using the given encoding.
protected static String decode(byte[] bytes, int offset, int count, boolean isPath, String encoding)
          Decodes a URL component given as a byte array.
static Map decode(InputStream input)
          Decodes the input stream following the application/x-www-form-urlencoded specification and using the default encoding.
static void decode(InputStream input, Map params)
          Decodes the input stream following the application/x-www-form-urlencoded specification and using the default encoding.
static Map decode(InputStream input, String encoding)
          Decodes the input stream following the application/x-www-form-urlencoded specification and using the given encoding.
static void decode(InputStream in, String encoding, Map params)
          Decodes the input stream following the application/x-www-form-urlencoded specification and using the given encoding.
static String decode(String param)
          Decodes a URL parameter using the default encoding.
static String decode(String param, String encoding)
          Decodes a URL parameter using the given encoding.
static File decodeFileURL(URL url)
          Decodes a file from the specified URL using the default encoding.
static File decodeFileURL(URL url, String encoding)
          Decodes a file from the specified URL using the given encoding.
static String decodePath(String path)
          Decodes a URL path using the default encoding.
static String decodePath(String path, String encoding)
          Decodes a URL path using the given encoding.
static String normalizePath(String path)
          Returns a context-relative path that represents the canonical version of the specified path after ".." and "." elements are resolved out.
static void parsePathInfo(String path, Map params, int start, Map offsets)
          Parses URL path parameters.
static String translatePath(String path)
          Translates a virtual path into a real one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_PROTOCOL

public static final String HTTP_PROTOCOL
The http protocol.

See Also:
Constant Field Values

FILE_PROTOCOL

public static final String FILE_PROTOCOL
The file protocol.

See Also:
Constant Field Values

FILE_PROTOCOL_PREFIX

public static final String FILE_PROTOCOL_PREFIX
The file protocol prefix.

See Also:
Constant Field Values

HTTP_PROTOCOL_PREFIX

public static final String HTTP_PROTOCOL_PREFIX
The http protocol prefix.

See Also:
Constant Field Values
Constructor Detail

URLDecoder

public URLDecoder()
Method Detail

decode

public static final String decode(String param)
Decodes a URL parameter using the default encoding.

Parameters:
param - a URL parameter.
Returns:
the decoded parameter or an empty string.

decode

public static final String decode(String param,
                                  String encoding)
Decodes a URL parameter using the given encoding.

Parameters:
param - a URL parameter.
encoding - the encoding.
Returns:
the decoded parameter or an empty string.

decode

public static final Map decode(InputStream input)
                        throws IOException
Decodes the input stream following the application/x-www-form-urlencoded specification and using the default encoding.

Parameters:
input - the input stream.
Returns:
the bindings as a map.
Throws:
IOException - on errors.

decode

public static final void decode(InputStream input,
                                Map params)
                         throws IOException
Decodes the input stream following the application/x-www-form-urlencoded specification and using the default encoding.

Parameters:
input - the input stream.
params - a map for results.
Throws:
IOException - on errors.

decode

public static Map decode(InputStream input,
                         String encoding)
                  throws IOException
Decodes the input stream following the application/x-www-form-urlencoded specification and using the given encoding.

Parameters:
input - the input stream.
encoding - the encoding for URL encoded chars.
Returns:
the bindings as a map.
Throws:
IOException - on errors.

decode

public static void decode(InputStream in,
                          String encoding,
                          Map params)
                   throws IOException
Decodes the input stream following the application/x-www-form-urlencoded specification and using the given encoding.

Parameters:
in - the input stream.
encoding - the encoding for URL encoded chars.
params - a map for results.
Throws:
IOException - on errors.

decodeFileURL

public static final File decodeFileURL(URL url)
Decodes a file from the specified URL using the default encoding.

Parameters:
url - the file URL.
Returns:
the decoded file or null if not a file URL.

decodeFileURL

public static final File decodeFileURL(URL url,
                                       String encoding)
Decodes a file from the specified URL using the given encoding.

Parameters:
url - the file URL.
encoding - the encoding for URL encoded chars.
Returns:
the decoded file or null if not a file URL.

decodePath

public static final String decodePath(String path)
Decodes a URL path using the default encoding.

Parameters:
path - an encoded path.
Returns:
the decoded path or an empty string.

decodePath

public static final String decodePath(String path,
                                      String encoding)
Decodes a URL path using the given encoding.

Parameters:
path - an encoded path.
encoding - the encoding for URL encoded chars.
Returns:
the decoded path or an empty string.

canonicalizePath

public static final String canonicalizePath(String path)
Canonicalizes a URI path using the default encoding.

Parameters:
path - a path to canonicalize.
Returns:
the canonicalized path.

canonicalizePath

public static final String canonicalizePath(String path,
                                            String encoding)
Canonicalizes a URI path using the given encoding.

Parameters:
path - a path to canonicalize.
encoding - the encoding.
Returns:
the canonicalized path.

normalizePath

public static final String normalizePath(String path)
Returns a context-relative path that represents the canonical version of the specified path after ".." and "." elements are resolved out. If the specified path attempts to go outside the boundaries of the current context (i.e. too many ".." path elements are present), the root path is returned.

Parameters:
path - a path to be normalized.
Returns:
the normalized path.

translatePath

public static final String translatePath(String path)
Translates a virtual path into a real one.

Parameters:
path - a path to translate.
Returns:
the translated path.

parsePathInfo

public static final void parsePathInfo(String path,
                                       Map params,
                                       int start,
                                       Map offsets)
Parses URL path parameters.

Parameters:
path - the encoded path info.
params - a map for parameters.
start - the start offset.
offsets - a map for offsets.

decode

protected static final String decode(byte[] bytes,
                                     int offset,
                                     int count,
                                     boolean isPath,
                                     String encoding)
Decodes a URL component given as a byte array. The array is also used as a buffer during decoding and may be modified, but only within the given limits.

Parameters:
bytes - a URL component as a byte array.
offset - the start offset in the array.
count - the number of characters to decode.
isPath - true for path components.
encoding - the encoding.
Returns:
the decoded component or null if not changed.


Copyright © 2004 The Norther Organization. All rights reserved.