The String taglibrary provides a host of tags for manipulating java.lang.Strings. The style is that the String to act upon is the body of the tag, and attributes are used as parameters for the manipulation.
This taglib is currently built on top of the Lang 2.0 component from Jakarta Commons. In addition a servlet container is required that supports the JavaServer Pages Specification, version 1.1 or higher.
Follow these steps to configure your web application with this tag library:
<taglib> <taglib-uri>http://jakarta.apache.org/taglibs/string-1.1</taglib-uri> <taglib-location>/WEB-INF/string.tld</taglib-location> </taglib>
To use the tags from this library in your JSP pages, add the following directive at the top of each page:
<%@ taglib uri="http://jakarta.apache.org/taglibs/string-1.1" prefix="str" %>
where "str" is the tag name prefix you wish to use for tags from this library. You can change this value to any prefix you like.
length | Return the length of a String. An empty string is returned for a null String if one should somehow be passed in. |
capitalize | Capitalize a String. The first character is converted to TitleCase. |
uncapitalize | Change the first letter of a String to Lowercase. |
upperCase | Turn the entire String to uppercase. Delegates to java.lang.String, so no idea if it uses Titlecase when it's supposed to. |
lowerCase | Turn all uppercase and titlecase characters to lowercase. |
trim | Remove whitespace from start and end of a String. |
chop | Remove the last character from a String. If it is a \n and a \r precedes it, then remove that too. |
chopNewline | Remove a \n from the end of a String if it is there. If a \r precedes it, then it removes that too. |
escape | Escape a String into a Java-compatible String. Handles unicode, and the standard escapes: \t, \b, \n, \f, \r, \\, \", \' |
reverse | Reverse a String. |
swapCase | Swap the casing in a String. Lowercase goes to Uppercase or Titlecase depending on whether they are the first in the String or after whitespace. Uppercase and Titlecase go to Lowercase |
soundex | Return the US_ENGLISH Soundex of a String. |
metaphone | Get the metaphone for a String. This is an improved variant of SoundEx. |
quoteRegexp | Quote a String so that it will pass through a regular expression as a constant. |
capitalizeAllWords | Capitalize all the words found in a piece of body text. Capitalization is performed upon any letters following whitespace, and on the first character. |
removeXml | Remove any XML tags from a String. A very simple algorithm which just removes any <..> blocks of text. |
encodeUrl | Encode a String to that it may be used as a URL. Note: accented characters may not be encoded correctly, but there is not we can do about it (a solution would be passing the encoding as an attribute, but that would require a J2SE 1.4 environment). |
decodeUrl | Decode a URL so it may be nicely printed. Note: accented characters may not be encoded correctly, but there is not we can do about it (a solution would be passing the encoding as an attribute, but that would require a J2SE 1.4 environment). |
count | Count the number of occurences of a passed in 'Set'. A Set is a String of a particular format. It may include ranges and single characters. A Set may be negated. range - "a-z" char - "a" negate - "^a" |
delete | Delete any characters from the body that match characters specified in the Set. The syntax of a Set is described in Count. |
squeeze | Squeeze any characters from the body that match characters specified in the Set. Squeezing means that if it finds two adjoining characters that are the same, they are replaced with a single one of the characters. The syntax of a Set is described in the Count tag. |
center | Center the body String in a larger String of size width. |
rightPad | Right pad a string with a particular delimiter to a specified width. The width includes the size of the string. |
leftPad | Left pad a string with a particular delimiter to a specified width. The width includes the size of the string. |
chomp | Remove the last occurence of a specified character, and everything after it. |
getChomp | Get everything after a specified delimiter. Returns the delimiter as well. |
prechomp | Remove everything up until a specified delimiter, and that specified delimiter from the start of a String. |
getPrechomp | Get everything up until a specific delimiter. Returns the delimiter as well. |
strip | Strip all of a specified character which appear at the start and end of a String. |
stripEnd | Strip all of a specified character which appear at the end of a String. |
stripStart | Strip all of a specified character which appear at the start of a String. |
reverseDelimitedString | Reverses a delimited String. One example would be changing org.apache.taglib to taglib.apache.org. The delimiter to use is settable. |
overlay | Overlay a String on top of another String. The length of the String to overlay does not have to be the same as the size of substring it replaces. |
substring | Get a specified substring from a larger String based on the start index and end-before index in the larger String |
repeat | Repeat a string a particular number of times. |
wordWrap | Word-wrap a String. This involves formatting a long String to fit within a certain character width of page. A delimiter may be passed in to put at the end of each line and a splitting character can be specified for when a word has to be cut in half. |
nestedString | Get a String that is nested between an open and closing substring. |
countMatches | Return the number of times that the body String contains the sub-string. |
default | If the body String is a particular value, then output a default value, else output the body String. The major use of this is to convert 'null' into an empty String. |
replace | Replace a specified substring with another string. A number of times may be specified to say how many times to replace the substring. |
randomString | Create a random string. It can create an ascii string, a numeric string, an alphanumeric string, and a unicode string. The size of the string may be specified, as can a start and end character. Lastly, a set of characters to use may be passed in. |
left | Get the leftmost 'n' characters from a string. |
right | Get the rightmost 'n' characters from a string. |
mid | Get 'n' characters from the inside of a string. The start position may be set, or the default may be used. The default is to get the central characters. |
truncateNicely | A more intelligent substring. It attempts to cut off a string after a space, following predefined or user-supplied lower and upper limits, useful for making short descriptions from long text. It strips the HTML out as a part of the code. Patches on a version which doesn't strip the HTML will be gratefully received. |
join | Joins the elements of the provided array. |
split | Splits the provided text into an array, separators specified. The separator is not included in the returned String array and adjacent separators are treated as one separator. |
length | Availability: 1.2 | ||||
Return the length of a String. An empty string is returned for a null String if one should somehow be passed in. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.2 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
capitalize | Availability: 1.0 | ||||
Capitalize a String. The first character is converted to TitleCase. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
uncapitalize | Availability: 1.0 | ||||
Change the first letter of a String to Lowercase. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
upperCase | Availability: 1.0 | ||||
Turn the entire String to uppercase. Delegates to java.lang.String, so no idea if it uses Titlecase when it's supposed to. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
lowerCase | Availability: 1.0 | ||||
Turn all uppercase and titlecase characters to lowercase. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
trim | Availability: 1.0 | ||||
Remove whitespace from start and end of a String. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
chop | Availability: 1.0 | ||||
Remove the last character from a String. If it is a \n and a \r precedes it, then remove that too. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
chopNewline | Availability: 1.0 | ||||
Remove a \n from the end of a String if it is there. If a \r precedes it, then it removes that too. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
escape | Availability: 1.0 | ||||
Escape a String into a Java-compatible String. Handles unicode, and the standard escapes: \t, \b, \n, \f, \r, \\, \", \' |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
reverse | Availability: 1.0 | ||||
Reverse a String. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
swapCase | Availability: 1.0 | ||||
Swap the casing in a String. Lowercase goes to Uppercase or Titlecase depending on whether they are the first in the String or after whitespace. Uppercase and Titlecase go to Lowercase |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
soundex | Availability: 1.0 | ||||
Return the US_ENGLISH Soundex of a String. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
metaphone | Availability: 1.0 | ||||
Get the metaphone for a String. This is an improved variant of SoundEx. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
quoteRegexp | Availability: 1.0 | ||||
Quote a String so that it will pass through a regular expression as a constant. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | None |
capitalizeAllWords | Availability: 1.0 | ||||
Capitalize all the words found in a piece of body text. Capitalization is performed upon any letters following whitespace, and on the first character. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | Will output: "Some Form Of Lower Case Sentence" | ||||
|
removeXml | Availability: 1.0 | ||||
Remove any XML tags from a String. A very simple algorithm which just removes any <..> blocks of text. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | All it currently does is strip any <xx> tags out. It doesn't check that the tags are correct xml and it would be confused by < or > signs inside a tag attribute. | ||||
|
encodeUrl | Availability: 1.0 | ||||
Encode a String to that it may be used as a URL. Note: accented characters may not be encoded correctly, but there is not we can do about it (a solution would be passing the encoding as an attribute, but that would require a J2SE 1.4 environment). |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | Especially useful if database output is being put into an <a href=".."> | ||||
|
decodeUrl | Availability: 1.0 | ||||
Decode a URL so it may be nicely printed. Note: accented characters may not be encoded correctly, but there is not we can do about it (a solution would be passing the encoding as an attribute, but that would require a J2SE 1.4 environment). |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | Useful in parallel with its counterpart. If a database contains the URL in encoded form, then this could be used to show a human readable version. | ||||
|
count | Availability: 1.0 | ||||
Count the number of occurences of a passed in 'Set'. A Set is a String of a particular format. It may include ranges and single characters. A Set may be negated.
|
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
set | Yes | Yes | 1.0 | ||
Character Set to look for. |
|||||
Variables | None | ||||
Examples | There is 1 a, 2 e's and no f's. So the result is 3. | ||||
|
delete | Availability: 1.0 | ||||
Delete any characters from the body that match characters specified in the Set. The syntax of a Set is described in Count. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
set | Yes | Yes | 1.0 | ||
Character Set to look for. |
|||||
Variables | None | ||||
Examples | Will output: 'Som smpl txt to dlt rom' | ||||
|
squeeze | Availability: 1.0 | ||||
Squeeze any characters from the body that match characters specified in the Set. Squeezing means that if it finds two adjoining characters that are the same, they are replaced with a single one of the characters. The syntax of a Set is described in the Count tag. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
set | Yes | Yes | 1.0 | ||
Character Set to look for. |
|||||
Variables | None | ||||
Examples | Will output: 'Some sample text to squeeze' | ||||
|
center | Availability: 1.0 | ||||
Center the body String in a larger String of size width. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
delimiter | No | Yes | 1.0 | ||
String to pad the larger String with. Default is a space character. |
|||||
width | Yes | Yes | 1.0 | ||
Size of larger String. |
|||||
Variables | None | ||||
Examples | Outputs a header with 'The Title' embedded in a bunch of - characters. | ||||
|
rightPad | Availability: 1.0 | ||||
Right pad a string with a particular delimiter to a specified width. The width includes the size of the string. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
delimiter | No | Yes | 1.0 | ||
String to pad the larger String with. Default is a space character. |
|||||
width | Yes | Yes | 1.0 | ||
Size of larger String. |
|||||
Variables | None | ||||
Examples | Will output: 'An arrow------->' | ||||
|
leftPad | Availability: 1.0 | ||||
Left pad a string with a particular delimiter to a specified width. The width includes the size of the string. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
delimiter | No | Yes | 1.0 | ||
String to pad the larger String with. Default is a space character. |
|||||
width | Yes | Yes | 1.0 | ||
Size of larger String. |
|||||
Variables | None | ||||
Examples | Will output: '<-------An arrow>' | ||||
|
chomp | Availability: 1.0 | ||||
Remove the last occurence of a specified character, and everything after it. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
delimiter | No | Yes | 1.0 | ||
Character to remove after. Default is a newline character. |
|||||
Variables | None | ||||
Examples | One use could be to remove # and // comments from code when outputted. | ||||
|
getChomp | Availability: 1.0 | ||||
Get everything after a specified delimiter. Returns the delimiter as well. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
delimiter | No | Yes | 1.0 | ||
Character to get text after. Default is a newline character. |
|||||
Variables | None | ||||
Examples | Similarily to its counterpart, this could be used to get the comments from a piece of code. | ||||
|
prechomp | Availability: 1.0 | ||||
Remove everything up until a specified delimiter, and that specified delimiter from the start of a String. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
delimiter | No | Yes | 1.0 | ||
Character to remove before. Default is a newline character. |
|||||
Variables | None | ||||
Examples | Again, this could be used to get the comment from a piece of code. However it would not include the delimiter as getChomp would. | ||||
|
getPrechomp | Availability: 1.0 | ||||
Get everything up until a specific delimiter. Returns the delimiter as well. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
delimiter | No | Yes | 1.0 | ||
Character to get text before. Default is a newline character. |
|||||
Variables | None | ||||
Examples | In the code comment theme, this would return the code but include the comment character itself. | ||||
|
strip | Availability: 1.0 | ||||
Strip all of a specified character which appear at the start and end of a String. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
delimiter | No | Yes | 1.0 | ||
Character to remove from start and end of body. Default is a isWhitespace() character. |
|||||
Variables | None | ||||
Examples | Default is isWhitespace, that is tab or newline or space character. | ||||
|
stripEnd | Availability: 1.0 | ||||
Strip all of a specified character which appear at the end of a String. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
delimiter | No | Yes | 1.0 | ||
Character to remove from end of body. Default is a isWhitespace() character. |
|||||
Variables | None | ||||
Examples | |||||
|
stripStart | Availability: 1.0 | ||||
Strip all of a specified character which appear at the start of a String. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
delimiter | No | Yes | 1.0 | ||
Character to remove from start of body. Default is a isWhitespace() character. |
|||||
Variables | None | ||||
Examples | |||||
|
reverseDelimitedString | Availability: 1.0 | ||||
Reverses a delimited String. One example would be changing org.apache.taglib to taglib.apache.org. The delimiter to use is settable. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
delimiter | No | Yes | 1.0 | ||
Character to use as the delimiter in the qualified name. Default is a dot character. |
|||||
Variables | None | ||||
Examples | Major use is to turn domain names into java package names. Bound to be other uses. | ||||
|
overlay | Availability: 1.0 | ||||
Overlay a String on top of another String. The length of the String to overlay does not have to be the same as the size of substring it replaces. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
with | Yes | Yes | 1.0 | ||
String to overlay onto the body. |
|||||
start | Yes | Yes | 1.0 | ||
Start index. |
|||||
end | Yes | Yes | 1.0 | ||
Index to end before. |
|||||
Variables | None | ||||
Examples | 'pond' will be replaced by 'tree' | ||||
|
substring | Availability: 1.0 | ||||
Get a specified substring from a larger String based on the start index and end-before index in the larger String |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
start | No | Yes | 1.0 | ||
Start index. May be negative, which means it is the index counting backwards from the end of the string. Default is 0. |
|||||
end | No | Yes | 1.0 | ||
Index to end before. May be negative, which means it is the index counting backwards from the end of the string. May also be longer than the length of the string, in which case it quietly sets it to the length of the string. |
|||||
Variables | None | ||||
Examples | Will get the substring 'tree' from the body. | ||||
|
repeat | Availability: 1.0 | ||||
Repeat a string a particular number of times. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
count | Yes | Yes | 1.0 | ||
Number of times to repeat the body. |
|||||
Variables | None | ||||
Examples | Will output 'xxxxx' | ||||
|
wordWrap | Availability: 1.0 | ||||
Word-wrap a String. This involves formatting a long String to fit within a certain character width of page. A delimiter may be passed in to put at the end of each line and a splitting character can be specified for when a word has to be cut in half. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
width | No | Yes | 1.0 | ||
Width to word wrap to. Default is 80. |
|||||
delimiter | No | Yes | 1.0 | ||
Character to put between each line. Default is a newline character. |
|||||
split | No | Yes | 1.0 | ||
Character to use when a word has to be split. Default is a - character. |
|||||
delimiterInside | No | No | 1.1 | ||
Flag indicating if the delimiter should be included in chunk before length reaches width. Default is true. |
|||||
Variables | None | ||||
Examples | |||||
|
nestedString | Availability: 1.0 | ||||
Get a String that is nested between an open and closing substring. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
open | Yes | Yes | 1.0 | ||
Index to start substring at. |
|||||
close | No | Yes | 1.0 | ||
Index to stop substring before. Default is the end of the string. |
|||||
Variables | None | ||||
Examples | Pluck's 'Bob' from out of the square brackets. | ||||
|
countMatches | Availability: 1.0 | ||||
Return the number of times that the body String contains the sub-string. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
substring | Yes | Yes | 1.0 | ||
Substring to count number of. |
|||||
Variables | None | ||||
Examples | The substring 'world' is repeated four times in the body. | ||||
|
default | Availability: 1.0 | ||||
If the body String is a particular value, then output a default value, else output the body String. The major use of this is to convert 'null' into an empty String. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
value | No | Yes | 1.0 | ||
Value to be equal to. Default is the string: "null". |
|||||
default | No | Yes | 1.0 | ||
Value to place if body is equal to value field. Default is an empty String. |
|||||
Variables | None | ||||
Examples | If the inner tag (db:get) return null (or the string "null") then an empty string will be printed out. | ||||
|
replace | Availability: 1.0 | ||||
Replace a specified substring with another string. A number of times may be specified to say how many times to replace the substring. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
replace | Yes | Yes | 1.0 | ||
Value to find to replace. |
|||||
with | Yes | Yes | 1.0 | ||
Value to replace with. |
|||||
count | No | Yes | 1.0 | ||
Number of times to replace. Default is all matches. |
|||||
newlineToken | No | Yes | 1.0.1 | ||
Token to use instead of a newline to get around JSP pain. Default is to ignore this functionality. |
|||||
carriageToken | No | Yes | 1.0.1 | ||
Token to use instead of a carriage return to get around JSP pain. Default is to ignore this functionality. |
|||||
Variables | None | ||||
Examples | One use of the replace tag is to change newlines to html br's. Note that real newlines need to be entered into the JSP. | ||||
|
randomString | Availability: 1.0 | ||||
Create a random string. It can create an ascii string, a numeric string, an alphanumeric string, and a unicode string. The size of the string may be specified, as can a start and end character. Lastly, a set of characters to use may be passed in. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
count | Yes | Yes | 1.0 | ||
Number of characters to generate. |
|||||
start | No | Yes | 1.0 | ||
Start of range of characters to generate from. Linked to type attribute. |
|||||
end | No | Yes | 1.0 | ||
End of range of characters to generate from. Linked to type attribute. |
|||||
type | No | Yes | 1.0 | ||
Type of random-string. One of: numeric | alphanumeric | alphabet | unicode. Default value is to unicode. |
|||||
Variables | None | ||||
Examples | The random tag has a lot of options. The easiest way is to just use the type field, as in the example. The second example shows how the developer can specify the characters to use, for example, random vowels. The last example is merely demonstrative, no one would want to do this, but it shows how the developer may specify the range of characters, in this example, all the control characters. | ||||
|
left | Availability: 1.0 | ||||
Get the leftmost 'n' characters from a string. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
count | Yes | Yes | 1.0 | ||
Number of characters to get. |
|||||
Variables | None | ||||
Examples | Will output: '<A long piece of>' | ||||
|
right | Availability: 1.0 | ||||
Get the rightmost 'n' characters from a string. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
count | Yes | Yes | 1.0 | ||
Number of characters to get. |
|||||
Variables | None | ||||
Examples | Will output: '<will get cut.>' | ||||
|
mid | Availability: 1.0 | ||||
Get 'n' characters from the inside of a string. The start position may be set, or the default may be used. The default is to get the central characters. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
start | No | Yes | 1.0 | ||
Position to start at. |
|||||
count | Yes | Yes | 1.0 | ||
Number of characters to get. |
|||||
Variables | None | ||||
Examples | Will output: '<text which>' | ||||
|
truncateNicely | Availability: 1.0 | ||||
A more intelligent substring. It attempts to cut off a string after a space, following predefined or user-supplied lower and upper limits, useful for making short descriptions from long text. It strips the HTML out as a part of the code. Patches on a version which doesn't strip the HTML will be gratefully received. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
var | No | Yes | 1.0 | ||
Variable to store result in. |
|||||
lower | No | Yes | 1.0 | ||
Mininum length to truncate at. |
|||||
upper | No | Yes | 1.0 | ||
Maximum length the string can be. Will force a truncate at this point. |
|||||
appendToEnd | No | Yes | 1.0 | ||
String to append to the end of the truncated string. |
|||||
Variables | None | ||||
Examples | Will output: '<The quick brown...>' | ||||
|
join | Availability: 1.1 | ||||
Joins the elements of the provided array. |
|||||
Tag Body | EMPTY | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
items | Yes | Yes | 1.1 | ||
Array of elements to be joined. |
|||||
separator | No | Yes | 1.1 | ||
Separator string to be used. |
|||||
Variables | None | ||||
Examples | Useful to join elements of a list. | ||||
|
split | Availability: 1.1 | ||||
Splits the provided text into an array, separators specified. The separator is not included in the returned String array and adjacent separators are treated as one separator. |
|||||
Tag Body | JSP | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
separator | Yes | Yes | 1.1 | ||
Separator string to be used. |
|||||
var | Yes | Yes | 1.0 | ||
Variable to store result in. |
|||||
Variables | None | ||||
Examples | This is the reverse of join and is the equivalent of StringTokenizer in a tag. | ||||
|
See the example application string-examples.war for examples of the usage of the tags from this custom tag library.
Java programmers can view the java class documentation for this tag library as javadocs.
Review the complete revision history of this tag library.