|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gdata.util.common.base.CharEscapers
public final class CharEscapers
Utility functions for dealing with CharEscaper
s, and some commonly
used CharEscaper
instances.
Method Summary | |
---|---|
static CharEscaper |
asciiHtmlEscaper()
Returns a CharEscaper instance that escapes special characters in a
string so it can safely be included in an HTML document in either element
content or attribute values. |
static Escaper |
cppUriEscaper()
Returns a Escaper instance that escapes Java characters in a manner
compatible with the C++ webutil/url URL class (the kGoogle1Escape
set). |
static CharEscaper |
htmlEscaper()
Returns a CharEscaper instance that escapes special characters in a
string so it can safely be included in an HTML document in either element
content or attribute values. |
static CharEscaper |
javaCharEscaper()
Returns a CharEscaper instance that escapes special characters in a
string so it can safely be included in a Java char or string literal. |
static CharEscaper |
javascriptEscaper()
Returns a CharEscaper instance that escapes non-ASCII characters in
a string so it can safely be included in a Javascript string literal. |
static CharEscaper |
javaStringEscaper()
Returns a CharEscaper instance that escapes special characters in a
string so it can safely be included in a Java string literal. |
static CharEscaper |
javaStringUnicodeEscaper()
Returns a CharEscaper instance that replaces non-ASCII characters
in a string with their Unicode escape sequences (\\uxxxx where
xxxx is a hex number). |
static CharEscaper |
pythonEscaper()
Returns a CharEscaper instance that escapes special characters from
a string so it can safely be included in a Python string literal. |
static Escaper |
uriEscaper()
Returns an Escaper instance that escapes Java chars so they can be
safely included in URIs. |
static Escaper |
uriEscaper(boolean plusForSpace)
Returns a Escaper instance that escapes Java characters so they can
be safely included in URIs. |
static Escaper |
uriPathEscaper()
Returns an Escaper instance that escapes Java chars so they can be
safely included in URI path segments. |
static Escaper |
uriQueryStringEscaper()
Returns an Escaper instance that escapes Java chars so they can be
safely included in URI query string segments. |
static CharEscaper |
xmlContentEscaper()
Returns a CharEscaper instance that escapes special characters in a
string so it can safely be included in an XML document in element content. |
static CharEscaper |
xmlEscaper()
Returns a CharEscaper instance that escapes special characters in a
string so it can safely be included in an XML document in either element
content or attribute values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static CharEscaper xmlEscaper()
CharEscaper
instance that escapes special characters in a
string so it can safely be included in an XML document in either element
content or attribute values.
Note
: silently removes null-characters and control characters, as there is no way to represent them in XML.
public static CharEscaper xmlContentEscaper()
CharEscaper
instance that escapes special characters in a
string so it can safely be included in an XML document in element content.
Note
: double and single quotes are not escaped, so it is not safe to use this escaper to escape attribute values. Use thexmlEscaper()
escaper to escape attribute values or if you are
unsure. Also silently removes non-whitespace control characters, as there
is no way to represent them in XML.
public static CharEscaper htmlEscaper()
CharEscaper
instance that escapes special characters in a
string so it can safely be included in an HTML document in either element
content or attribute values.
Note
: alters non-ASCII and control characters. The entity list was taken from: here
public static CharEscaper asciiHtmlEscaper()
CharEscaper
instance that escapes special characters in a
string so it can safely be included in an HTML document in either element
content or attribute values.
Note
: does not alter non-ASCII and control characters.
public static Escaper uriEscaper()
Escaper
instance that escapes Java chars so they can be
safely included in URIs. For details on escaping URIs, see section 2.4 of
RFC 2396.
When encoding a String, the following rules apply:
Note: Unlike other escapers, URI escapers produce uppercase
hexidecimal sequences. From
RFC 3986:
"URI producers and normalizers should use uppercase hexadecimal digits
for all percent-encodings."
This escaper has identical behavior to (but is potentially much faster than):
FastURLEncoder.encode(String)
FastURLEncoder.encode(String,String)
with the encoding name "UTF-8"
com.google.gdata.util.common.net.UriEncoder#encode(String)
com.google.gdata.util.common.net.UriEncoder#encode(String,java.nio.charset.Charset)
with the UTF_8 Charset
URLEncoder.encode(String, String)
with the encoding name "UTF-8"
This method is equivalent to uriEscaper(true)
.
public static Escaper uriPathEscaper()
Escaper
instance that escapes Java chars so they can be
safely included in URI path segments. For details on escaping URIs, see
section 2.4 of RFC 3986.
When encoding a String, the following rules apply:
Note: Unlike other escapers, URI escapers produce uppercase
hexidecimal sequences. From
RFC 3986:
"URI producers and normalizers should use uppercase hexadecimal digits
for all percent-encodings."
public static Escaper uriQueryStringEscaper()
Escaper
instance that escapes Java chars so they can be
safely included in URI query string segments. When the query string
consists of a sequence of name=value pairs separated by &, the names
and values should be individually encoded. If you escape an entire query
string in one pass with this escaper, then the "=" and "&" characters
used as separators will also be escaped.
This escaper is also suitable for escaping fragment identifiers.
For details on escaping URIs, see section 2.4 of RFC 3986.
When encoding a String, the following rules apply:
Note: Unlike other escapers, URI escapers produce uppercase
hexidecimal sequences. From
RFC 3986:
"URI producers and normalizers should use uppercase hexadecimal digits
for all percent-encodings."
public static Escaper uriEscaper(boolean plusForSpace)
Escaper
instance that escapes Java characters so they can
be safely included in URIs. For details on escaping URIs, see section 2.4
of RFC 2396.
When encoding a String, the following rules apply:
plusForSpace
was specified, the space character " " is
converted into a plus sign "+". Otherwise it is converted into "%20".
Note: Unlike other escapers, URI escapers produce uppercase
hexidecimal sequences. From
RFC 3986:
"URI producers and normalizers should use uppercase hexadecimal digits
for all percent-encodings."
plusForSpace
- if true
space is escaped to +
otherwise
it is escaped to %20
. Although common, the escaping of
spaces as plus signs has a very ambiguous status in the relevant
specifications. You should prefer %20
unless you are doing
exact character-by-character comparisons of URLs and backwards
compatibility requires you to use plus signs.uriEscaper()
public static Escaper cppUriEscaper()
Escaper
instance that escapes Java characters in a manner
compatible with the C++ webutil/url URL class (the kGoogle1Escape
set).
When encoding a String, the following rules apply:
Note: Unlike other escapers, URI escapers produce uppercase
hexidecimal sequences. From
RFC 3986:
"URI producers and normalizers should use uppercase hexadecimal digits
for all percent-encodings."
Note: This escaper is a special case and is not
compliant with
RFC 2396. Specifically it will not escape "/", ":" and ",". This is
only provided for certain limited use cases and you should favor using
uriEscaper()
whenever possible.
public static CharEscaper javaStringEscaper()
CharEscaper
instance that escapes special characters in a
string so it can safely be included in a Java string literal.
Note
: does not escape single quotes, so use the escaper returned byjavaCharEscaper()
if you are generating char
literals or if you are unsure.
public static CharEscaper javaCharEscaper()
CharEscaper
instance that escapes special characters in a
string so it can safely be included in a Java char or string literal. The
behavior of this escaper is the same as that of the
javaStringEscaper()
, except it also escapes single quotes.
public static CharEscaper javaStringUnicodeEscaper()
CharEscaper
instance that replaces non-ASCII characters
in a string with their Unicode escape sequences (\\uxxxx
where
xxxx
is a hex number). Existing escape sequences won't be affected.
public static CharEscaper pythonEscaper()
CharEscaper
instance that escapes special characters from
a string so it can safely be included in a Python string literal. Does not
have any special handling for non-ASCII characters.
public static CharEscaper javascriptEscaper()
CharEscaper
instance that escapes non-ASCII characters in
a string so it can safely be included in a Javascript string literal.
Non-ASCII characters are replaced with their ASCII javascript escape
sequences (e.g., \\uhhhh or \xhh).
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |