Class Functions


  • public class Functions
    extends java.lang.Object
    Static functions that extend the Expression Language with standardized behaviour commonly used by page authors.

    Implementation Note: When passing a String parameter, section 1.18.2 of the EL specification requires the container to coerce a null value to an empty string. These implementation assume such behaviour and do not check for null parameters. Passing a null will generally trigger a NullPointerException.

    • Constructor Summary

      Constructors 
      Constructor Description
      Functions()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean contains​(java.lang.String input, java.lang.String substring)
      Tests if a string contains the specified substring.
      static boolean containsIgnoreCase​(java.lang.String input, java.lang.String substring)
      Tests if a string contains the specified substring in a case insensitive way.
      static boolean endsWith​(java.lang.String input, java.lang.String suffix)
      Tests if a string ends with the specified suffix according to the semantics of String#endsWith().
      static java.lang.String escapeXml​(java.lang.String input)
      Escapes characters that could be interpreted as XML markup as defined by the <c:out> action.
      static int indexOf​(java.lang.String input, java.lang.String substring)
      Returns the index (0-based) withing a string of the first occurrence of a specified substring according to the semantics of the method String#indexOf().
      static java.lang.String join​(java.lang.String[] array, java.lang.String separator)
      Joins all elements of an array into a string.
      static int length​(java.lang.Object obj)
      Returns the number of items in a collection or the number of characters in a string.
      static java.lang.String replace​(java.lang.String input, java.lang.String before, java.lang.String after)
      Returns a string resulting from replacing all occurrences of a "before" substring with an "after" substring.
      static java.lang.String[] split​(java.lang.String input, java.lang.String delimiters)
      Splits a string into an array of substrings according to the semantics of StringTokenizer.
      static boolean startsWith​(java.lang.String input, java.lang.String prefix)
      Tests if a string starts with the specified prefix according to the semantics of String#startsWith().
      static java.lang.String substring​(java.lang.String input, int beginIndex, int endIndex)
      Returns a subset of a string according to the semantics of String#substring() with additional semantics as follows: if beginIndex < 0 its value is adjusted to 0 if endIndex < 0 or greater than the string length, its value is adjusted to the length of the string if endIndex < beginIndex, an empty string is returned
      static java.lang.String substringAfter​(java.lang.String input, java.lang.String substring)
      Returns a subset of a string following the first occurrence of a specific substring.
      static java.lang.String substringBefore​(java.lang.String input, java.lang.String substring)
      Returns a subset of a string immediately before the first occurrence of a specific substring.
      static java.lang.String toLowerCase​(java.lang.String input)
      Converts all of the characters of the input string to lower case according to the semantics of method String#toLowerCase().
      static java.lang.String toUpperCase​(java.lang.String input)
      Converts all of the characters of the input string to upper case according to the semantics of method String#toUpperCase().
      static java.lang.String trim​(java.lang.String input)
      removes whitespace from both ends of a string according to the semantics of String#trim().
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Functions

        public Functions()
    • Method Detail

      • toUpperCase

        public static java.lang.String toUpperCase​(java.lang.String input)
        Converts all of the characters of the input string to upper case according to the semantics of method String#toUpperCase().
        Parameters:
        input - the input string on which the transformation to upper case is applied
        Returns:
        the input string transformed to upper case
      • toLowerCase

        public static java.lang.String toLowerCase​(java.lang.String input)
        Converts all of the characters of the input string to lower case according to the semantics of method String#toLowerCase().
        Parameters:
        input - the input string on which the transformation to lower case is applied
        Returns:
        the input string transformed to lower case
      • indexOf

        public static int indexOf​(java.lang.String input,
                                  java.lang.String substring)
        Returns the index (0-based) withing a string of the first occurrence of a specified substring according to the semantics of the method String#indexOf().

        If substring is empty, this matches the beginning of the string and the value returned is 0.

        Parameters:
        input - the input string on which the function is applied
        substring - the substring to search for in the input string
        Returns:
        the 0-based index of the first matching substring, or -1 if it does not occur
      • contains

        public static boolean contains​(java.lang.String input,
                                       java.lang.String substring)
        Tests if a string contains the specified substring.
        Parameters:
        input - the input string on which the function is applied
        substring - the substring tested for
        Returns:
        true if the character sequence represented by the substring exists in the string
      • containsIgnoreCase

        public static boolean containsIgnoreCase​(java.lang.String input,
                                                 java.lang.String substring)
        Tests if a string contains the specified substring in a case insensitive way. Equivalent to fn:contains(fn:toUpperCase(string), fn:toUpperCase(substring)).
        Parameters:
        input - the input string on which the function is applied
        substring - the substring tested for
        Returns:
        true if the character sequence represented by the substring exists in the string
      • startsWith

        public static boolean startsWith​(java.lang.String input,
                                         java.lang.String prefix)
        Tests if a string starts with the specified prefix according to the semantics of String#startsWith().
        Parameters:
        input - the input string on which the function is applied
        prefix - the prefix to be matched
        Returns:
        true if the input string starts with the prefix
      • endsWith

        public static boolean endsWith​(java.lang.String input,
                                       java.lang.String suffix)
        Tests if a string ends with the specified suffix according to the semantics of String#endsWith().
        Parameters:
        input - the input string on which the function is applied
        suffix - the suffix to be matched
        Returns:
        true if the input string ends with the suffix
      • substring

        public static java.lang.String substring​(java.lang.String input,
                                                 int beginIndex,
                                                 int endIndex)
        Returns a subset of a string according to the semantics of String#substring() with additional semantics as follows:
        • if beginIndex < 0 its value is adjusted to 0
        • if endIndex < 0 or greater than the string length, its value is adjusted to the length of the string
        • if endIndex < beginIndex, an empty string is returned
        Parameters:
        input - the input string on which the substring function is applied
        beginIndex - the beginning index (0-based), inclusive
        endIndex - the end index (0-based), exclusive
        Returns:
        a subset of string
      • substringAfter

        public static java.lang.String substringAfter​(java.lang.String input,
                                                      java.lang.String substring)
        Returns a subset of a string following the first occurrence of a specific substring.

        If the substring is empty, it matches the beginning of the input string and the entire input string is returned. If the substring does not occur, an empty string is returned.

        Parameters:
        input - the input string on which the substring function is applied
        substring - the substring that delimits the beginning of the subset of the input string to be returned
        Returns:
        a substring of the input string that starts at the first character after the specified substring
      • substringBefore

        public static java.lang.String substringBefore​(java.lang.String input,
                                                       java.lang.String substring)
        Returns a subset of a string immediately before the first occurrence of a specific substring.

        If the substring is empty, it matches the beginning of the input string and an empty string is returned. If the substring does not occur, an empty string is returned.

        Parameters:
        input - the input string on which the substring function is applied
        substring - the substring that delimits the beginning of the subset of the input string to be returned
        Returns:
        a substring of the input string that starts at the first character after the specified substring
      • escapeXml

        public static java.lang.String escapeXml​(java.lang.String input)
        Escapes characters that could be interpreted as XML markup as defined by the <c:out> action.
        Parameters:
        input - the string to escape
        Returns:
        escaped string
      • trim

        public static java.lang.String trim​(java.lang.String input)
        removes whitespace from both ends of a string according to the semantics of String#trim().
        Parameters:
        input - the input string to be trimmed
        Returns:
        the trimmed string
      • replace

        public static java.lang.String replace​(java.lang.String input,
                                               java.lang.String before,
                                               java.lang.String after)
        Returns a string resulting from replacing all occurrences of a "before" substring with an "after" substring. The string is processed once and not reprocessed for further replacements.
        Parameters:
        input - the string on which the replacement is to be applied
        before - the substring to replace
        after - the replacement substring
        Returns:
        a string with before replaced with after
      • split

        public static java.lang.String[] split​(java.lang.String input,
                                               java.lang.String delimiters)
        Splits a string into an array of substrings according to the semantics of StringTokenizer. If the input string is empty, a single element array containing an empty string is returned. If the delimiters are empty, a single element array containing the input string is returned.
        Parameters:
        input - the string to split
        delimiters - characters used to split the string
        Returns:
        an array of strings
      • join

        public static java.lang.String join​(java.lang.String[] array,
                                            java.lang.String separator)
        Joins all elements of an array into a string.

        Implementation Note: The specification does not define what happens when elements in the array are null. For compatibility with previous implementations, the string "null" is used although EL conventions would suggest an empty string might be better.

        Parameters:
        array - an array of strings to be joined
        separator - used to separate the joined strings
        Returns:
        all array elements joined into one string with the specified separator
      • length

        public static int length​(java.lang.Object obj)
                          throws JspTagException
        Returns the number of items in a collection or the number of characters in a string. The collection can be of any type supported for the items attribute of the <c:forEach> action.
        Parameters:
        obj - the collection or string whose length should be computed
        Returns:
        the length of the collection or string; 0 if obj is null
        Throws:
        JspTagException - if the type is not valid