dion 2005/01/26 05:28:02
Modified: jelly/src/test/org/apache/commons/jelly suite.jelly
jelly/src/java/org/apache/commons/jelly/tags/core
FileTag.java
Log:
Handle append on FileTag when the var attribute has a value
Revision Changes Path
1.23 +13 -8
jakarta-commons/jelly/src/test/org/apache/commons/jelly/suite.jelly
Index: suite.jelly
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/src/test/org/apache/commons/jelly/suite.jelly,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- suite.jelly 23 Jan 2005 22:36:53 -0000 1.22
+++ suite.jelly 26 Jan 2005 13:28:02 -0000 1.23
@@ -201,14 +201,12 @@
actual="${foo}"/>
</test:case>
- <test:case name="testFileToVar">
- <j:file var="foo" omitXmlDeclaration="true">
- <foo x="1">hello</foo>
- </j:file>
+ <test:case name="testFileToVar">
+ <j:file var="foo" omitXmlDeclaration="true">
+ <foo x="1">hello</foo>
+ </j:file>
- <test:assertEquals
- expected='<foo x="1">hello</foo>'
- actual="${foo}"/>
+ <test:assertEquals expected='<foo x="1">hello</foo>'
actual="${foo}"/>
</test:case>
@@ -359,5 +357,12 @@
<l>é#\ü</l></j:file>
<j:set var="doubleSize" value="${f.length()}"/>
<test:assertEquals expected="${singleSize*2}" actual="${doubleSize}"/>
- </test:case>
+ </test:case>
+
+ <!-- make sure append works for the 'var' version of the file tag -->
+ <test:case name="testFileToVarAppend">
+ <j:set var="result" value="previous result."/>
+ <j:file var="result" omitXmlDeclaration="true" append="true">And
again</j:file>
+ <test:assertEquals expected='previous result.And again'
actual="${result}"/>
+ </test:case>
</test:suite>
1.18 +8 -1
jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/FileTag.java
Index: FileTag.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/FileTag.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- FileTag.java 23 Jan 2005 22:36:53 -0000 1.17
+++ FileTag.java 26 Jan 2005 13:28:02 -0000 1.18
@@ -62,7 +62,14 @@
else if (var != null) {
StringWriter writer = new StringWriter();
writeBody(writer);
- context.setVariable(var, writer.toString());
+ String result = writer.toString();
+ Object varValue = context.getVariable(var);
+ // if we're appending, and var is an instance of string,
append it.
+ if (doAppend && varValue instanceof String) {
+ context.setVariable(var, varValue + result);
+ } else {
+ context.setVariable(var, result);
+ }
}
else {
throw new JellyTagException( "This tag must have either the
'name' or the 'var' variables defined" );
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]