org.mortbay.util

Class UrlEncoded

Implemented Interfaces:
Cloneable

public class UrlEncoded
extends MultiMap

Handles coding of MIME "x-www-form-urlencoded". This class handles the encoding and decoding for either the query string of a URL or the content of a POST HTTP request.

Notes

The hashtable either contains String single values, vectors of String or arrays of Strings. This class is only partially synchronised. In particular, simple get operations are not protected from concurrent updates.
Version:
$Id: UrlEncoded.java,v 1.24 2005/12/21 23:14:38 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
java.net.URLEncoder

Constructor Summary

UrlEncoded()
UrlEncoded(String s)
UrlEncoded(String s, String charset)
UrlEncoded(UrlEncoded url)

Method Summary

Object
clone()
void
decode(String query)
void
decode(String query, String charset)
static String
decodeString(String encoded)
Decode String with % encoding.
static String
decodeString(String encoded, String charset)
Decode String with % encoding.
static String
decodeString(String encoded, int offset, int length, String charset)
Decode String with % encoding.
static void
decodeTo(String content, MultiMap map)
static void
decodeTo(String content, MultiMap map, String charset)
Decoded parameters to Map.
static void
decodeTo(byte[] data, int offset, int length, MultiMap map, String charset)
Decoded parameters to Map.
String
encode()
Encode Hashtable with % encoding.
String
encode(String charset)
Encode Hashtable with % encoding.
String
encode(String charset, boolean equalsForNullValue)
Encode Hashtable with % encoding.
static String
encodeString(String string)
Perform URL encoding.
static String
encodeString(String string, String charset)
Perform URL encoding.

Methods inherited from class org.mortbay.util.MultiMap

add, addValues, addValues, clone, get, getString, getValue, getValues, put, putAll, putValues, putValues, removeValue, toStringArrayMap

Constructor Details

UrlEncoded

public UrlEncoded()

UrlEncoded

public UrlEncoded(String s)

UrlEncoded

public UrlEncoded(String s,
                  String charset)

UrlEncoded

public UrlEncoded(UrlEncoded url)

Method Details

clone

public Object clone()
Overrides:
clone in interface MultiMap

decode

public void decode(String query)

decode

public void decode(String query,
                   String charset)

decodeString

public static String decodeString(String encoded)
Decode String with % encoding. This method makes the assumption that the majority of calls will need no decoding and uses the 8859 encoding.

decodeString

public static String decodeString(String encoded,
                                  String charset)
Decode String with % encoding. This method makes the assumption that the majority of calls will need no decoding.

decodeString

public static String decodeString(String encoded,
                                  int offset,
                                  int length,
                                  String charset)
Decode String with % encoding. This method makes the assumption that the majority of calls will need no decoding.

decodeTo

public static void decodeTo(String content,
                            MultiMap map)

decodeTo

public static void decodeTo(String content,
                            MultiMap map,
                            String charset)
Decoded parameters to Map.
Parameters:
content - the string containing the encoded parameters

decodeTo

public static void decodeTo(byte[] data,
                            int offset,
                            int length,
                            MultiMap map,
                            String charset)
Decoded parameters to Map.
Parameters:
data - the byte[] containing the encoded parameters

encode

public String encode()
Encode Hashtable with % encoding.

encode

public String encode(String charset)
Encode Hashtable with % encoding.

encode

public String encode(String charset,
                     boolean equalsForNullValue)
Encode Hashtable with % encoding.
Parameters:
equalsForNullValue - if True, then an '=' is always used, even for parameters without a value. e.g. "blah?a=&b=&c=".

encodeString

public static String encodeString(String string)
Perform URL encoding. Assumes 8859 charset
Parameters:
string -
Returns:
encoded string.

encodeString

public static String encodeString(String string,
                                  String charset)
Perform URL encoding.
Parameters:
string -
Returns:
encoded string.

Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.