Package org.omnifaces.el.functions
Class Strings
- java.lang.Object
-
- org.omnifaces.el.functions.Strings
-
public final class Strings extends Object
Collection of EL functions for string manipulation:
of:abbreviate()
,of:capitalize()
,of:concat()
,of:prettyURL()
,of:encodeURL()
,of:encodeURI()
,of:encodeBase64()
,of:escapeJS()
,of:stripTags()
andof:formatX()
.Instead of
of:formatX()
, you can also use<o:outputFormat>
.- Author:
- Bauke Scholtz
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
abbreviate(String text, int size)
Abbreviate the given text on the given size limit with ellipsis.static String
capitalize(String string)
Capitalize the given string, i.e.static String
concat(Object left, Object right)
Concatenate the string representation of the given objects.static String
encodeBase64(String string)
Base64-encode the given string.static String
encodeURI(String string)
URI-encode the given string using UTF-8.static String
encodeURL(String string)
URL-encode the given string using UTF-8.static String
escapeJS(String string)
Escapes the given string according the JavaScript code rules.static String
format1(String pattern, Object param1)
Format the given string with 1 parameter usingMessageFormat
API.static String
format2(String pattern, Object param1, Object param2)
Format the given string with 2 parameters usingMessageFormat
API.static String
format3(String pattern, Object param1, Object param2, Object param3)
Format the given string with 3 parameters usingMessageFormat
API.static String
format4(String pattern, Object param1, Object param2, Object param3, Object param4)
Format the given string with 4 parameters usingMessageFormat
API.static String
format5(String pattern, Object param1, Object param2, Object param3, Object param4, Object param5)
Format the given string with 5 parameters usingMessageFormat
API.static boolean
matches(String value, String pattern)
Returns true if the given string matches the given pattern.static String
parenthesize(Object object)
Parenthesize the given object.static String
prettyURL(String string)
URL-prettify the given string.static String
replaceAll(String value, String pattern, String replacement)
Replace all matches of the given pattern on the given string with the given replacement.static String
stripTags(String string)
Remove XML tags from a string and return only plain text.
-
-
-
Method Detail
-
abbreviate
public static String abbreviate(String text, int size)
Abbreviate the given text on the given size limit with ellipsis.- Parameters:
text
- The text to be abbreviated.size
- The size limit of the text.- Returns:
- The abbreviated text, or the unmodified text if it is shorter than the size.
-
concat
public static String concat(Object left, Object right)
Concatenate the string representation of the given objects. This is useful when you don't know beforehand if one of the both hands is a string or isnull
, otherwise the EL#{bean.string1.concat(bean.string2)}
can just be used.- Parameters:
left
- The left hand.right
- The right hand.- Returns:
- The concatenated strings.
-
capitalize
public static String capitalize(String string)
Capitalize the given string, i.e. uppercase the first character.- Parameters:
string
- The string to be capitalized.- Returns:
- The capitalized string.
- Since:
- 1.1
-
parenthesize
public static String parenthesize(Object object)
Parenthesize the given object. This will only wrap the given object in parenthesis when it's not empty or zero.- Parameters:
object
- The object to be parenthesized.- Returns:
- The parenthesized object.
- Since:
- 3.0
-
replaceAll
public static String replaceAll(String value, String pattern, String replacement)
Replace all matches of the given pattern on the given string with the given replacement.- Parameters:
value
- The string to be replaced.pattern
- The regular expression pattern to be tested.replacement
- The string to be substituted for each match.- Returns:
- True if the given string matches the given pattern.
- Since:
- 1.5
- See Also:
String.replaceAll(String, String)
-
matches
public static boolean matches(String value, String pattern)
Returns true if the given string matches the given pattern.- Parameters:
value
- The string to be matched.pattern
- The regular expression pattern to be tested.- Returns:
- True if the given string matches the given pattern.
- Since:
- 1.5
- See Also:
String.matches(String)
-
prettyURL
public static String prettyURL(String string)
URL-prettify the given string. It performs the following tasks:- Lowercase the string.
- Remove combining diacritical marks.
- Replace non-alphanumeric characters by hyphens.
- Parameters:
string
- The string to be prettified.- Returns:
- The prettified string.
-
encodeURL
public static String encodeURL(String string)
URL-encode the given string using UTF-8. This is useful for cases where you can't use<f:param>
.- Parameters:
string
- The string to be URL-encoded.- Returns:
- The URL-encoded string.
- Throws:
UnsupportedOperationException
- When this platform does not support UTF-8.
-
encodeURI
public static String encodeURI(String string)
URI-encode the given string using UTF-8. This is useful for cases where you need to embed path parameters in URLs.- Parameters:
string
- The string to be URI-encoded.- Returns:
- The URI-encoded string.
- Throws:
UnsupportedOperationException
- When this platform does not support UTF-8.- Since:
- 3.5
-
encodeBase64
public static String encodeBase64(String string)
Base64-encode the given string. This is useful for cases where you need to create data URLs.- Parameters:
string
- The string to be Base64-encoded.- Returns:
- The Base64-encoded string.
- Since:
- 3.8
-
escapeJS
public static String escapeJS(String string)
Escapes the given string according the JavaScript code rules. This escapes among others the special characters, the whitespace, the quotes and the unicode characters. Useful whenever you want to use a Java string variable as a JavaScript string variable.- Parameters:
string
- The string to be escaped according the JavaScript code rules.- Returns:
- The escaped string according the JavaScript code rules.
-
stripTags
public static String stripTags(String string)
Remove XML tags from a string and return only plain text.- Parameters:
string
- The string with XML tags.- Returns:
- The string without XML tags.
- Since:
- 3.7
-
format1
public static String format1(String pattern, Object param1)
Format the given string with 1 parameter usingMessageFormat
API. The locale is obtained byFaces.getLocale()
. Design notice: There are five formatX() methods, each taking 1 to 5 format parameters because EL functions do not support varargs methods nor overloaded function names.- Parameters:
pattern
- The format pattern.param1
- The first parameter.- Returns:
- The formatted string.
- See Also:
MessageFormat
-
format2
public static String format2(String pattern, Object param1, Object param2)
Format the given string with 2 parameters usingMessageFormat
API. The locale is obtained byFaces.getLocale()
. Design notice: There are five formatX() methods, each taking 1 to 5 format parameters because EL functions do not support varargs methods nor overloaded function names.- Parameters:
pattern
- The format pattern.param1
- The first parameter.param2
- The second parameter.- Returns:
- The formatted string.
- See Also:
format1(String, Object)
-
format3
public static String format3(String pattern, Object param1, Object param2, Object param3)
Format the given string with 3 parameters usingMessageFormat
API. The locale is obtained byFaces.getLocale()
. Design notice: There are five formatX() methods, each taking 1 to 5 format parameters because EL functions do not support varargs methods nor overloaded function names.- Parameters:
pattern
- The format pattern.param1
- The first parameter.param2
- The second parameter.param3
- The third parameter.- Returns:
- The formatted string.
- See Also:
format1(String, Object)
-
format4
public static String format4(String pattern, Object param1, Object param2, Object param3, Object param4)
Format the given string with 4 parameters usingMessageFormat
API. The locale is obtained byFaces.getLocale()
. Design notice: There are five formatX() methods, each taking 1 to 5 format parameters because EL functions do not support varargs methods nor overloaded function names.- Parameters:
pattern
- The format pattern.param1
- The first parameter.param2
- The second parameter.param3
- The third parameter.param4
- The fourth parameter.- Returns:
- The formatted string.
- See Also:
format1(String, Object)
-
format5
public static String format5(String pattern, Object param1, Object param2, Object param3, Object param4, Object param5)
Format the given string with 5 parameters usingMessageFormat
API. The locale is obtained byFaces.getLocale()
. Design notice: There are five formatX() methods, each taking 1 to 5 format parameters because EL functions do not support varargs methods nor overloaded function names.- Parameters:
pattern
- The format pattern.param1
- The first parameter.param2
- The second parameter.param3
- The third parameter.param4
- The fourth parameter.param5
- The fifth parameter.- Returns:
- The formatted string.
- See Also:
format1(String, Object)
-
-