org.apache.commons.httpclient.util

Class URIUtil

public class URIUtil extends Object

The URI escape and character encoding and decoding utility. It's compatible with HttpURL rather than URI.

Version: $Revision: 155418 $ $Date: 2002/03/14 15:14:01

Author: Sung-Gu

Nested Class Summary
protected static classURIUtil.Coder
The basic and internal utility for URI escape and character encoding and decoding.
Field Summary
protected static BitSetempty
Method Summary
static Stringdecode(String escaped)
Unescape and decode a given string regarded as an escaped string with the default protocol charset.
static Stringdecode(String escaped, String charset)
Unescape and decode a given string regarded as an escaped string.
static Stringencode(String unescaped, BitSet allowed)
Escape and encode a given string with allowed characters not to be escaped and the default protocol charset.
static Stringencode(String unescaped, BitSet allowed, String charset)
Escape and encode a given string with allowed characters not to be escaped and a given charset.
static StringencodeAll(String unescaped)
Get the all escaped and encoded string with the default protocl charset.
static StringencodeAll(String unescaped, String charset)
Get the all escaped and encoded string with a given charset.
static StringencodePath(String unescaped)
Escape and encode a string regarded as the path component of an URI with the default protocol charset.
static StringencodePath(String unescaped, String charset)
Escape and encode a string regarded as the path component of an URI with a given charset.
static StringencodePathQuery(String unescaped)
Escape and encode a string regarded as the path and query components of an URI with the default protocol charset.
static StringencodePathQuery(String unescaped, String charset)
Escape and encode a string regarded as the path and query components of an URI with a given charset.
static StringencodeQuery(String unescaped)
Escape and encode a string regarded as the query component of an URI with the default protocol charset.
static StringencodeQuery(String unescaped, String charset)
Escape and encode a string regarded as the query component of an URI with a given charset.
static StringencodeWithinAuthority(String unescaped)
Escape and encode a string regarded as within the authority component of an URI with the default protocol charset.
static StringencodeWithinAuthority(String unescaped, String charset)
Escape and encode a string regarded as within the authority component of an URI with a given charset.
static StringencodeWithinPath(String unescaped)
Escape and encode a string regarded as within the path component of an URI with the default protocol charset.
static StringencodeWithinPath(String unescaped, String charset)
Escape and encode a string regarded as within the path component of an URI with a given charset.
static StringencodeWithinQuery(String unescaped)
Escape and encode a string regarded as within the query component of an URI with the default protocol charset.
static StringencodeWithinQuery(String unescaped, String charset)
Escape and encode a string regarded as within the query component of an URI with a given charset.
static StringgetFromPath(String uri)
Get the path of an URI and its rest part.
static StringgetName(String uri)
Get the basename of an URI.
static StringgetPath(String uri)
Get the path of an URI.
static StringgetPathQuery(String uri)
Get the path and query of an URI.
static StringgetQuery(String uri)
Get the query of an URI.

Field Detail

empty

protected static final BitSet empty

Method Detail

decode

public static String decode(String escaped)
Unescape and decode a given string regarded as an escaped string with the default protocol charset.

Parameters: escaped a string

Returns: the unescaped string

Throws: URIException if the string cannot be decoded (invalid)

See Also: URI

decode

public static String decode(String escaped, String charset)
Unescape and decode a given string regarded as an escaped string.

Parameters: escaped a string charset the charset

Returns: the unescaped string

Throws: URIException if the charset is not supported

See Also: Coder

encode

public static String encode(String unescaped, BitSet allowed)
Escape and encode a given string with allowed characters not to be escaped and the default protocol charset.

Parameters: unescaped a string allowed allowed characters not to be escaped

Returns: the escaped string

Throws: URIException if the default protocol charset is not supported

See Also: URI

encode

public static String encode(String unescaped, BitSet allowed, String charset)
Escape and encode a given string with allowed characters not to be escaped and a given charset.

Parameters: unescaped a string allowed allowed characters not to be escaped charset the charset

Returns: the escaped string

encodeAll

public static String encodeAll(String unescaped)
Get the all escaped and encoded string with the default protocl charset. It's the same function to use encode(String unescaped, Bitset empty, URI.getDefaultProtocolCharset()).

Parameters: unescaped an unescaped string

Returns: the escaped string

Throws: URIException if the default protocol charset is not supported

See Also: URI URIUtil

encodeAll

public static String encodeAll(String unescaped, String charset)
Get the all escaped and encoded string with a given charset. It's the same function to use encode(String unescaped, Bitset empty, String charset).

Parameters: unescaped an unescaped string charset the charset

Returns: the escaped string

Throws: URIException if the charset is not supported

See Also: URIUtil

encodePath

public static String encodePath(String unescaped)
Escape and encode a string regarded as the path component of an URI with the default protocol charset.

Parameters: unescaped an unescaped string

Returns: the escaped string

Throws: URIException if the default protocol charset is not supported

See Also: URI URIUtil

encodePath

public static String encodePath(String unescaped, String charset)
Escape and encode a string regarded as the path component of an URI with a given charset.

Parameters: unescaped an unescaped string charset the charset

Returns: the escaped string

Throws: URIException if the charset is not supported

See Also: URIUtil

encodePathQuery

public static String encodePathQuery(String unescaped)
Escape and encode a string regarded as the path and query components of an URI with the default protocol charset.

Parameters: unescaped an unescaped string

Returns: the escaped string

Throws: URIException if the default protocol charset is not supported

See Also: URI URIUtil

encodePathQuery

public static String encodePathQuery(String unescaped, String charset)
Escape and encode a string regarded as the path and query components of an URI with a given charset.

Parameters: unescaped an unescaped string charset the charset

Returns: the escaped string

Throws: URIException if the charset is not supported

See Also: URIUtil

encodeQuery

public static String encodeQuery(String unescaped)
Escape and encode a string regarded as the query component of an URI with the default protocol charset. When a query string is not misunderstood the reserved special characters ("&", "=", "+", ",", and "$") within a query component, this method is recommended to use in encoding the whole query.

Parameters: unescaped an unescaped string

Returns: the escaped string

Throws: URIException if the default protocol charset is not supported

See Also: URI URIUtil

encodeQuery

public static String encodeQuery(String unescaped, String charset)
Escape and encode a string regarded as the query component of an URI with a given charset. When a query string is not misunderstood the reserved special characters ("&", "=", "+", ",", and "$") within a query component, this method is recommended to use in encoding the whole query.

Parameters: unescaped an unescaped string charset the charset

Returns: the escaped string

Throws: URIException if the charset is not supported

See Also: URIUtil

encodeWithinAuthority

public static String encodeWithinAuthority(String unescaped)
Escape and encode a string regarded as within the authority component of an URI with the default protocol charset. Within the authority component, the characters ";", ":", "@", "?", and "/" are reserved.

Parameters: unescaped an unescaped string

Returns: the escaped string

Throws: URIException if the default protocol charset is not supported

See Also: URI URIUtil

encodeWithinAuthority

public static String encodeWithinAuthority(String unescaped, String charset)
Escape and encode a string regarded as within the authority component of an URI with a given charset. Within the authority component, the characters ";", ":", "@", "?", and "/" are reserved.

Parameters: unescaped an unescaped string charset the charset

Returns: the escaped string

Throws: URIException if the charset is not supported

See Also: URIUtil

encodeWithinPath

public static String encodeWithinPath(String unescaped)
Escape and encode a string regarded as within the path component of an URI with the default protocol charset. The path may consist of a sequence of path segments separated by a single slash "/" character. Within a path segment, the characters "/", ";", "=", and "?" are reserved.

Parameters: unescaped an unescaped string

Returns: the escaped string

Throws: URIException if the default protocol charset is not supported

See Also: URI URIUtil

encodeWithinPath

public static String encodeWithinPath(String unescaped, String charset)
Escape and encode a string regarded as within the path component of an URI with a given charset. The path may consist of a sequence of path segments separated by a single slash "/" character. Within a path segment, the characters "/", ";", "=", and "?" are reserved.

Parameters: unescaped an unescaped string charset the charset

Returns: the escaped string

Throws: URIException if the charset is not supported

See Also: URIUtil

encodeWithinQuery

public static String encodeWithinQuery(String unescaped)
Escape and encode a string regarded as within the query component of an URI with the default protocol charset. When a query comprise the name and value pairs, it is used in order to encode each name and value string. The reserved special characters within a query component are being included in encoding the query.

Parameters: unescaped an unescaped string

Returns: the escaped string

Throws: URIException if the default protocol charset is not supported

See Also: URI URIUtil

encodeWithinQuery

public static String encodeWithinQuery(String unescaped, String charset)
Escape and encode a string regarded as within the query component of an URI with a given charset. When a query comprise the name and value pairs, it is used in order to encode each name and value string. The reserved special characters within a query component are being included in encoding the query.

Parameters: unescaped an unescaped string charset the charset

Returns: the escaped string

Throws: URIException if the charset is not supported

See Also: URIUtil

getFromPath

public static String getFromPath(String uri)
Get the path of an URI and its rest part.

Parameters: uri a string regarded an URI

Returns: the string from the path part

getName

public static String getName(String uri)
Get the basename of an URI. It's possibly an empty string.

Parameters: uri a string regarded an URI

Returns: the basename string; an empty string if the path ends with slash

getPath

public static String getPath(String uri)
Get the path of an URI.

Parameters: uri a string regarded an URI

Returns: the path string

getPathQuery

public static String getPathQuery(String uri)
Get the path and query of an URI.

Parameters: uri a string regarded an URI

Returns: the path and query string

getQuery

public static String getQuery(String uri)
Get the query of an URI.

Parameters: uri a string regarded an URI

Returns: the query string; null if empty or undefined

Copyright (c) 1999-2005 - Apache Software Foundation