You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by ba...@apache.org on 2002/10/25 22:51:36 UTC
cvs commit: jakarta-taglibs/string/src/org/apache/taglibs/string ReplaceTag.java
bayard 2002/10/25 13:51:35
Modified: string/xml string.xml
string/src/org/apache/taglibs/string ReplaceTag.java
Log:
Added in an attribute to str:replace to allow newlines to be handled
nicely. At least it's a nice hack.
Revision Changes Path
1.23 +11 -0 jakarta-taglibs/string/xml/string.xml
Index: string.xml
===================================================================
RCS file: /home/cvs/jakarta-taglibs/string/xml/string.xml,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- string.xml 8 Oct 2002 01:23:37 -0000 1.22
+++ string.xml 25 Oct 2002 20:51:35 -0000 1.23
@@ -1633,6 +1633,17 @@
</description>
<availability>1.0</availability>
</attribute>
+ <attribute>
+ <name>newlineToken</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ <type>java.lang.String</type>
+ <description>
+ Token to use instead of a newline to get around JSP pain.
+ Default is to ignore this functionality.
+ </description>
+ <availability>1.1</availability>
+ </attribute>
<example>
<usage>
<comment>
1.4 +36 -4 jakarta-taglibs/string/src/org/apache/taglibs/string/ReplaceTag.java
Index: ReplaceTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/string/src/org/apache/taglibs/string/ReplaceTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ReplaceTag.java 28 Jul 2002 00:11:15 -0000 1.3
+++ ReplaceTag.java 25 Oct 2002 20:51:35 -0000 1.4
@@ -81,6 +81,11 @@
* Number of times to replace.
* Default is all matches.
* </dd>
+ * <dt>newlineToken</dt><dd>
+ * Token to use as a newline.
+ * This gets around the pain of haivng a literal newline in the jsp.
+ * By default this is ignored.
+ * </dd>
* </dl>
*
* @author bayard@generationjava.com
@@ -90,6 +95,7 @@
private int count;
private String replace;
private String with;
+ private String newlineToken;
public ReplaceTag() {
super();
@@ -113,6 +119,24 @@
this.replace = replace;
}
+ /**
+ * Get the newlineToken property
+ *
+ * @return String property
+ */
+ public String getNewlineToken() {
+ return this.newlineToken;
+ }
+
+ /**
+ * Set the newlineToken property
+ *
+ * @param newlineToken String property
+ */
+ public void setNewlineToken(String newlineToken) {
+ this.newlineToken = newlineToken;
+ }
+
/**
* Get the with property
@@ -154,7 +178,13 @@
public String changeString(String text) {
- return StringUtils.replace(text, replace, with, count);
+ String repl = replace;
+ String wit = with;
+ if(this.newlineToken != null) {
+ repl = StringUtils.replace(replace, this.newlineToken, "\n");
+ wit = StringUtils.replace(with, this.newlineToken, "\n");
+ }
+ return StringUtils.replace(text, repl, wit, count);
}
public void initAttributes() {
@@ -164,6 +194,8 @@
this.with = null;
this.count = -1;
+
+ this.newlineToken = null;
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>