public class Functions extends 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(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() . |
public static String toUpperCase(String input)
String#toUpperCase()
.input
- the input string on which the transformation to upper case is appliedpublic static String toLowerCase(String input)
String#toLowerCase()
.input
- the input string on which the transformation to lower case is appliedpublic static int indexOf(String input, 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(String input, String substring)
input
- the input string on which the function is appliedsubstring
- the substring tested forpublic static boolean containsIgnoreCase(String input, 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(String input, String prefix)
String#startsWith()
.input
- the input string on which the function is appliedprefix
- the prefix to be matchedpublic static boolean endsWith(String input, String suffix)
String#endsWith()
.input
- the input string on which the function is appliedsuffix
- the suffix to be matchedpublic static String substring(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 String substringAfter(String input, 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 String substringBefore(String input, 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 String escapeXml(String input)
<c:out> action.
input
- the string to escapepublic static String trim(String input)
String#trim()
.input
- the input string to be trimmedpublic static String replace(String input, String before, String after)
input
- the string on which the replacement is to be appliedbefore
- the substring to replaceafter
- the replacement substringpublic static String[] split(String input, 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 String join(String[] array, 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(Object obj) throws JspTagException
items
attribute of
the <c:forEach>
action.obj
- the collection or string whose length should be computedJspTagException
- if the type is not validCopyright © 2016 JBoss by Red Hat. All rights reserved.