public class S extends Object
Note all methods defined in this class is null safe.
if any input is null
the return value is ""
An instance of this utility is exposed to any Rythm template
via TemplateBase.s()
method and can be used
in template source code freely. E.g.
@if(s().empty(name)) {
user name is empty!
}
Modifier and Type | Field and Description |
---|---|
static String |
EMPTY_STR |
static int |
IGNORECASE
The modifier used to indicate the comparison should
ignore case
|
static int |
IGNORESPACE
The modifier used to indicate the comparison should
ignore space
|
static S |
INSTANCE |
Constructor and Description |
---|
S() |
Modifier and Type | Method and Description |
---|---|
static String |
camelCase(Object obj)
Turn an object's String representation into Camel Case
|
static String |
capFirst(Object o)
Make the first character be uppercase of the given object's string representation
|
static String |
capitalizeWords(Object o)
Capitalize the first character of every word of the specified object's
string representation.
|
static String[] |
divide(Object o,
String sep)
Bridge String.split() method to Object
|
static boolean |
empty(Object o)
Alias of
isEmpty(Object) |
static boolean |
empty(String s)
Alias of
isEmpty(String) |
static boolean |
eq(Object o1,
Object o2)
Alias of
isEqual(Object, Object) |
static boolean |
eq(String s1,
String s2)
Alias of
isEqual(String, String) |
static boolean |
eq(String s1,
String s2,
int modifier)
Alias of
isEqual(String, String, int) |
static RawData |
escape(ITemplate template,
Object o)
The template implicit argument version of
escape(Object) |
static RawData |
escape(Object o)
Return a
RawData type wrapper of
an object without escaping or if the current template exists
return the escape specified by the current escape scheme of the current
render template
|
static RawData |
escape(Object o,
Object escape)
Return a
RawData type wrapper of
an object with specified escaping scheme. |
static RawData |
escapeCsv(Object o)
Alias of
escapeCSV(Object) |
static RawData |
escapeCSV(Object o)
Return a
RawData type wrapper of
an object with CSV escaping
|
static RawData |
escapeHtml(Object o)
Alias of
escapeHTML(Object) |
static RawData |
escapeHTML(Object o)
Return a
RawData type wrapper of
an object with HTML escaping
|
static RawData |
escapeJava(Object o)
Return a
RawData type wrapper of
an object with Java escaping
|
static RawData |
escapeJavascript(Object o)
Alias of
escapeJavaScript(Object) |
static RawData |
escapeJavaScript(Object o)
Return a
RawData type wrapper of
an object with JavaScript escaping
|
static RawData |
escapeJS(Object o)
Alias of
escapeJavaScript(Object) |
static RawData |
escapeJson(Object o)
Alias of
escapeCSV(Object) |
static RawData |
escapeJSON(Object o)
Return a
RawData type wrapper of
an object with JSON escaping
|
static RawData |
escapeRegex(Object o)
Escape for regular expression
|
static RawData |
escapeXml(Object o)
Alias of
escapeXML(Object) |
static RawData |
escapeXML(Object o)
Return a
RawData type wrapper of
an object with XML escaping
|
static String |
format(Date date)
Format a date with engine's default format corresponding
to the engine's locale configured
|
static String |
format(Date date,
String pattern)
Format a date with specified pattern
|
static String |
format(Date date,
String pattern,
Locale locale)
Transformer.
|
static String |
format(Date date,
String pattern,
Locale locale,
String timezone)
Transformer.
|
static String |
format(ITemplate template,
Date date)
Format a date with specified engine's default format corresponding
to the engine's locale configured
|
static String |
format(ITemplate template,
Date date,
String pattern)
Format a date with specified pattern
|
static String |
format(ITemplate template,
Date date,
String pattern,
Locale locale)
|
static String |
format(ITemplate template,
Date date,
String pattern,
Locale locale,
String timezone)
Format a date with specified pattern, lang, locale and timezone.
|
static String |
format(ITemplate template,
Number number)
Format number with specified template
|
static String |
format(ITemplate template,
Number number,
String pattern)
Format a number with specified engine, pattern
|
static String |
format(ITemplate template,
Number number,
String pattern,
Locale locale)
Format the number with specified template, pattern, language and locale
|
static String |
format(ITemplate template,
Object o)
Generalize format parameter for the sake of dynamic expr evaluation
|
static String |
format(ITemplate template,
Object o,
String pattern)
Generalize format parameter for the sake of dynamic evaluation
|
static String |
format(ITemplate template,
Object o,
String pattern,
Locale locale)
Generalize format parameter for the sake of dynamic evaluation
|
static String |
format(ITemplate template,
Object o,
String pattern,
Locale locale,
String timezone)
Generalize format parameter for the sake of dynamic evaluation
|
static String |
format(Number number)
Format a number using default pattern, language and locale
|
static String |
format(Number number,
String pattern)
Format a number with specified pattern
|
static String |
format(Number number,
String pattern,
Locale locale)
Format the number with specified pattern, language and locale
|
static String |
format(Object o)
Format general object: for the sake of dynamic expr evaluation
|
static String |
format(Object o,
String pattern)
Generalize format parameter for the sake of dynamic evaluation
|
static String |
format(Object o,
String pattern,
Locale locale)
Generalize format parameter for the sake of dynamic evaluation
|
static String |
format(Object o,
String pattern,
Locale locale,
String timezone)
Generalize format parameter for the sake of dynamic evaluation
|
static String |
formatCurrency(ITemplate template,
Object data)
|
static String |
formatCurrency(ITemplate template,
Object data,
String currencyCode)
|
static String |
formatCurrency(ITemplate template,
Object data,
String currencyCode,
Locale locale)
Format give data into currency using locale info from the engine specified
|
static String |
formatCurrency(Object data)
Transformer method.
|
static String |
formatCurrency(Object data,
String currencyCode)
Transformer method.
|
static String |
formatCurrency(Object data,
String currencyCode,
Locale locale)
|
static String |
formatSize(Object data)
Format size (e.g.
|
static String |
i18n(ITemplate template,
Object key,
Object... args)
Return i18n message of a given key and args, use the locale info from the template specified.
|
static String |
i18n(Object key) |
static String |
i18n(Object key,
Object... args)
Transformer method.
|
static boolean |
isDigitsOrAlphabetic(char c) |
static boolean |
isEmpty(Object o)
Determine if a given Object instance is null or empty after it
converted to a String.
|
static boolean |
isEmpty(String s)
Determine if a given String is null or empty.
|
static boolean |
isEqual(Object o1,
Object o2)
Check if two Object is equal after converted into String
|
static boolean |
isEqual(String s1,
String s2)
Check if two String is equal.
|
static boolean |
isEqual(String s1,
String s2,
int modifier)
Determine whether two string instance is equal based on
the modifier passed in.
|
static boolean |
isNotEmpty(Object o)
Determine if a given Object instance is NOT null or empty.
|
static boolean |
isNotEmpty(String s)
Determine if a given String is NOT null or empty.
|
static boolean |
isNotEqual(Object o1,
Object o2)
Check if two Object is not equal after converted into String
|
static boolean |
isNotEqual(String s1,
String s2)
Check if two String is not equal.
|
static boolean |
isNotEqual(String s1,
String s2,
int modifier)
The counter function of
isEqual(String, String, int) |
static String |
join(Character[] a) |
static String |
join(char sep,
Character[] a) |
static String |
join(char sep,
Double[] a) |
static String |
join(char sep,
Float[] a) |
static String |
join(char sep,
Integer[] a) |
static String |
join(char sep,
Iterable itr)
Join an
iterable with a char separator |
static String |
join(char sep,
Long[] a) |
static String |
join(Double[] a) |
static String |
join(Float[] a) |
static String |
join(Integer[] a) |
static String |
join(Iterable itr)
Join items in an
iterable with "," |
static String |
join(Long[] a) |
static String |
join(String sep,
Character[] a) |
static String |
join(String sep,
Double[] a) |
static String |
join(String sep,
Float[] a) |
static String |
join(String sep,
Integer[] a) |
static String |
join(String sep,
Iterable itr)
Join an
iterable with separator |
static String |
join(String sep,
Iterator i) |
static String |
join(String sep,
Long[] a) |
static String |
join(String sep,
Object obj) |
static int |
len(Object o)
get length of specified object
If o is a Collection or Map, then return size of it
If o is an array, then return length of it
Otherwise return length() of String representation of the object
|
static String |
lowerCase(Object o)
Bridge String.toUpperCase() method to Object
|
static String |
lowerFirst(Object o)
Make the first character be lowercase of the given object's string representation
|
static boolean |
ne(Object o1,
Object o2)
Alias of
isNotEqual(Object, Object) |
static boolean |
ne(String s1,
String s2)
Alias of
isNotEqual(String, String) |
static boolean |
ne(String s1,
String s2,
int modifier)
Alias of
isNotEqual(String, String, int) |
static RawData |
nl2br(Object data)
Change line break in the data string into
|
static RawData |
nl2br(RawData data)
Change line break in the data string into
|
static String |
noAccents(Object o)
Replace accent character (usually found in European languages) of the String representation of a
give object to non-accent char.
|
static boolean |
notEmpty(Object o)
Alias of
isNotEmpty(Object) |
static boolean |
notEmpty(String s)
Alias of
isNotEmpty(String) |
static String |
random()
Return a random string with 8 chars
|
static String |
random(int len)
Generate random string.
|
static RawData |
raw(Object o)
Return a
RawData type wrapper of
an object without any escaping. |
static String |
removeAllLineBreaks(Object o)
Remove all line breaks from string representation of specified object O
|
static String |
shrinkSpace(Object o)
Shrink spaces in an object's string representation by merge multiple
spaces, tabs into one space, and multiple line breaks into one line break
|
static String |
str(Object o)
Alias of
toString(Object) |
static String |
string(Object o)
Alias of
toString(Object) |
static String |
strip(Object o,
String prefix,
String suffix)
Strip the prefix and suffix from an object's String representation and
return the result
|
static String |
stripBrace(Object o)
Strip the brace from an object's string representation and return the result
|
static String |
stripBraceAndQuotation(Object o)
Strip off both brace and quotation
|
static String |
stripQuotation(Object o)
Strip the quotation mark from an object's string representation and return the result
|
static String |
toString(Object o)
Safe convert an Object to String.
|
static String |
upperCase(Object o)
Bridge String.toUpperCase() method to Object
|
static String |
urlEncode(Object data)
encode using utf-8
|
public static final S INSTANCE
public static final String EMPTY_STR
public static final int IGNORECASE
public static final int IGNORESPACE
public static boolean isEmpty(String s)
""
after do a String.trim()
operation on its
- public static boolean empty(String s)
isEmpty(String)
s
- public static boolean isNotEmpty(String s)
s
- isEmpty(String)
public static boolean notEmpty(String s)
isNotEmpty(String)
s
- public static boolean isEmpty(Object o)
o
- isEmpty(String)
public static boolean empty(Object o)
isEmpty(Object)
o
- public static boolean isNotEmpty(Object o)
o
- isEmpty(Object)
public static boolean notEmpty(Object o)
isNotEmpty(Object)
o
- public static boolean isEqual(String s1, String s2)
case sensitive
and space sensitive
s1
- s2
- public static boolean isNotEqual(String s1, String s2)
case sensitive
and space sensitive
s1
- s2
- public static boolean eq(String s1, String s2)
isEqual(String, String)
s1
- s2
- public static boolean ne(String s1, String s2)
isNotEqual(String, String)
s1
- s2
- public static boolean isEqual(Object o1, Object o2)
o1
- o2
- public static boolean isNotEqual(Object o1, Object o2)
o1
- o2
- public static boolean eq(Object o1, Object o2)
isEqual(Object, Object)
o1
- o2
- public static boolean ne(Object o1, Object o2)
isNotEqual(Object, Object)
o1
- o2
- public static boolean eq(String s1, String s2, int modifier)
isEqual(String, String, int)
s1
- s2
- modifier
- public static boolean ne(String s1, String s2, int modifier)
isNotEqual(String, String, int)
s1
- s2
- modifier
- public static boolean isEqual(String s1, String s2, int modifier)
is 2 strings equal case insensitive?
S.isEqual(s1, s2, S.IGNORECASE)
is 2 strings equals case and space insensitive?
S.isEqual(s1, s2, S.IGNORECASE & S.IGNORESPACE)
s1
- s2
- modifier
- public static boolean isNotEqual(String s1, String s2, int modifier)
isEqual(String, String, int)
s1
- s2
- modifier
- public static String str(Object o)
toString(Object)
o
- public static String string(Object o)
toString(Object)
o
- public static String toString(Object o)
null
than ""
is
returnedo
- public static String removeAllLineBreaks(Object o)
o
- public static RawData raw(Object o)
RawData
type wrapper of
an object without any escaping.o
- public static RawData escape(Object o)
RawData
type wrapper of
an object without escaping or if the current template exists
return the escape specified by the current escape scheme of the current
render template
Object is converted to String
before escaping
o
- public static RawData escape(ITemplate template, Object o)
escape(Object)
template
- o
- public static RawData escape(Object o, Object escape)
RawData
type wrapper of
an object with specified escaping scheme.
You can pass any type of object to specify the escaping scheme. However
they will in the end converted to converted to String
and then determine which escaping to use:
escapeJSON(Object)
escapeXML(Object)
escapeJavaScript(Object)
escapeCSV(Object)
escapeCSV(Object)
Note Object instance is converted to String before escaping
o
- escape
- public static RawData escapeHTML(Object o)
RawData
type wrapper of
an object with HTML escaping
Object is converted to String
before escaping
o
- public static RawData escapeHtml(Object o)
escapeHTML(Object)
o
- public static RawData escapeCSV(Object o)
RawData
type wrapper of
an object with CSV escaping
Object is converted to String
before escaping
o
- public static RawData escapeCsv(Object o)
escapeCSV(Object)
o
- public static RawData escapeJSON(Object o)
RawData
type wrapper of
an object with JSON escaping
Object is converted to String
before escaping
After the object get escaped, the output string is safe to put into a JSON block
o
- public static RawData escapeJson(Object o)
escapeCSV(Object)
o
- public static RawData escapeJavaScript(Object o)
RawData
type wrapper of
an object with JavaScript escaping
Object is converted to String
before escaping
After the object get escaped, the output string is safe to put inside a pair of JavaScript quotation marks
o
- public static RawData escapeJavascript(Object o)
escapeJavaScript(Object)
o
- public static RawData escapeJS(Object o)
escapeJavaScript(Object)
o
- public static RawData escapeJava(Object o)
RawData
type wrapper of
an object with Java escaping
Object is converted to String
before escaping
After the object get escaped, the output string is safe to put inside a pair of Java quotation marks
o
- public static RawData escapeXML(Object o)
RawData
type wrapper of
an object with XML escaping
Object is converted to String
before escaping
After the object get escaped, the output string is safe to put inside a XML attribute
o
- public static RawData escapeXml(Object o)
escapeXML(Object)
o
- public static RawData escapeRegex(Object o)
o
- public static String strip(Object o, String prefix, String suffix)
For example:
Object o = "xxBByy";
String s = S.strip(o, "xx", "yy")
At the end above code, s
should be "BB"
o
- prefix
- suffix
- public static String stripBrace(Object o)
o
- public static String stripQuotation(Object o)
o
- public static String stripBraceAndQuotation(Object o)
o
- public static String shrinkSpace(Object o)
o
- public static boolean isDigitsOrAlphabetic(char c)
public static String capitalizeWords(Object o)
o
- public static String noAccents(Object o)
o
- public static String lowerFirst(Object o)
o
- public static String capFirst(Object o)
o
- public static String camelCase(Object obj)
obj
- public static String[] divide(Object o, String sep)
o
- sep
- public static String lowerCase(Object o)
o
- public static String upperCase(Object o)
o
- public static int len(Object o)
o
- public static RawData nl2br(RawData data)
data
- public static RawData nl2br(Object data)
data
- public static String urlEncode(Object data)
data
- public static String format(Number number)
number
- public static String format(ITemplate template, Number number)
template
- number
- public static String format(Number number, String pattern, Locale locale)
number
- pattern
- locale
- DecimalFormatSymbols
public static String format(ITemplate template, Number number, String pattern, Locale locale)
number
- pattern
- locale
- DecimalFormatSymbols
public static String format(Number number, String pattern)
number
- pattern
- public static String format(ITemplate template, Number number, String pattern)
number
- pattern
- public static String format(Object o)
o
- public static String format(Date date)
date
- public static String format(ITemplate template, Object o)
template
- o
- public static String format(ITemplate template, Date date)
date
- public static String format(Date date, String pattern)
date
- pattern
- public static String format(Object o, String pattern)
o
- pattern
- public static String format(ITemplate template, Date date, String pattern)
template
- date
- pattern
- public static String format(ITemplate template, Object o, String pattern)
o
- pattern
- public static String format(Date date, String pattern, Locale locale)
date
- pattern
- locale
- public static String format(Object o, String pattern, Locale locale)
o
- pattern
- public static String format(ITemplate template, Date date, String pattern, Locale locale)
template
- date
- pattern
- locale
- public static String format(ITemplate template, Object o, String pattern, Locale locale)
o
- pattern
- public static String format(Date date, String pattern, Locale locale, String timezone)
date
- pattern
- locale
- timezone
- SimpleDateFormat
public static String format(Object o, String pattern, Locale locale, String timezone)
o
- pattern
- public static String format(ITemplate template, Date date, String pattern, Locale locale, String timezone)
template
- date
- pattern
- locale
- timezone
- public static String format(ITemplate template, Object o, String pattern, Locale locale, String timezone)
o
- pattern
- public static String formatSize(Object data)
1024L
, return size + B
1024L ^ 2
, return size/1024L + KB
1024L ^ 3
, return size/1048576L + MB
1024L ^ 4
, return size/1073741824L + GB
The method accept any data type. When null
is found then
NullPointerException
will be thrown out; if an Number
is passed in, it will be type cast to Long
; otherwise
a Long.valueOf(data.toString())
is used to find out
the number
data
- public static String formatCurrency(Object data)
data
- #formatCurrency(org.rythmengine.template.ITemplate, Object, String, java.util.Locale)}
public static String formatCurrency(ITemplate template, Object data)
template
- data
- public static String formatCurrency(Object data, String currencyCode)
data
- currencyCode
- #formatCurrency(org.rythmengine.template.ITemplate, Object, String, java.util.Locale)}
public static String formatCurrency(ITemplate template, Object data, String currencyCode)
template
- data
- currencyCode
- public static String formatCurrency(Object data, String currencyCode, Locale locale)
data
- currencyCode
- locale
- public static String formatCurrency(ITemplate template, Object data, String currencyCode, Locale locale)
The method accept any data type. When null
is found then
NullPointerException
will be thrown out; if an Number
is passed in, it will be type cast to Number
; otherwise
a Double.valueOf(data.toString())
is used to find out
the number
template
- data
- currencyCode
- locale
- public static String i18n(ITemplate template, Object key, Object... args)
Return i18n message of a given key and args, use the locale info from the template specified.
if null template instance passed in then it will try to guess from the current engine via
RythmEngine.get()
template
- key
- args
- the format arguments. If the first argument is of type Locale then it will be used to specify
the locale of the processing, and the rest elements are used as format argumentspublic static String i18n(Object key, Object... args)
key
- args
- public static String random(int len)
len
- public static String random()
public static String join(Iterable itr)
iterable
with ","itr
- public static String join(String sep, Iterable itr)
iterable
with separatoritr
- sep
- public static String join(char sep, Iterable itr)
iterable
with a char separatoritr
- sep
- Copyright © 2015. All Rights Reserved.