common:transformText

This taglib allows for rather advanced text/string transformations.

Parameters

Name Required Default Type Description
id true   Object/String The id of the variable to store the result in.
text true   Object/String The text to transform
htmlEncode false false Object/String Should the text be HTMLEncoded – all non ascii chars are replaced by html-entities.
replaceLineBreaks false false Object/String Should the tag replace linebreak chars?
lineBreakReplacer false   Object/String What string should replace the linebreak chars?
replaceString false   Object/String State this if you wish to replace a string in the text with another string. Can be a regular expression.
replaceWithString false   Object/String The new string
prefix false   Object/String Set this attribute if you wish to insert a string before the text.
addPrefixIfTextMatches false   Object/String This is an optional attribute to the prefix attribute. Let’s you state that the prefix only be added if the text contains/matches a regular expression you state here.
addPrefixIfTextNotMatches false   Object/String This is an optional attribute to the prefix attribute. Let’s you state that the prefix only be added if the text does not contains/matches a regular expression you state.
suffix false   Object/String Set this attribute if you wish to insert a string after the text.
addSuffixIfTextMatches false   Object/String This is an optional attribute to the suffix attribute. Let’s you state that the suffix only be added if the text contains/matches a regular expression you state here.
addSuffixIfTextNotMatches false   Object/String This is an optional attribute to the suffix attribute. Let’s you state that the suffix only be added if the text does not contains/matches a regular expression you state.
         


ID-result variable contains: A String-object.

Examples


This example will output "Testing replacing all spaces" into the document.

<%@ taglib uri="infoglue-common" prefix="common" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<common:transformText id="transformedText" text="Testing replacing all spaces" replaceString="\\s"
replaceWithString="&nbsp;"/>
<c:out value="${transformedText}"/>


This example will output the string html encoded and all line breaks would be replaced with <br/>-tags into the document.

<%@ taglib uri="infoglue-common" prefix="common" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<common:transformText id="transformedText" text="Testing replacing & i18N like åäö ÅÄÖ"
replaceString="\\s" replaceWithString="&nbsp;" htmlEncode="true" replaceLineBreaks="true"
lineBreakReplacer="<br/>"/>
<c:out value="${transformedText}"/>

 


comments powered by Disqus