commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy TestMixedContentEncoding.java
Date Sun, 04 Apr 2004 09:23:11 GMT
rdonkin     2004/04/04 01:23:10

  Modified:    betwixt/src/java/org/apache/commons/betwixt/strategy
                        MixedContentEncodingStrategy.java
               betwixt/src/test/org/apache/commons/betwixt/strategy
                        TestMixedContentEncoding.java
  Log:
  Added factory constants for two new additional content encoding strategies.
  
  Revision  Changes    Path
  1.2       +31 -3     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/MixedContentEncodingStrategy.java
  
  Index: MixedContentEncodingStrategy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/MixedContentEncodingStrategy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MixedContentEncodingStrategy.java	24 Mar 2004 22:51:21 -0000	1.1
  +++ MixedContentEncodingStrategy.java	4 Apr 2004 09:23:10 -0000	1.2
  @@ -37,8 +37,7 @@
   public abstract class MixedContentEncodingStrategy {
   
       /**
  -     * The default implementation used by Betwixt.
  -     * This always encodes by escaping character data.
  +     * The standard implementation used by Betwixt by default.
        * This is a singleton.
        */
       public static final MixedContentEncodingStrategy DEFAULT 
  @@ -50,6 +49,35 @@
               return false;       
           }
       };
  +    
  +    /**
  +     * Encodes element content within a <code>CDATA</code> section.
  +     * This is a singleton.
  +     */
  +    public static final MixedContentEncodingStrategy CDATA 
  +            = new BaseMixedContentEncodingStrategy() {
  +        /**
  +         * Always encode by escaping character data.
  +         */
  +        protected boolean encodeAsCDATA(ElementDescriptor element) {
  +            return true;       
  +        }
  +    };    
  +
  +    /**
  +      * Encodes by escaping character data.
  +      * This is a singleton.
  +      */
  +     public static final MixedContentEncodingStrategy ESCAPED_CHARACTERS 
  +             = new BaseMixedContentEncodingStrategy() {
  +         /**
  +          * Always encode by escaping character data.
  +          */
  +         protected boolean encodeAsCDATA(ElementDescriptor element) {
  +             return false;       
  +         }
  +     };
  +    
   
       /**
        * Encodes the body content into a form suitable for output as 
  
  
  
  1.2       +17 -1     jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/TestMixedContentEncoding.java
  
  Index: TestMixedContentEncoding.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/TestMixedContentEncoding.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestMixedContentEncoding.java	24 Mar 2004 22:52:59 -0000	1.1
  +++ TestMixedContentEncoding.java	4 Apr 2004 09:23:10 -0000	1.2
  @@ -88,6 +88,22 @@
               MixedContentEncodingStrategy.DEFAULT.encode("<proclaim>The King Is Dead,
Long Live The King</proclaim>", descriptor));
       }
       
  +    public void testEscapedCharactersImplementation() {
  +        ElementDescriptor descriptor = new ElementDescriptor();
  +        assertEquals(
  +            "Default implementation uses character escaping",
  +            "&lt;proclaim&gt;The King Is Dead, Long Live The King&lt;/proclaim&gt;",
  +            MixedContentEncodingStrategy.ESCAPED_CHARACTERS.encode("<proclaim>The
King Is Dead, Long Live The King</proclaim>", descriptor));
  +    }
  +    
  +    public void testCDATAImplementation() {
  +        ElementDescriptor descriptor = new ElementDescriptor();
  +        assertEquals(
  +            "Default implementation uses character escaping",
  +            "<![CDATA[<proclaim>The King Is Dead, Long Live The King</proclaim>]]>",
  +            MixedContentEncodingStrategy.CDATA.encode("<proclaim>The King Is Dead,
Long Live The King</proclaim>", descriptor));
  +    }
  +    
       public void testdefaultOutput() throws Exception {
           Element element = new Element();
           element.setValue("<greeting>What Ho Jeeves!</greeting>");
  
  
  

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


Mime
View raw message