2010-04-14 - Jakarta Taglibs has been retired.

For more information, please explore the Attic.

Jakarta Project: String Tag library

Version: 1.1.0

Table of Contents

Overview

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.

Requirements

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.

Configuration

Follow these steps to configure your web application with this tag library:

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.

Tag Summary

String Tags
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.
 

Tag Reference

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 BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.2
 

Variable to store result in.

VariablesNone
ExamplesNone
capitalize Availability: 1.0

Capitalize a String. The first character is converted to TitleCase.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
uncapitalize Availability: 1.0

Change the first letter of a String to Lowercase.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
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 BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
lowerCase Availability: 1.0

Turn all uppercase and titlecase characters to lowercase.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
trim Availability: 1.0

Remove whitespace from start and end of a String.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
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 BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
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 BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
escape Availability: 1.0

Escape a String into a Java-compatible String. Handles unicode, and the standard escapes: \t, \b, \n, \f, \r, \\, \", \'

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
reverse Availability: 1.0

Reverse a String.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
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 BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
soundex Availability: 1.0

Return the US_ENGLISH Soundex of a String.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
metaphone Availability: 1.0

Get the metaphone for a String. This is an improved variant of SoundEx.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
quoteRegexp Availability: 1.0

Quote a String so that it will pass through a regular expression as a constant.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
ExamplesNone
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 BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
Examples Will output: "Some Form Of Lower Case Sentence"  
 


 
<str:capitalizeAllWords>some form of lower case sentence</str:capitalizeAllWords>
       
            

removeXml Availability: 1.0

Remove any XML tags from a String. A very simple algorithm which just removes any <..> blocks of text.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
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.  
 


 
<str:removeXml><name>John Brown</name></str:removeXml>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
Examples Especially useful if database output is being put into an <a href="..">  
 


 
<str:encodeUrl>http://www.apache.org/some file//page.html</str:encodeUrl>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

VariablesNone
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.  
 


 
<str:decodeUrl>http://www.apache.org/some+file%20/page.html</str:decodeUrl>
       
            

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.

  • range - "a-z"
  • char - "a"
  • negate - "^a"

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

 set  Yes   Yes  1.0
 

Character Set to look for.

VariablesNone
Examples There is 1 a, 2 e's and no f's. So the result is 3.  
 


 
<str:count set="aef">Some sample text to count</count>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

 set  Yes   Yes  1.0
 

Character Set to look for.

VariablesNone
Examples Will output: 'Som smpl txt to dlt rom'  
 


 
<str:delete set="aef">Some sample text to delete from</str:delete>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

 set  Yes   Yes  1.0
 

Character Set to look for.

VariablesNone
Examples Will output: 'Some sample text to squeeze'  
 


 
<str:squeeze set="xo">Some sample texxxt toooo squeeze</str:squeeze>
       
            

center Availability: 1.0

Center the body String in a larger String of size width.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples Outputs a header with 'The Title' embedded in a bunch of - characters.  
 


 
<str:center width="40" delimiter="-">The Title</str:center>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples Will output: 'An arrow------->'  
 


 
<str:rightPad width="15" delimiter="-">An arrow</str:rightPad>&gt;
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples Will output: '<-------An arrow>'  
 


 
&lt;<str:leftPad width="15" delimiter="-">An arrow</str:rightPad>
       
            

chomp Availability: 1.0

Remove the last occurence of a specified character, and everything after it.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples One use could be to remove # and // comments from code when outputted.  
 


 
<str:chomp delimiter="#">Some code; # A comment</str:chomp>
       
            

getChomp Availability: 1.0

Get everything after a specified delimiter. Returns the delimiter as well.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples Similarily to its counterpart, this could be used to get the comments from a piece of code.  
 


 
<str:getChomp delimiter="#">Some code; # A comment</str:getChomp>
       
            

prechomp Availability: 1.0

Remove everything up until a specified delimiter, and that specified delimiter from the start of a String.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
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.  
 


 
<str:prechomp delimiter="#">Some code; # A comment</str:prechomp>
       
            

getPrechomp Availability: 1.0

Get everything up until a specific delimiter. Returns the delimiter as well.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples In the code comment theme, this would return the code but include the comment character itself.  
 


 
<str:getPrechomp delimiter="#">Some code; # A comment</str:getPrechomp>
       
            

strip Availability: 1.0

Strip all of a specified character which appear at the start and end of a String.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples Default is isWhitespace, that is tab or newline or space character.  
 


 
<str:strip delimiter="-">---A Title---</str:strip>
       
            

stripEnd Availability: 1.0

Strip all of a specified character which appear at the end of a String.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples  
 


 
<str:stripEnd delimiter="-">A Title---</str:stripEnd>
       
            

stripStart Availability: 1.0

Strip all of a specified character which appear at the start of a String.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples  
 


 
<str:stripStart delimiter="-">---A Title</str:stripStart>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples Major use is to turn domain names into java package names. Bound to be other uses.  
 


 
<str:reverseDelimitedString delimiter=".">org.apache.taglib.string.String</str:reverseDelimitedString>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples 'pond' will be replaced by 'tree'  
 


 
<str:overlay with="tree" start="4" end="8">The pond was wet.</str:overlay>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples Will get the substring 'tree' from the body.  
 


 
<str:substring start="4" end="8">The tree is green.</str:substring>
       
            

repeat Availability: 1.0

Repeat a string a particular number of times.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples Will output 'xxxxx'  
 


 
<str:repeat count="5">x</str:repeat>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples  
 


 
<str:wordWrap width ="50" delimiter="&lt;br&gt;">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.</str:wordWrap>
       
            

nestedString Availability: 1.0

Get a String that is nested between an open and closing substring.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples Pluck's 'Bob' from out of the square brackets.  
 


 
<str:nestedString open="[" close="]">[Bob]</str:nestedString>
       
            

countMatches Availability: 1.0

Return the number of times that the body String contains the sub-string.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

 substring  Yes   Yes  1.0
 

Substring to count number of.

VariablesNone
Examples The substring 'world' is repeated four times in the body.  
 


 
<str:countMatches substring="world">Hello world programs are rife in this world due to their worldy view of how to program a world of code</str:countMatches>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples If the inner tag (db:get) return null (or the string "null") then an empty string will be printed out.  
 


 
<str:default><db:get value="Name"></str:default>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
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.  
 


 
<str:replace replace="
" with="&lt;br&gt;
">A sentence.
Another sentence.
Some more to test. And insert Br's into.
Hopefully.</str:replace>
       
_or_ with 1.0.1:
 
<str:replace replace="NL" with="&lt;br&gt;NL" newlineToken="NL">
A sentence.
Another sentence.
Some more to test. And insert Br's into.
Hopefully.</str:replace>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
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.  
 


 
<str:random count="10" type="alphanumeric"/>
<str:random count="1">aeiou</str:random>
<str:random count="5" start="1" end="32"/>
       
            

left Availability: 1.0

Get the leftmost 'n' characters from a string.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

 count  Yes   Yes  1.0
 

Number of characters to get.

VariablesNone
Examples Will output: '<A long piece of>'  
 


 
&lt;<str:left count="15">A long piece of text which will get cut.</str:rightPad>
       
            

right Availability: 1.0

Get the rightmost 'n' characters from a string.

Tag BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 var  No   Yes  1.0
 

Variable to store result in.

 count  Yes   Yes  1.0
 

Number of characters to get.

VariablesNone
Examples Will output: '<will get cut.>'  
 


 
&lt;<str:right count="13">A long piece of text which will get cut.</str:rightPad>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples Will output: '<text which>'  
 


 
&lt;<str:mid count="10">A long piece of text which will get cut.</str:rightPad>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples Will output: '<The quick brown...>'  
 


 
&lt;<str:truncateNicely lower="13" upper="20">The quick brown fox jumped over the lazy dog.</str:truncateNicely>
       
            

join Availability: 1.1

Joins the elements of the provided array.

Tag BodyEMPTY    
Restrictions

None

AttributesNameRequired 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.

VariablesNone
Examples Useful to join elements of a list.  
 



<% String[] users = new String[] { "john", "bob", "alice", "felipe" }; %>
<str:join items="<%=users%>" separator=" - "/>
       
            

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 BodyJSP    
Restrictions

None

AttributesNameRequired Runtime Expression Evaluation Availability
 separator  Yes   Yes  1.1
 

Separator string to be used.

 var  Yes   Yes  1.0
 

Variable to store result in.

VariablesNone
Examples This is the reverse of join and is the equivalent of StringTokenizer in a tag.  
 



<%
<str:split separator=" - " var="users">john - bob - alice - felipe</str:split>
       
            

Examples

See the example application string-examples.war for examples of the usage of the tags from this custom tag library.

Java Docs

Java programmers can view the java class documentation for this tag library as javadocs.

Revision History

Review the complete revision history of this tag library.