org.apache.taglibs.standard.functions
Class Functions

java.lang.Object
  extended by org.apache.taglibs.standard.functions.Functions

public class Functions
extends 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.

Author:
Pierre Delisle

Constructor Summary
Functions()
           
 
Method Summary
static boolean contains(String input, String substring)
          Tests if a string contains the specified substring.
static boolean containsIgnoreCase(String input, String substring)
          Tests if a string contains the specified substring in a case insensitive way.
static boolean endsWith(String input, String suffix)
          Tests if a string ends with the specified suffix according to the semantics of String#endsWith().
static String escapeXml(String input)
          Escapes characters that could be interpreted as XML markup as defined by the <c:out> action.
static int indexOf(String input, 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 String join(String[] array, String separator)
          Joins all elements of an array into a string.
static int length(Object obj)
          Returns the number of items in a collection or the number of characters in a string.
static String replace(String input, String before, String after)
          Returns a string resulting from replacing all occurrences of a "before" substring with an "after" substring.
static String[] split(String input, String delimiters)
          Splits a string into an array of substrings according to the semantics of StringTokenizer.
static boolean startsWith(String input, String prefix)
          Tests if a string starts with the specified prefix according to the semantics of String#startsWith().
static String substring(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 String substringAfter(String input, String substring)
          Returns a subset of a string following the first occurrence of a specific substring.
static String substringBefore(String input, String substring)
          Returns a subset of a string immediately before the first occurrence of a specific substring.
static String toLowerCase(String input)
          Converts all of the characters of the input string to lower case according to the semantics of method String#toLowerCase().
static String toUpperCase(String input)
          Converts all of the characters of the input string to upper case according to the semantics of method String#toUpperCase().
static String trim(String input)
          removes whitespace from both ends of a string according to the semantics of String#trim().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Functions

public Functions()
Method Detail

toUpperCase

public static String toUpperCase(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 String toLowerCase(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(String input,
                          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(String input,
                               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(String input,
                                         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(String input,
                                 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(String input,
                               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 String substring(String input,
                               int beginIndex,
                               int endIndex)
Returns a subset of a string according to the semantics of String#substring() with additional semantics as follows:

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 String substringAfter(String input,
                                    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 String substringBefore(String input,
                                     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 String escapeXml(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 String trim(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 String replace(String input,
                             String before,
                             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 String[] split(String input,
                             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 String join(String[] array,
                          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(Object obj)
                  throws javax.servlet.jsp.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:
javax.servlet.jsp.JspTagException - if the type is not valid


Copyright © 2001-2015 The Apache Software Foundation. All Rights Reserved.