Class CommonFns

java.lang.Object
org.zkoss.xel.fn.CommonFns

public class CommonFns extends Object
Common functions used with EL.
Author:
tomyeh
  • Constructor Details

    • CommonFns

      protected CommonFns()
  • Method Details

    • toBoolean

      public static boolean toBoolean(Object val)
      Converts the specified object to a boolean.
    • toString

      public static String toString(Object val)
      Converts the specified object to a string.
    • toNumber

      public static Number toNumber(Object val)
      Converts the specified object to a number.
    • toInt

      public static int toInt(Object val)
      Converts the specified object to an integer.
    • toDecimal

      public static BigDecimal toDecimal(Object val)
      Converts the specified object to a (big) decimal.
    • toChar

      public static char toChar(Object val)
      Converts the specified object to an character.
    • isInstance

      public static boolean isInstance(Object c, Object o)
      Tests whether an object, o, is an instance of a class, c.
    • getLabel

      public static final String getLabel(String key)
      Returns the label or message of the specified key.
      See Also:
    • getLabel

      public static final String getLabel(String key, 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, invokes MessageFormats.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(Object o)
      Returns the length of an array, string, collection or map.
    • indexOf

      public static final int indexOf(Object o, 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, then Map.keySet() is assumed.
      Since:
      5.0.7
    • lastIndexOf

      public static final int lastIndexOf(Object o, 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 Object new_(Object o) throws Exception
      Instantiates the specified class.
      Throws:
      Exception
    • new_

      public static final Object new_(Object o, Object arg) throws Exception
      Instantiates the specified class, and argument.
      Parameters:
      o - the class name or class
      arg - the argument
      Throws:
      Exception
      Since:
      5.0.5
    • new_

      public static final Object new_(Object o, Object arg1, Object arg2) throws Exception
      Instantiates the specified class, and two arguments.
      Parameters:
      o - the class name or class
      arg1 - the first argument
      arg2 - the second argument
      Throws:
      Exception
      Since:
      5.0.5
    • new_

      public static final Object new_(Object o, Object arg1, Object arg2, Object arg3) throws Exception
      Instantiates the specified class, and two arguments.
      Parameters:
      o - the class name or class
      arg1 - the first argument
      arg2 - the second argument
      Throws:
      Exception
      Since:
      5.0.5
    • formatDate

      public static final String formatDate(Date date, 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 Date parseDate(String source, String pattern) 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 - A String whose beginning should be parsed.
      pattern - the pattern describing the date and time format
      Returns:
      A Date parsed from the string.
      Throws:
      Exception
      Since:
      6.0.0
    • formatNumber

      public static final String formatNumber(Object value, 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 Number parseNumber(String source, String pattern) 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 - A String whose beginning should be parsed.
      pattern - the pattern describing the date and time format
      Returns:
      A Number parsed 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 format
      locale - The Locale to apply, if it is null, The current locale given by Locales.getCurrent() is used.
      timezone - the time zone to apply, if it is null, The current timezone given by TimeZones.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 - A String whose beginning should be parsed.
      pattern - the pattern describing the date and time format
      locale - The Locale to apply, if it is null, The current locale given by Locales.getCurrent() is used.
      timezone - the time zone to apply, if it is null, The current timezone given by TimeZones.getCurrent() is used.
      dateStyle - styling index of date.
      timeStyle - styling index of time.
      Returns:
      A Date parsed from the string.
      Throws:
      Exception
      Since:
      6.0.0
    • formatNumber

      public static final String formatNumber(Object number, String pattern, 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 by Locales.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 - A String whose beginning should be parsed.
      pattern - the pattern describing the date and time format
      locale - The Locale to apply, if it is null, The current locale given by Locales.getCurrent() is used.
      Returns:
      A Number parsed from the string.
      Throws:
      Exception
      Since:
      6.0.1