polx        2005/01/21 12:42:16

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/core
                        FileTag.java
               jelly/src/test/org/apache/commons/jelly testFile.jelly
  Log:
  Fixing issue JELLY-191 raised by Marc Dexet.
  "FileTag should allow appending to a file".
  It is now possible to use and append boolean attribute.
  paul
  
  Revision  Changes    Path
  1.16      +11 -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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- FileTag.java      8 Sep 2004 04:35:22 -0000       1.15
  +++ FileTag.java      21 Jan 2005 20:42:16 -0000      1.16
  @@ -39,6 +39,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Vinay Chandran</a>
    */
   public class FileTag extends TagSupport {
  +    private boolean doAppend = false;
       private String var;
       private String name;
       private boolean omitXmlDeclaration = false;
  @@ -55,7 +56,7 @@
           try {
               if ( name != null ) {
                   String encoding = (this.encoding != null) ? this.encoding : 
"UTF-8";
  -                Writer writer = new OutputStreamWriter( new 
FileOutputStream( name ), encoding );
  +                Writer writer = new OutputStreamWriter( new 
FileOutputStream( name, doAppend ), encoding );
                   writeBody(writer);
               }
               else if (var != null) {
  @@ -113,6 +114,15 @@
       public void setEncoding(String encoding) {
           this.encoding = encoding;
       }
  +    
  +    /**
  +     * Sets wether to append at the end of the file
  +     * (not really something you normally do with an XML file).
  +     */
  +    public void setAppends(boolean doAppend) {
  +        this.doAppend = doAppend;
  +    }
  +    
   
       /**
        * Returns the var.
  
  
  
  1.5       +11 -1     
jakarta-commons/jelly/src/test/org/apache/commons/jelly/testFile.jelly
  
  Index: testFile.jelly
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/src/test/org/apache/commons/jelly/testFile.jelly,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- testFile.jelly    8 Sep 2004 05:41:32 -0000       1.4
  +++ testFile.jelly    21 Jan 2005 20:42:16 -0000      1.5
  @@ -38,5 +38,15 @@
   <file name="target/test_iso.xml" encoding="ISO-8859-1">
     <include uri="dummy.xml"/>
   </file>
  - 
  +<set var="size" value="${f.length()}"/>
  +<file name="target/test_iso.xml" encoding="ISO-8859-1" append="true">
  +  <include uri="dummy.xml"/>
  +</file>
  +<set var="sizeNow" value="${f.length()}"/>
  +
  +<if test="${!(size*2 = sizeNow)}">
  +  <set var="testFailure" value="A string and not a number size=${size}, 
sizeNow=${sizeNow}."/>
  +  ${testFailure-0}<!-- tricky way to make a test fail! -->
  +  </if>
  +
   </jelly>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to