Class Functions


  • public final class Functions
    extends Object
    Methods exposed for EL usage.
    • Method Detail

      • array

        public static String[] array​(String... values)
        Create an array of String based on the strings given as parameters.
        Parameters:
        values - the strings to put in the array.
        Returns:
        the array of strings.
      • integer

        public static Integer integer​(String value)
        Transforms a String to an Integer. If the parameter is not a valid integer (in radix 10) then it returns null.
        Parameters:
        value - the String containing the integer representation to be parsed
        Returns:
        the integer represented by the string argument in the radix 10.
      • integerWithRadix

        public static Integer integerWithRadix​(String value,
                                               int radix)
        Transforms a String to an Integer. If the parameter is not a valid integer then it returns null.
        Parameters:
        value - the String containing the integer representation to be parsed
        radix - the radix to be used while parsing s.
        Returns:
        the integer represented by the string argument in the specified radix.
      • bool

        public static Boolean bool​(String value)
        Transforms a String to an Boolean. The rules for the transformation are the same as the ones described on Boolean.valueOf(String).
        Parameters:
        value - the String containing the boolean representation to be parsed
        Returns:
        the boolean represented by the string argument.
      • contains

        public static boolean contains​(Object object,
                                       Object value)
        Returns true if the object contains the value.
        Parameters:
        object - the object to be searched.
        value - the value to find.
        Returns:
        the length of the object, or 0 if length could not be determined.
      • indexOf

        public static int indexOf​(String value,
                                  String substring)
        Returns the index within a string of the first occurrence of a specified substring.
        Parameters:
        value - the string to be searched.
        substring - the value to search for within the string
        Returns:
        the index of the first instance of substring, or -1 if not found.
      • join

        public static String join​(Object values,
                                  String separator)
        Joins an array or Iterable values into a single string value, using the toString() result from each value and separated by the specified separator.
        Parameters:
        separator - the separator to place between joined elements.
        values - the values to be joined.
        Returns:
        the string containing the joined values.
      • keyMatch

        public static String keyMatch​(Object map,
                                      String pattern)
        Returns the first key found in a map that matches the specified regular expression pattern, or null if no such match is found.
        Parameters:
        map - the map whose keys are to be searched.
        pattern - a string containing the regular expression pattern to match.
        Returns:
        the first matching key, or null if no match found.
      • length

        public static int length​(Object value)
        Returns the number of items in a collection, or the number of characters in a string.
        Parameters:
        value - the object whose length is to be determined.
        Returns:
        the length of the object, or 0 if length could not be determined.
      • matches

        @Deprecated(since="7.2.0",
                    forRemoval=true)
        public static boolean matches​(String value,
                                      String pattern)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 7.2.0, with OPENIG-5793. Use find(String, String) or matchesWithRegex(String, String) instead.
        Returns true if the string contains the specified regular expression pattern.
        Parameters:
        value - the string to be searched.
        pattern - a string containing the regular expression pattern to find.
        Returns:
        true if the string contains the specified regular expression pattern.
      • find

        public static boolean find​(String input,
                                   String regex)
        Attempts to find the next subsequence of the input sequence that matches the regular expression.
        Parameters:
        input - The input on which the regular expression must apply.
        regex - A string containing the regular expression.
        Returns:
        true if the regular expression is found in the given input, false if the input is null or if the regular expression does not match.
        See Also:
        Matcher.find()
      • matchesWithRegex

        public static boolean matchesWithRegex​(String input,
                                               String regex)
        Returns true if the string matches the specified regular expression pattern.
        Parameters:
        input - The input on which the regular expression must apply.
        regex - A string containing the regular expression.
        Returns:
        true if the string contains the specified regular expression pattern, false if the input is null or if the regular expression does not match.
      • matchingGroups

        @Deprecated(since="7.2.0",
                    forRemoval=true)
        public static String[] matchingGroups​(String value,
                                              String pattern)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 7.2.0, with OPENIG-5957. Use findGroups(String, String) instead.
        Returns an array containing the matches of a regular expression pattern against a string, or null if no match is found. The first element of the array is the entire match, and each subsequent element correlates to any capture group specified within the regular expression.
        Parameters:
        value - the string to be searched.
        pattern - a string containing the regular expression pattern to match.
        Returns:
        an array of matches, or null if no match found.
      • findGroups

        public static String[] findGroups​(String input,
                                          String regex)
        Returns an array containing the result of a find on a regular expression against a string, or null if no result is found. The first element of the array is the entire match, and each subsequent element correlates to any capture group specified within the regular expression.
        Parameters:
        input - The string to be searched.
        regex - A string containing the regular expression regex to find.
        Returns:
        an array of the found matches, or null if no match found.
        See Also:
        Matcher.find()
      • split

        public static String[] split​(String value,
                                     String regex)
        Splits a string into an array of substrings around matches of the given regular expression.
        Parameters:
        value - the string to be split.
        regex - the regular expression to split substrings around.
        Returns:
        the resulting array of split substrings.
      • toJson

        public static Object toJson​(String value)
        Parse/Un-marshal the input String into a JSON structure.
        Parameters:
        value - The stringified-JSON.
        Returns:
        an un-marshalled JSON structure or null if anything went wrong during parsing.
      • toLowerCase

        public static String toLowerCase​(String value)
        Converts all of the characters in a string to lower case.
        Parameters:
        value - the string whose characters are to be converted.
        Returns:
        the string with characters converted to lower case.
      • toString

        public static String toString​(Object value)
        Returns the string value of an arbitrary object.
        Parameters:
        value - the object whose string value is to be returned.
        Returns:
        the string value of the object.
      • toUpperCase

        public static String toUpperCase​(String value)
        Converts all of the characters in a string to upper case.
        Parameters:
        value - the string whose characters are to be converted.
        Returns:
        the string with characters converted to upper case.
      • trim

        public static String trim​(String value)
        Returns a copy of a string with leading and trailing whitespace omitted.
        Parameters:
        value - the string whose white space is to be omitted.
        Returns:
        the string with leading and trailing white space omitted.
      • urlEncode

        public static String urlEncode​(String value)
        Returns the URL encoding of the provided string.
        Parameters:
        value - the string to be URL encoded, which may be null.
        Returns:
        the URL encoding of the provided string, or null if string was null.
      • urlDecode

        public static String urlDecode​(String value)
        Returns the URL decoding of the provided string.
        Parameters:
        value - the string to be URL decoded, which may be null.
        Returns:
        the URL decoding of the provided string, or null if string was null.
      • encodeBase64

        public static String encodeBase64​(Object value)
        Encode the given String input into Base64.
        Parameters:
        value - the object to be base64 encoded, which may be null a CharSequence or a byte[].
        Returns:
        the Base64 encoding of the provided string, or null if string was null.
      • decodeBase64

        public static String decodeBase64​(String value)
        Decode the given Base64 String input.
        Parameters:
        value - the string to be Base64 decoded, which may be null.
        Returns:
        the decoding of the provided string, or null if string was null or if the input was not a Base64 valid input.
      • encodeBase64url

        public static String encodeBase64url​(Object value)
        Encode the given String input into Base64url.
        Parameters:
        value - the object to be Base64url encoded, which may be null a CharSequence or a byte[].
        Returns:
        the Base64url encoding of the provided string, or null if string was null.
      • decodeBase64url

        public static String decodeBase64url​(String value)
        Decode the given Base64url String input.
        Parameters:
        value - the string to be Base64url decoded, which may be null.
        Returns:
        the decoding of the provided string, or null if string was null or if the input was not a Base64url valid input.
      • read

        public static String read​(String filename)
        Returns the content of the given file as a plain String.
        Parameters:
        filename - file to be read
        Returns:
        the file content as a String or null if here was an error (missing file, ...)
      • readWithCharset

        public static String readWithCharset​(String filename,
                                             Charset charset)
        Returns the content of the given file as a plain String using a specific Charset.
        Parameters:
        filename - The file to read.
        charset - The Charset to use to read that file.
        Returns:
        The file contente as a String or null if an error occurred.
      • readProperties

        public static Properties readProperties​(String filename)
        Returns the content of the given file as a Properties.
        Parameters:
        filename - file to be read
        Returns:
        the file content as Properties or null if here was an error (missing file, ...)
      • pathToUrl

        public static String pathToUrl​(String path)
        Returns the String representation of the URL denoting the given path.
        Parameters:
        path - the path to build the URL from.
        Returns:
        the String representation of the URL denoting the given path.
      • fileToUrl

        public static String fileToUrl​(File file)
        Returns the String representation of the URL denoting the given file.
        Parameters:
        file - the file to build the URL from.
        Returns:
        the String representation of the URL denoting the given file.
      • pemCertificate

        public static Certificate pemCertificate​(Object incoming)
        Convert the incoming CharSequence, which is expected to be a PEM format certificate, into a certificate.
        Parameters:
        incoming - The incoming CharSequence
        Returns:
        The certificate or null if incoming is either null, not a CharSequence, empty or if certificate reconstruction failed for any reason.
      • digestSha256

        public static byte[] digestSha256​(Object incoming)
        Calculate the SHA256 hash of the incoming object, which may be a byte array or a string.
        Parameters:
        incoming - The incoming object, which may be a byte array or a CharSequence (anything else returns null).
        Returns:
        The SHA256 hash as an array of byte, or null if the hash could not be calculated.
      • ipMatch

        public static boolean ipMatch​(String ip,
                                      String ipPattern)
        Matches an IP (either v4 or v6) with a IP range using the Classless inter-domain routing (CIDR) formalism.
        Parameters:
        ip - the IP to check (either v4 or v6)
        ipPattern - the CIDR pattern defining an IP range.
        Returns:
        whether the IP is included in the specified IP range or not.