You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by po...@apache.org on 2005/01/21 21:42:16 UTC

cvs commit: jakarta-commons/jelly/src/test/org/apache/commons/jelly testFile.jelly

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:vinayc@apache.org">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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-commons/jelly/src/test/org/apache/commons/jelly testFile.jelly

Posted by Paul Libbrecht <pa...@activemath.org>.
Le 21 janv. 05, à 23:53, Dion Gillard a écrit :

> Does this really work? Because...
> [...] The method here is called setAppends (note the 's').
>>   1.5       +11 -1      
>> jakarta-commons/jelly/src/test/org/apache/commons/jelly/ 
>> testFile.jelly
> [snip]
>>   +<set var="size" value="${f.length()}"/>
>>   +<file name="target/test_iso.xml" encoding="ISO-8859-1"  
>> append="true">
>>   +  <include uri="dummy.xml"/>
>>   +</file>
>
> And note the attribute used above of 'append' , with no 's'.

Thanks Dion!

Your point raised another issue: testFile.jelly was actually never read  
or executed!
I'm moving tests for file-tag into testJelly (which uses jelly:junit  
hence is way more expressive!), removing testFile.jelly (because I got  
caught by it), adding a test for the append attribute, for which setter  
I'm removing the "s".

thanks Dion for your care!

paul


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-commons/jelly/src/test/org/apache/commons/jelly testFile.jelly

Posted by Dion Gillard <di...@gmail.com>.
Does this really work? Because...


On 21 Jan 2005 20:42:16 -0000, polx@apache.org <po...@apache.org> wrote:
> 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.
[snip]
>   +
>   +    /**
>   +     * 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;
>   +    }
>   +

The method here is called setAppends (note the 's').


>   1.5       +11 -1     jakarta-commons/jelly/src/test/org/apache/commons/jelly/testFile.jelly
[snip]
>   +<set var="size" value="${f.length()}"/>
>   +<file name="target/test_iso.xml" encoding="ISO-8859-1" append="true">
>   +  <include uri="dummy.xml"/>
>   +</file>

And note the attribute used above of 'append' , with no 's'.

?
-- 
http://www.multitask.com.au/people/dion/

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org