Package webwork.util
Class URLCodec
java.lang.Object
webwork.util.URLCodec
Implements the 'www-form-urlencoded' encoding scheme, also misleadingly known as URL encoding.
For more detailed information please refer to Chapter 17.13.4 'Form content types' of the HTML 4.01 Specification
This codec is meant to be a replacement for standard Java classesURLEncoder and URLDecoder on older Java platforms, as these classes in Java versions below 1.4 rely on the platform's
default charset encoding. This class was copied from Apache, with some modifications
- Author:
- Apache Software Foundation
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static byteprotected static org.apache.commons.logging.Logprotected static final BitSetBitSet of www-form-url safe characters. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]decode(byte[] bytes) Decodes an array of URL safe 7-bit characters into an array of original bytes.static ObjectDecodes a URL safe object into its original form.static StringDecodes a URL safe string into its original form using the default string charset.static StringDecodes a URL safe string into its original form using the specified encoding.static byte[]decodeUrl(byte[] bytes) Decodes an array of URL safe 7-bit characters into an array of original bytes.static byte[]encode(byte[] bytes) Encodes an array of bytes into an array of URL safe 7-bit characters.static ObjectEncodes an object into its URL safe form.static StringEncodes a string into its URL safe form using the default string charset.static StringEncodes a string into its URL safe form using the specified string charset.static byte[]Encodes an array of bytes into an array of URL safe 7-bit characters.
-
Field Details
-
log
protected static org.apache.commons.logging.Log log -
ESCAPE_CHAR
protected static byte ESCAPE_CHAR -
WWW_FORM_URL
BitSet of www-form-url safe characters.
-
-
Constructor Details
-
URLCodec
public URLCodec()
-
-
Method Details
-
encodeUrl
Encodes an array of bytes into an array of URL safe 7-bit characters. Unsafe characters are escaped.- Parameters:
urlsafe- bitset of characters deemed URL safebytes- array of bytes to convert to URL safe characters- Returns:
- array of bytes containing URL safe characters
-
decodeUrl
Decodes an array of URL safe 7-bit characters into an array of original bytes. Escaped characters are converted back to their original representation.- Parameters:
bytes- array of URL safe characters- Returns:
- array of original bytes
- Throws:
UnsupportedEncodingException- Thrown if URL decoding is unsuccessful
-
encode
public static byte[] encode(byte[] bytes) Encodes an array of bytes into an array of URL safe 7-bit characters. Unsafe characters are escaped.- Parameters:
bytes- array of bytes to convert to URL safe characters- Returns:
- array of bytes containing URL safe characters
-
decode
Decodes an array of URL safe 7-bit characters into an array of original bytes. Escaped characters are converted back to their original representation.- Parameters:
bytes- array of URL safe characters- Returns:
- array of original bytes
- Throws:
UnsupportedEncodingException- Thrown if URL decoding is unsuccessful
-
encode
Encodes a string into its URL safe form using the specified string charset. Unsafe characters are escaped.- Parameters:
pString- string to convert to a URL safe formcharset- the charset for pString- Returns:
- URL safe string
- Throws:
UnsupportedEncodingException- Thrown if charset is not supported
-
encode
Encodes a string into its URL safe form using the default string charset. Unsafe characters are escaped.- Parameters:
pString- string to convert to a URL safe form- Returns:
- URL safe string
- Throws:
UnsupportedEncodingException- Thrown if URL encoding is unsuccessful- See Also:
-
decode
Decodes a URL safe string into its original form using the specified encoding. Escaped characters are converted back to their original representation.- Parameters:
pString- URL safe string to convert into its original formcharset- the original string charset- Returns:
- original string
- Throws:
UnsupportedEncodingException- Thrown if charset is not supported
-
decode
Decodes a URL safe string into its original form using the default string charset. Escaped characters are converted back to their original representation.- Parameters:
pString- URL safe string to convert into its original form- Returns:
- original string
- Throws:
UnsupportedEncodingException- Thrown if URL decoding is unsuccessful- See Also:
-
encode
Encodes an object into its URL safe form. Unsafe characters are escaped.- Parameters:
pObject- string to convert to a URL safe form- Returns:
- URL safe object
- Throws:
UnsupportedEncodingException- Thrown if URL encoding is not applicable to objects of this type or if encoding is unsuccessful
-
decode
Decodes a URL safe object into its original form. Escaped characters are converted back to their original representation.- Parameters:
pObject- URL safe object to convert into its original form- Returns:
- original object
- Throws:
UnsupportedEncodingException- Thrown if the argument is not aStringorbyte[]. Thrown if a failure condition is encountered during the decode process.
-