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/java/org/apache/commons/betwixt/io BeanWriter.java
Date Sun, 19 Jan 2003 23:22:48 GMT
rdonkin     2003/01/19 15:22:48

  Modified:    betwixt/src/java/org/apache/commons/betwixt/io
                        BeanWriter.java
  Log:
  Moved utility methods into XMLUtils. Deprecated methods that were moved.
  
  Revision  Changes    Path
  1.14      +9 -65     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanWriter.java
  
  Index: BeanWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanWriter.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- BeanWriter.java	7 Jan 2003 22:32:57 -0000	1.13
  +++ BeanWriter.java	19 Jan 2003 23:22:47 -0000	1.14
  @@ -72,6 +72,8 @@
   import org.apache.commons.logging.LogFactory;
   import org.xml.sax.SAXException;
   
  +import org.apache.commons.betwixt.XMLUtils;
  +
   /** <p><code>BeanWriter</code> outputs beans as XML to an io stream.</p>
     *
     * <p>The output for each bean is an xml fragment
  @@ -121,17 +123,6 @@
     */
   public class BeanWriter extends AbstractBeanWriter {
   
  -    /** Escaped <code>&lt;</code> entity */
  -    private static final String LESS_THAN_ENTITY = "&lt;";
  -    /** Escaped <code>&gt;</code> entity */
  -    private static final String GREATER_THAN_ENTITY = "&gt;";
  -    /** Escaped <code>&amp;</code> entity */
  -    private static final String AMPERSAND_ENTITY = "&amp;";
  -    /** Escaped <code>'</code> entity */
  -    private static final String APOSTROPHE_ENTITY = "&apos;";
  -    /** Escaped <code>"</code> entity */
  -    private static final String QUOTE_ENTITY = "&quot;";
  -
       /** Where the output goes */
       private Writer writer;    
       /** text used for end of lines. Defaults to <code>\n</code>*/
  @@ -364,7 +355,7 @@
               log.error( "[expressBodyText]Body text is null" );
               
           } else {
  -            writer.write( escapeBodyValue(text) );
  +            writer.write( XMLUtils.escapeBodyValue(text) );
           }
       }
       
  @@ -395,7 +386,7 @@
           writer.write( ' ' );
           writer.write( qualifiedName );
           writer.write( "=\"" );
  -        writer.write( escapeAttributeValue(value) );
  +        writer.write( XMLUtils.escapeAttributeValue(value) );
           writer.write( '\"' );
       }
   
  @@ -433,29 +424,10 @@
        *
        * @param value escape <code>value.toString()</code>
        * @return text with escaped delimiters 
  +     * @deprecated After 1.0-Alpha-1 moved into utility class {@link XMLUtils#escapeBodyValue}
        */
       protected String escapeBodyValue(Object value) {
  -        StringBuffer buffer = new StringBuffer(value.toString());
  -        for (int i=0, size = buffer.length(); i <size; i++) {
  -            switch (buffer.charAt(i)) {
  -                case '<':
  -                    buffer.replace(i, i+1, LESS_THAN_ENTITY);
  -                    size += 3;
  -                    i+=3;
  -                    break;
  -                 case '>':
  -                    buffer.replace(i, i+1, GREATER_THAN_ENTITY);
  -                    size += 3;
  -                    i += 3;
  -                    break;
  -                 case '&':
  -                    buffer.replace(i, i+1, AMPERSAND_ENTITY);
  -                    size += 4;
  -                    i += 4;
  -                    break;        
  -            }
  -        }
  -        return buffer.toString();
  +        return XMLUtils.escapeBodyValue(value);
       }
   
       /** 
  @@ -464,39 +436,11 @@
        *
        * @param value escape <code>value.toString()</code>
        * @return text with characters restricted (for use in attributes) escaped
  +     *
  +     * @deprecated After 1.0-Alpha-1 moved into utility class {@link XMLUtils#escapeAttributeValue}
        */
       protected String escapeAttributeValue(Object value) {
  -        StringBuffer buffer = new StringBuffer(value.toString());
  -        for (int i=0, size = buffer.length(); i <size; i++) {
  -            switch (buffer.charAt(i)) {
  -                case '<':
  -                    buffer.replace(i, i+1, LESS_THAN_ENTITY);
  -                    size += 3;
  -                    i+=3;
  -                    break;
  -                 case '>':
  -                    buffer.replace(i, i+1, GREATER_THAN_ENTITY);
  -                    size += 3;
  -                    i += 3;
  -                    break;
  -                 case '&':
  -                    buffer.replace(i, i+1, AMPERSAND_ENTITY);
  -                    size += 4;
  -                    i += 4;
  -                    break;
  -                 case '\'':
  -                    buffer.replace(i, i+1, APOSTROPHE_ENTITY);
  -                    size += 4;
  -                    i += 4;
  -                    break;
  -                 case '\"':
  -                    buffer.replace(i, i+1, QUOTE_ENTITY);
  -                    size += 5;
  -                    i += 5;
  -                    break;           
  -            }
  -        }
  -        return buffer.toString();
  +        return XMLUtils.escapeAttributeValue(value);
       }
   
   }
  
  
  

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


Mime
View raw message