public class StringEncoder
extends java.lang.Object
implements java.io.Serializable
The methods in this class are accessible from within a template via the
$str
variable.
Modifier and Type | Field and Description |
---|---|
private static java.util.Hashtable<java.lang.String,java.util.regex.Pattern> |
cvRegExPatterns
A cache of compiled regular expression patterns.
|
static java.lang.String |
DEFAULT_ENCODING
The default character encoding.
|
private static long |
serialVersionUID
The class' serialization version id.
|
Constructor and Description |
---|
StringEncoder() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
enc(java.lang.String s)
Returns a string that has been URL encoded.
|
static java.lang.String |
enc(java.lang.StringBuilder sb)
Returns a string that has been URL encoded.
|
static java.lang.String |
encspc(java.lang.String s)
Returns a string that has all of its embedded spaces URL encoded.
|
static java.lang.String |
encspc(java.lang.StringBuilder sb)
Returns a string that has all of its embedded spaces URL encoded.
|
static java.lang.String |
esc(java.lang.String s)
Returns a string that has any "script unsafe" characters (such as double
quotes, single quotes and backslashes) preceded with the escape character
(a backslash).
|
static java.lang.String |
esc(java.lang.StringBuilder sb)
Returns a string that has any "script unsafe" characters (such as double
quotes, single quotes and backslashes) preceded with the escape character
(a backslash).
|
private static java.lang.String |
escCRLF(java.lang.String s)
Returns the given string with LF and CRLF converted to double tildes.
|
static java.lang.String |
fhs(java.lang.String s)
Returns a string that has any "html unsafe" characters (such as double
quotes, single quotes, greater than signs, less than signs) replaced with
corresponding "html safe" decimal entity codes.
|
static java.lang.String |
fhs(java.lang.StringBuilder sb)
Returns a string that has any "html unsafe" characters (such as double
quotes, single quotes, greater than signs, less than signs) replaced with
corresponding "html safe" decimal entity codes.
|
private static java.lang.String |
fhsAmpersand(java.lang.String s)
Returns a string that has any standalone ampersands (&) converted to the
"html safe" decimal entity code.
|
static java.lang.String |
fhsLine(java.lang.String s)
Returns a string that has any "html unsafe" characters (such as double
quotes, single quotes, greater than signs, less than signs) replaced with
corresponding "html safe" decimal entity codes.
|
static java.lang.String |
fhsLine(java.lang.StringBuilder sb)
Returns a string that has any "html unsafe" characters (such as double
quotes, single quotes, greater than signs, less than signs) replaced with
corresponding "html safe" decimal entity codes.
|
static java.lang.String |
fts(java.lang.String s)
Returns a string that has any "text unsafe" characters (such as html
entity codes) replaced with corresponding "text safe" characters.
|
static java.lang.String |
fts(java.lang.StringBuilder sb)
Returns a string that has any "text unsafe" characters (such as html
entity codes) replaced with corresponding "text safe" characters.
|
static java.lang.String |
fwl(java.lang.StringBuilder sb,
int length)
Pads or truncates a string to a fixed-width length.
|
static java.lang.String |
fwl(java.lang.String s,
int length)
Pads or truncates a string to a fixed-width length.
|
static java.lang.String |
fwld(java.lang.StringBuilder sb,
int length)
Pads or truncates a string to a fixed-width length.
|
static java.lang.String |
fwld(java.lang.String s,
int length)
Pads or truncates a string to a fixed-width length.
|
static java.lang.String |
fwr(java.lang.StringBuilder sb,
int length)
Pads or truncates a string to a fixed-width length.
|
static java.lang.String |
fwr(java.lang.String s,
int length)
Pads or truncates a string to a fixed-width length.
|
static java.lang.String |
fwrd(java.lang.StringBuilder sb,
int length)
Pads or truncates a string to a fixed-width length.
|
static java.lang.String |
fwrd(java.lang.String s,
int length)
Pads or truncates a string to a fixed-width length.
|
static java.lang.String |
fxs(java.lang.String s)
Returns a string that has any "xml unsafe" characters (such as double
quotes, single quotes, greater than signs, less than signs) replaced with
corresponding "xml safe" decimal entity codes.
|
static java.lang.String |
fxs(java.lang.StringBuilder sb)
Returns a string that has any "xml unsafe" characters (such as double
quotes, single quotes, greater than signs, less than signs) replaced with
corresponding "xml safe" decimal entity codes.
|
private static java.util.regex.Pattern |
getRegExPattern(java.lang.String s)
Returns a compiled regular expression
Pattern object for the
given string. |
private static boolean |
isEntity(java.lang.StringBuilder sb,
int index)
Determines if an html entity is about to be processed.
|
static java.lang.String |
pre(java.lang.String s)
Returns a string that has been pre-encoded or pre-formatted.
|
static java.lang.String |
quote(java.lang.String s)
Returns the given string enclosed within double quotes.
|
static java.lang.String |
quote(java.lang.String s,
boolean escape)
Returns the given string enclosed within double quotes and optionally
escapes the string prior to quoting.
|
private static final long serialVersionUID
public static final java.lang.String DEFAULT_ENCODING
private static java.util.Hashtable<java.lang.String,java.util.regex.Pattern> cvRegExPatterns
public static java.lang.String enc(java.lang.String s)
s
- (String) The string to process.public static java.lang.String enc(java.lang.StringBuilder sb)
sb
- (StringBuilder) The string to process.public static java.lang.String encspc(java.lang.String s)
s
- (String) The string to process.public static java.lang.String encspc(java.lang.StringBuilder sb)
sb
- (StringBuilder) The string to process.public static java.lang.String esc(java.lang.String s)
s
- (String) The string to process.public static java.lang.String esc(java.lang.StringBuilder sb)
sb
- (StringBuilder) The string to process.private static java.lang.String escCRLF(java.lang.String s)
s
- (String) The string to process.public static java.lang.String fhs(java.lang.String s)
s
- (String) The string to process.public static java.lang.String fhs(java.lang.StringBuilder sb)
sb
- (StringBuilder) The string to process.private static java.lang.String fhsAmpersand(java.lang.String s)
s
- (String) The string to process.public static java.lang.String fhsLine(java.lang.String s)
fhs
except does not convert "crlf" and "lf" to html "br". If the result is
an empty string, returns the html non-breaking space entity ( ).
This method is typically invoked when html safe encoding is desired for
a single line of html and the line should remain intact vs. being split
into multiple lines.s
- (String) The string to process.public static java.lang.String fhsLine(java.lang.StringBuilder sb)
fhs
except does not convert "crlf" and "lf" to html "br". If the result is
an empty string, returns the html non-breaking space entity ( ).
This method is typically invoked when html safe encoding is desired for
a single line of html and the line should remain intact vs. being split
into multiple lines.sb
- (StringBuilder) The string to process.public static java.lang.String fts(java.lang.String s)
s
- (String) The string to process.public static java.lang.String fts(java.lang.StringBuilder sb)
sb
- (StringBuilder) The string to process.public static java.lang.String fwl(java.lang.String s, int length)
s
- (String) The string to process.length
- (int) The desired length of the result.public static java.lang.String fwl(java.lang.StringBuilder sb, int length)
sb
- (StringBuilder) The string to process.length
- (int) The desired length of the result.public static java.lang.String fwld(java.lang.String s, int length)
Same as fwl
except uses a dot (.) for the pad character vs.
using a space.
s
- (String) The string to process.length
- (int) The desired length of the result.public static java.lang.String fwld(java.lang.StringBuilder sb, int length)
Same as fwl
except uses a dot (.) for the pad character vs.
using a space.
sb
- (StringBuilder) The string to process.length
- (int) The desired length of the result.public static java.lang.String fwr(java.lang.String s, int length)
s
- (String) The string to process.length
- (int) The desired length of the result.public static java.lang.String fwr(java.lang.StringBuilder sb, int length)
sb
- (StringBuilder) The string to process.length
- (int) The desired length of the result.public static java.lang.String fwrd(java.lang.String s, int length)
Same as fwr
except uses a dot (.) for the pad character vs.
using a space.
s
- (String) The string to process.length
- (int) The desired length of the result.public static java.lang.String fwrd(java.lang.StringBuilder sb, int length)
Same as fwr
except uses a dot (.) for the pad character vs.
using a space.
sb
- (StringBuilder) The string to process.length
- (int) The desired length of the result.public static java.lang.String fxs(java.lang.String s)
s
- (String) The string to process.public static java.lang.String fxs(java.lang.StringBuilder sb)
sb
- (StringBuilder) The string to process.public static java.lang.String pre(java.lang.String s)
s
- (String) The string to process.public static java.lang.String quote(java.lang.String s)
s
- (String) The string to process.public static java.lang.String quote(java.lang.String s, boolean escape)
s
- (String) The string to process.escape
- (boolean) true
to escape the given string
before quoting, otherwise false
.private static java.util.regex.Pattern getRegExPattern(java.lang.String s)
Pattern
object for the
given string. The given string should simply contain the character(s)
that are to be matched vs. a formatted regex pattern string. This method
assumes that any regex metacharacters contained in the given string are
characters to be matched, meaning that any metacharacters in the string
are escaped prior to creating the compiled regex pattern.s
- (String) The string to process.private static boolean isEntity(java.lang.StringBuilder sb, int index)
true
if an html entity is about to be
processed, otherwise false
.