jstrachan    2002/10/02 09:55:05

  Modified:    jelly/src/test/org/apache/commons/jelly suite.jelly
               jelly/src/java/org/apache/commons/jelly/tags/core
                        SetTag.java
  Log:
  Added support for the <j:set> tag to set the value of a String variable to its body 
without XML-encoding the XML as text.
  
  So that
  
  <j:set var="foo" encode="false">
        <some>xml</some>
  </j:set>
  
  Would generate a String "     <some>xml</some>" rather than encoding the < and > 
characters.
  
  I've preserved the current behaviour, that the default should be to encode; though 
maybe we should change the default? It was fear of braking code that stopped me do it.
  
  Revision  Changes    Path
  1.5       +10 -0     
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/suite.jelly
  
  Index: suite.jelly
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/suite.jelly,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- suite.jelly       1 Oct 2002 16:45:23 -0000       1.4
  +++ suite.jelly       2 Oct 2002 16:55:04 -0000       1.5
  @@ -107,6 +107,16 @@
                        actual="${customer.class.name}"/>
     </test:case>
   
  +     <test:case name="testSetWithNoEncoding">
  +             <j:set var="foo" encode="false">
  +                     <foo x="1">hello</foo>
  +             </j:set>
  +
  +             <test:assertEquals 
  +                     expected='&lt;foo x="1"&gt;hello&lt;/foo&gt;' 
  +                     actual="${foo}"/>
  +  </test:case>
  +
        <test:case name="testFileToVar">
                <j:file var="foo" omitXmlDeclaration="true">
                        <foo x="1">hello</foo>
  
  
  
  1.8       +27 -6     
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/SetTag.java
  
  Index: SetTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/SetTag.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SetTag.java       15 Jul 2002 16:57:44 -0000      1.7
  +++ SetTag.java       2 Oct 2002 16:55:04 -0000       1.8
  @@ -102,6 +102,9 @@
   
       /** The name of the property to set on the target object. */
       private String property;
  +    
  +    /** Should we XML encode the body of this tag as text? */
  +    private boolean encode = true;
   
       public SetTag() {
       }
  @@ -114,7 +117,7 @@
               answer = value.evaluate(context);
           }
           else {
  -            answer = getBodyText();
  +            answer = getBodyText(isEncode());
           }
           
           if ( var != null ) {
  @@ -170,6 +173,24 @@
           this.property = property;
       }
       
  +    /**
  +     * Returns whether the body of this tag will be XML encoded or not.
  +     */
  +    public boolean isEncode() {
  +        return encode;
  +    }
  +
  +    /**
  +     * Sets whether the body of the tag should be XML encoded as text (so that &lt; 
and &gt; are
  +     * encoded as &amp;lt; and &amp;gt;) or leave the text as XML which is the 
default.
  +     * This is only used if this tag is specified with no value so that the text 
body of this
  +     * tag is used as the body.
  +     */
  +    public void setEncode(boolean encode) {
  +        this.encode = encode;
  +    }
  +
  +
       // Implementation methods
       //-------------------------------------------------------------------------     
           
       protected void setPropertyValue( Object target, String property, Object value ) 
throws Exception {
  
  
  

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

Reply via email to