String tags ver. 2.5

    Custom JSP taglib. Tag Substr extracts some part of the body. You may set bounding templates or first and last indexes. Tag Replace replaces all occurrences of the given string in the body with the new string. Tag toUpperCase converts own body to upper case, tag toLowerCase converts own body to lower case, tag Capitalize capitalizes the first letter of each word in the body. Tag leftPad (rightPath) pads own body with a particular symbol. Tag parseString parses a source string and iterates over tokens. Tag forEachLine iterates over lines. Tag stripTags lets you remove all tags (some text starts with < and ends with >) in your code. Tags Ltrim and Rtrim let you to remove some symbols from the left or from the right side. Tag filter lets you remove some symbols from the string.

For example:
 


<%@ taglib uri="taglib.tld" prefix="str" %>

Replace #User with John
<str:Replace oldStr="#User" newStr="John">
   <br> Dear #User,
   .....
   .....
</str:Replace>

Extract table from the variable htmlSource:
 


<str:Substr start="<table" end="</table">
  <%=htmlSource%>
</str:Substr>

Remove spaces, tabs and new lines from the right
 


<str:Rtrim symbol=" \t\r\n"><%=some_var%></str:Rtrim>

Extract first two symbols:
 


<str:Substr from="0" to="2">01/11/2001</str:Substr>

Convert to lower case:
 


<str:toLowerCase>
   IT WILL BE ON THE LOWER CASE
</str:toLower>

Parse string and print tokens:
 


<str:parseString source="first,second,etc." separator=",">
   <br>token is: <str:getToken/>
</str:parseString>

Parse text and print lines:
 


<str:forEachLine source="<%=myText%>">
   <br>current line is: <%=currentLine%>
</str:forEachLine>

Filters string according to the given RegExp:
 


<str:filter pattern="[a-zA-Z]">
   qwerty123456uiop
</str:filter>

Tags are:

Substr

Body tag. Extracts a substring from own body. Extracted part could be described as a pair of two templates (start, end) or as a pair of two indexes (from,to). With parameter id result will be saved in the page scope variable, without this parameter tag just prints substring. Parameters are:

1) start describes a begin template (inclusive)
2) end describes an end template (inclusive)
3) from initial index (inclusive). Default value is 0
4) to last index (exclusive). By default extends up to end if this string
5) id Optional parameter. Describes page scope variable

Replace

Replaces oldStr with newStr in the body. With parameter id result will be saved in the page scope variable, without this parameter tag just prints data. Parameters are:

1) oldStr old value (template)
2) newStr new value (replacement)
3) id Optional parameter. Describes a page scope variable for data
4) ignoreCase Optional parameter. Possible values are true or false. If this value is true than replacement is not case-sensitive. Default value is false.

stripTags

Body tag removes all the text within < and > (inclusive). With parameter id result will be saved in the page scope variable, without this parameter tag just prints data. Parameters are:

1) id Optional parameter. Describes a page scope variable for the result (type is java.lang.String). Without this parameter tag simply prints data.

cleanXSS

Body tag removes malicious Cross Site Scripting (XSS) code . Parameters are:

1) id Optional parameter. Describes a page scope variable for the result (type is java.lang.String). Without this parameter tag simply prints data.

toUpperCase

Body tag. Converts own body content to upper case. With parameter id result will be saved in the page scope variable, without this parameter it will be just printed. Parameters are:

1) id describes a page scope variable for the result (type is java.lang.String). Without this parameter tag simply prints data.

toLowerCase

Body tag. Converts own body content to lower case. With parameter id result will be saved in the page scope variable, without this parameter it will be just printed. Parameters are:

1) id describes a page scope variable for the result (type is java.lang.String). Without this parameter tag simply prints data.

Capitalize

Body tag. For the each word in the body converts the first letter to upper case and the rest of the word to lower case. With parameter id result will be saved in the page scope variable, without this parameter it will be just printed. Parameters are:

1) id describes a page scope variable for the result (type is java.lang.String). Without this parameter tag simply prints data.

filter

Body tag. Lets you filtering the body and left the only symbols that conform to the given RegExp. With parameter id result will be saved in the page scope variable, without this parameter it will be just printed. Parameters are:

1) id Optional parameter. Describes a page scope variable for the result (type is java.lang.String). Without this parameter tag simply prints data.
2) pattern Describes a regular expression for the valid symbols

leftPad

Body tag. Pads a body from the left with a particular symbols up to specified length. With parameter id result will be saved in the page scope variable, without this parameter it will be just printed. Parameters are:

1) length describes a final length for string
2) symbol Optional parameter. Describes a symbol for padding. Default value is space.
3) id Optional parameter. Describes a page scope variable

rightPad

Body tag. Pads a body from the right with a particular symbols up to specified length. With parameter id result will be saved in the page scope variable, without this parameter it will be just printed. Parameters are:

1) length describes a final length for string
2) symbol Optional parameter. Describes a symbol for padding. Default value is space.
3) id Optional parameter. Describes a page scope variable

Ltrim

Body tag. Removes all the symbols from the given list from the left side of body string. With parameter id result will be saved in the page scope variable, without this parameter it will be just printed. Parameters are:

1) symbol Optional parameter. Describes a list of symbols for the removing. Default value is space.
2) id Optional parameter. Describes a page scope variable

Rtrim

Body tag. Removes all the symbols from the given list from the right side of body string. With parameter id result will be saved in the page scope variable, without this parameter it will be just printed. Parameters are:

1) symbol Optional parameter. Describes a list of symbols for the removing. Default value is space.
2) id Optional parameter. Describes a page scope variable

Trim

Body tag. Removes all the symbols from the given list from the left and right sides of body string. With parameter id result will be saved in the page scope variable, without this parameter it will be just printed. Parameters are:

1) symbol Optional parameter. Describes a list of symbols for the removing. Default value is space.
2) id Optional parameter. Describes a page scope variable

cutString

Body tag. Restricts the size for string (cut the string if size is bigger than maxLength). With parameter id result will be saved in the page scope variable, without this parameter it will be just printed. Parameters are:

1) maxLength Describes a maximal length for string.
2) add Optional parameter. Describes a string that will be concatenated with truncated body. By default is empty.
3) id Optional parameter. Describes a page scope variable

parseString

Parses source strings and iterates over tokens. Parameters are:

1) source source string
2) separator Optional parameter. Lets you describe a separator. Default value is a space.

getToken

You may use this tag in the body of parseString tag. Tag will read/print current token. With parameter id current token will be saved in the page scope variable (type is java.lang.String) and without this parameter tag just prints the value. Parameters are:

1) id Optional parameter. Describes a page scope variable

forEachLine

Body tag, parses source string and iterates over lines. Parameters are:

1) source source string
2) id Optional parameter. Describes a name for the nested page scope variable (type is java.lang.String). Default value is currentLine.

addslashes

Body tag. Returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote ('), double quote ("), backslash (\). With parameter id result will be saved in the page scope variable, without this parameter it will be just printed. Parameters are:

1) id Optional parameter. Describes a page scope variable

stripslashes

Body tag. Returns a string with backslashes stripped off. (\' becomes ' and so on.) Double backslashes (\\) are made into a single backslash (\). With parameter id result will be saved in the page scope variable, without this parameter it will be just printed. Parameters are:

1) id Optional parameter. Describes a page scope variable for the result (type is java.lang.String). Without this parameter tag simply prints data.

for downloading:

 Library: strtag.jar     Description: taglib.tld

 © Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.

Also in Coldtags: