Package org.zkoss.xel.fn
Class CommonFns
java.lang.Object
org.zkoss.xel.fn.CommonFns
Common functions used with EL.
- Author:
- tomyeh
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final StringformatDate(Date date, String pattern) Formats a Date into a date/time string.static final StringformatDate(Date date, String pattern, Locale locale, TimeZone timezone, String dateStyle, String timeStyle) Formats a Date into a date/time string.static final StringformatNumber(Object value, String format) Formats a number (Integer, BigDecimal...) into a string.static final StringformatNumber(Object number, String pattern, Locale locale) Formats a number (Integer, BigDecimal...) into a string.static final StringReturns the label or message of the specified key.static final StringReturns the label of the specified key and formats it with the specified argument, or null if not found.static final intReturns the index of the given element.static booleanisInstance(Object c, Object o) Tests whether an object, o, is an instance of a class, c.static final intlastIndexOf(Object o, Object element) Returns the last index of the given element.static final intReturns the length of an array, string, collection or map.static final ObjectInstantiates the specified class.static final ObjectInstantiates the specified class, and argument.static final ObjectInstantiates the specified class, and two arguments.static final ObjectInstantiates the specified class, and two arguments.static final DateParses text from the beginning of the given string to produce a date.static final DateparseDate(String source, String pattern, Locale locale, TimeZone timezone, String dateStyle, String timeStyle) Parses text from the beginning of the given string to produce a date.static final NumberparseNumber(String source, String pattern) Parses text from the beginning of the given string to produce a number.static final NumberparseNumber(String source, String pattern, Locale locale) Parses text from the beginning of the given string to produce a number.static booleanConverts the specified object to a boolean.static charConverts the specified object to an character.static BigDecimalConverts the specified object to a (big) decimal.static intConverts the specified object to an integer.static NumberConverts the specified object to a number.static StringConverts the specified object to a string.
-
Constructor Details
-
CommonFns
protected CommonFns()
-
-
Method Details
-
toBoolean
Converts the specified object to a boolean. -
toString
Converts the specified object to a string. -
toNumber
Converts the specified object to a number. -
toInt
Converts the specified object to an integer. -
toDecimal
Converts the specified object to a (big) decimal. -
toChar
Converts the specified object to an character. -
isInstance
Tests whether an object, o, is an instance of a class, c. -
getLabel
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
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
Returns the length of an array, string, collection or map. -
indexOf
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
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_
Instantiates the specified class.- Throws:
Exception
-
new_
Instantiates the specified class, and argument.- Parameters:
o- the class name or classarg- the argument- Throws:
Exception- Since:
- 5.0.5
-
new_
Instantiates the specified class, and two arguments.- Parameters:
o- the class name or classarg1- the first argumentarg2- the second argument- Throws:
Exception- Since:
- 5.0.5
-
new_
Instantiates the specified class, and two arguments.- Parameters:
o- the class name or classarg1- the first argumentarg2- the second argument- Throws:
Exception- Since:
- 5.0.5
-
formatDate
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
Parses 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:
Exception- Since:
- 6.0.0
-
formatNumber
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
Parses 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:
Exception- Since:
- 6.0.1
-
formatDate
public static final String formatDate(Date date, String pattern, Locale locale, TimeZone timezone, String dateStyle, 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 Date parseDate(String source, String pattern, Locale locale, TimeZone timezone, String dateStyle, String timeStyle) throws Exception Parses 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:
Exception- Since:
- 6.0.0
-
formatNumber
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 Number parseNumber(String source, String pattern, Locale locale) throws Exception Parses 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:
Exception- Since:
- 6.0.1
-