Package org.zkoss.xel.fn
Class CommonFns
- java.lang.Object
-
- org.zkoss.xel.fn.CommonFns
-
public class CommonFns extends java.lang.ObjectCommon functions used with EL.- Author:
- tomyeh
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCommonFns()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringformatDate(java.util.Date date, java.lang.String pattern)Formats a Date into a date/time string.static java.lang.StringformatDate(java.util.Date date, java.lang.String pattern, java.util.Locale locale, java.util.TimeZone timezone, java.lang.String dateStyle, java.lang.String timeStyle)Formats a Date into a date/time string.static java.lang.StringformatNumber(java.lang.Object value, java.lang.String format)Formats a number (Integer, BigDecimal...) into a string.static java.lang.StringformatNumber(java.lang.Object number, java.lang.String pattern, java.util.Locale locale)Formats a number (Integer, BigDecimal...) into a string.static java.lang.StringgetLabel(java.lang.String key)Returns the label or message of the specified key.static java.lang.StringgetLabel(java.lang.String key, java.lang.Object[] args)Returns the label of the specified key and formats it with the specified argument, or null if not found.static intindexOf(java.lang.Object o, java.lang.Object element)Returns the index of the given element.static booleanisInstance(java.lang.Object c, java.lang.Object o)Tests whether an object, o, is an instance of a class, c.static intlastIndexOf(java.lang.Object o, java.lang.Object element)Returns the last index of the given element.static intlength(java.lang.Object o)Returns the length of an array, string, collection or map.static java.lang.Objectnew_(java.lang.Object o)Instantiates the specified class.static java.lang.Objectnew_(java.lang.Object o, java.lang.Object arg)Instantiates the specified class, and argument.static java.lang.Objectnew_(java.lang.Object o, java.lang.Object arg1, java.lang.Object arg2)Instantiates the specified class, and two arguments.static java.lang.Objectnew_(java.lang.Object o, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)Instantiates the specified class, and two arguments.static java.util.DateparseDate(java.lang.String source, java.lang.String pattern)Parses text from the beginning of the given string to produce a date.static java.util.DateparseDate(java.lang.String source, java.lang.String pattern, java.util.Locale locale, java.util.TimeZone timezone, java.lang.String dateStyle, java.lang.String timeStyle)Parses text from the beginning of the given string to produce a date.static java.lang.NumberparseNumber(java.lang.String source, java.lang.String pattern)Parses text from the beginning of the given string to produce a number.static java.lang.NumberparseNumber(java.lang.String source, java.lang.String pattern, java.util.Locale locale)Parses text from the beginning of the given string to produce a number.static booleantoBoolean(java.lang.Object val)Converts the specified object to a boolean.static chartoChar(java.lang.Object val)Converts the specified object to an character.static java.math.BigDecimaltoDecimal(java.lang.Object val)Converts the specified object to a (big) decimal.static inttoInt(java.lang.Object val)Converts the specified object to an integer.static java.lang.NumbertoNumber(java.lang.Object val)Converts the specified object to a number.static java.lang.StringtoString(java.lang.Object val)Converts the specified object to a string.
-
-
-
Method Detail
-
toBoolean
public static boolean toBoolean(java.lang.Object val)
Converts the specified object to a boolean.
-
toString
public static java.lang.String toString(java.lang.Object val)
Converts the specified object to a string.
-
toNumber
public static java.lang.Number toNumber(java.lang.Object val)
Converts the specified object to a number.
-
toInt
public static int toInt(java.lang.Object val)
Converts the specified object to an integer.
-
toDecimal
public static java.math.BigDecimal toDecimal(java.lang.Object val)
Converts the specified object to a (big) decimal.
-
toChar
public static char toChar(java.lang.Object val)
Converts the specified object to an character.
-
isInstance
public static boolean isInstance(java.lang.Object c, java.lang.Object o)Tests whether an object, o, is an instance of a class, c.
-
getLabel
public static final java.lang.String getLabel(java.lang.String key)
Returns the label or message of the specified key.- If key is "mesg:class:MMM", Messages.get(class.MMM) is called
- Otherwise,
Labels.getLabel(String)is called.
- See Also:
getLabel(String, Object[])
-
getLabel
public static final java.lang.String getLabel(java.lang.String key, java.lang.Object[] args)Returns the label of the specified key and formats it with the specified argument, or null if not found.It first uses
getLabel(String)to load the label. Then, it, if not null, invokesMessageFormats.format(java.lang.String, java.lang.Object[], java.util.Locale)to format it.The current locale is given by
Locales.getCurrent().- Since:
- 3.0.6
-
length
public static final int length(java.lang.Object o)
Returns the length of an array, string, collection or map.
-
indexOf
public static final int indexOf(java.lang.Object o, java.lang.Object element)Returns the index of the given element.- Parameters:
o- the array/collection of objects to examine, or a string. If o is a map, thenMap.keySet()is assumed.- Since:
- 5.0.7
-
lastIndexOf
public static final int lastIndexOf(java.lang.Object o, java.lang.Object element)Returns the last index of the given element.- Parameters:
o- the array/list of objects to examine, or a string.- Since:
- 5.0.7
-
new_
public static final java.lang.Object new_(java.lang.Object o) throws java.lang.ExceptionInstantiates the specified class.- Throws:
java.lang.Exception
-
new_
public static final java.lang.Object new_(java.lang.Object o, java.lang.Object arg) throws java.lang.ExceptionInstantiates the specified class, and argument.- Parameters:
o- the class name or classarg- the argument- Throws:
java.lang.Exception- Since:
- 5.0.5
-
new_
public static final java.lang.Object new_(java.lang.Object o, java.lang.Object arg1, java.lang.Object arg2) throws java.lang.ExceptionInstantiates the specified class, and two arguments.- Parameters:
o- the class name or classarg1- the first argumentarg2- the second argument- Throws:
java.lang.Exception- Since:
- 5.0.5
-
new_
public static final java.lang.Object new_(java.lang.Object o, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3) throws java.lang.ExceptionInstantiates the specified class, and two arguments.- Parameters:
o- the class name or classarg1- the first argumentarg2- the second argument- Throws:
java.lang.Exception- Since:
- 5.0.5
-
formatDate
public static final java.lang.String formatDate(java.util.Date date, java.lang.String pattern)Formats a Date into a date/time string.- Parameters:
date- the time value to be formatted into a time string.pattern- the pattern describing the date and time format- Returns:
- the formatted time string.
- Since:
- 6.0.0
-
parseDate
public static final java.util.Date parseDate(java.lang.String source, java.lang.String pattern) throws java.lang.ExceptionParses text from the beginning of the given string to produce a date. The method may not use the entire text of the given string.- Parameters:
source- AStringwhose beginning should be parsed.pattern- the pattern describing the date and time format- Returns:
- A
Dateparsed from the string. - Throws:
java.lang.Exception- Since:
- 6.0.0
-
formatNumber
public static final java.lang.String formatNumber(java.lang.Object value, java.lang.String format)Formats a number (Integer, BigDecimal...) into a string. If null, an empty string is returned.A utility to assist the handling of numeric data.
- Parameters:
value- The number to format.format- The pattern to apply, if it is null, the system's default format is used.- Returns:
- the formatted number string.
- Since:
- 6.0.1
-
parseNumber
public static final java.lang.Number parseNumber(java.lang.String source, java.lang.String pattern) throws java.lang.ExceptionParses text from the beginning of the given string to produce a number. The method may not use the entire text of the given string.- Parameters:
source- AStringwhose beginning should be parsed.pattern- the pattern describing the date and time format- Returns:
- A
Numberparsed from the string. - Throws:
java.lang.Exception- Since:
- 6.0.1
-
formatDate
public static final java.lang.String formatDate(java.util.Date date, java.lang.String pattern, java.util.Locale locale, java.util.TimeZone timezone, java.lang.String dateStyle, java.lang.String timeStyle)Formats a Date into a date/time string.- Parameters:
date- the time value to be formatted into a time string.pattern- the pattern describing the date and time formatlocale- The Locale to apply, if it is null, The current locale given byLocales.getCurrent()is used.timezone- the time zone to apply, if it is null, The current timezone given byTimeZones.getCurrent()is used.dateStyle- styling index of date.timeStyle- styling index of time.- Returns:
- the formatted time string.
- Since:
- 6.0.0
-
parseDate
public static final java.util.Date parseDate(java.lang.String source, java.lang.String pattern, java.util.Locale locale, java.util.TimeZone timezone, java.lang.String dateStyle, java.lang.String timeStyle) throws java.lang.ExceptionParses text from the beginning of the given string to produce a date. The method may not use the entire text of the given string.- Parameters:
source- AStringwhose beginning should be parsed.pattern- the pattern describing the date and time formatlocale- The Locale to apply, if it is null, The current locale given byLocales.getCurrent()is used.timezone- the time zone to apply, if it is null, The current timezone given byTimeZones.getCurrent()is used.dateStyle- styling index of date.timeStyle- styling index of time.- Returns:
- A
Dateparsed from the string. - Throws:
java.lang.Exception- Since:
- 6.0.0
-
formatNumber
public static final java.lang.String formatNumber(java.lang.Object number, java.lang.String pattern, java.util.Locale locale)Formats a number (Integer, BigDecimal...) into a string. If null, an empty string is returned.A utility to assist the handling of numeric data.
- Parameters:
number- The number to format.pattern- The pattern to apply, if it is null, the system's default format is used.locale- The Locale to apply, if it is null, The current locale given byLocales.getCurrent()is used.- Returns:
- String The formatted number string.
- Since:
- 6.0.1
-
parseNumber
public static final java.lang.Number parseNumber(java.lang.String source, java.lang.String pattern, java.util.Locale locale) throws java.lang.ExceptionParses text from the beginning of the given string to produce a number. The method may not use the entire text of the given string.- Parameters:
source- AStringwhose beginning should be parsed.pattern- the pattern describing the date and time formatlocale- The Locale to apply, if it is null, The current locale given byLocales.getCurrent()is used.- Returns:
- A
Numberparsed from the string. - Throws:
java.lang.Exception- Since:
- 6.0.1
-
-