public class Functions
extends java.lang.Object
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 and Description |
---|
Functions() |
Modifier and Type | Method and 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() . |
public static java.lang.String toUpperCase(java.lang.String input)
String#toUpperCase()
.input
- the input string on which the transformation to upper case is appliedpublic static java.lang.String toLowerCase(java.lang.String input)
String#toLowerCase()
.input
- the input string on which the transformation to lower case is appliedpublic static int indexOf(java.lang.String input, java.lang.String substring)
String#indexOf()
.
If substring
is empty, this matches the beginning of the string and the
value returned is 0.
input
- the input string on which the function is appliedsubstring
- the substring to search for in the input stringpublic static boolean contains(java.lang.String input, java.lang.String substring)
input
- the input string on which the function is appliedsubstring
- the substring tested forpublic static boolean containsIgnoreCase(java.lang.String input, java.lang.String substring)
fn:contains(fn:toUpperCase(string), fn:toUpperCase(substring))
.input
- the input string on which the function is appliedsubstring
- the substring tested forpublic static boolean startsWith(java.lang.String input, java.lang.String prefix)
String#startsWith()
.input
- the input string on which the function is appliedprefix
- the prefix to be matchedpublic static boolean endsWith(java.lang.String input, java.lang.String suffix)
String#endsWith()
.input
- the input string on which the function is appliedsuffix
- the suffix to be matchedpublic static java.lang.String substring(java.lang.String input, int beginIndex, int endIndex)
String#substring()
with additional semantics as follows:
beginIndex < 0
its value is adjusted to 0endIndex < 0 or greater than the string length
,
its value is adjusted to the length of the stringendIndex < beginIndex
, an empty string is returnedinput
- the input string on which the substring function is appliedbeginIndex
- the beginning index (0-based), inclusiveendIndex
- the end index (0-based), exclusivepublic static java.lang.String substringAfter(java.lang.String input, java.lang.String 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.
input
- the input string on which the substring function is appliedsubstring
- the substring that delimits the beginning of the subset
of the input string to be returnedpublic static java.lang.String substringBefore(java.lang.String input, java.lang.String 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.
input
- the input string on which the substring function is appliedsubstring
- the substring that delimits the beginning of the subset
of the input string to be returnedpublic static java.lang.String escapeXml(java.lang.String input)
<c:out> action.
input
- the string to escapepublic static java.lang.String trim(java.lang.String input)
String#trim()
.input
- the input string to be trimmedpublic static java.lang.String replace(java.lang.String input, java.lang.String before, java.lang.String after)
input
- the string on which the replacement is to be appliedbefore
- the substring to replaceafter
- the replacement substringpublic static java.lang.String[] split(java.lang.String input, java.lang.String delimiters)
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.input
- the string to splitdelimiters
- characters used to split the stringpublic static java.lang.String join(java.lang.String[] array, java.lang.String separator)
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.
array
- an array of strings to be joinedseparator
- used to separate the joined stringspublic static int length(java.lang.Object obj) throws javax.servlet.jsp.JspTagException
items
attribute of
the <c:forEach>
action.obj
- the collection or string whose length should be computedjavax.servlet.jsp.JspTagException
- if the type is not valid