de.infinityloop.util
Class CustomURLEncoder
java.lang.Object
de.infinityloop.util.CustomURLEncoder
public class CustomURLEncoder
- extends java.lang.Object
The class contains a utility method for converting a
String
into a MIME format called
"x-www-form-urlencoded
" format.
To convert a String
, each character is examined in turn:
- The ASCII characters '
a
' through 'z
',
'A
' through 'Z
', '0
'
through '9
', and ".", "-",
"*", "_" remain the same.
- The space character '
' is converted into a
plus sign '+
'.
- All other characters are converted into the 3-character string
"
%xy
", where xy is the two-digit
hexadecimal representation of the lower 8-bits of the character.
Method Summary |
static java.lang.String |
decode(java.lang.String s)
Translates a string from x-www-form-urlencoded format to a UTF-8 Java string.
2005-10-14: Added new heuristics: What to do when the string contains high-ASCII-characters? |
static java.lang.String |
encode(java.lang.String s)
Translates a string into x-www-form-urlencoded format. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
kPlatformWindows
public static final int kPlatformWindows
- See Also:
- Constant Field Values
kPlatformMac
public static final int kPlatformMac
- See Also:
- Constant Field Values
kPlatformUnix
public static final int kPlatformUnix
- See Also:
- Constant Field Values
encode
public static java.lang.String encode(java.lang.String s)
- Translates a string into
x-www-form-urlencoded
format.
- Parameters:
s
- String
to be translated.
- Returns:
- the translated
String
.
decode
public static java.lang.String decode(java.lang.String s)
- Translates a string from
x-www-form-urlencoded
format to a UTF-8 Java string.
2005-10-14: Added new heuristics: What to do when the string contains high-ASCII-characters? E.g. Word writes
"URL"s that have spaces quoted correctly (%20), but have umlauts simply written 1:1 as high-ASCII characters.
What we need to do is determine which encoding we should use for that hi-ASCII characters to convert it into the
appropriate Unicode character. For now, we assume that any hi-ASCII-characters are UTF-8 compatible, i.e.
part of CP1252
- Parameters:
s
- String
to be decoded.
- Returns:
- the translated
String
.