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 AbstractBeanWriter.java
Date Tue, 29 Jul 2003 21:32:15 GMT
rdonkin     2003/07/29 14:32:15

  Modified:    betwixt/src/java/org/apache/commons/betwixt/io
                        AbstractBeanWriter.java
  Log:
  Added code that calls ConvertUtils to perform the conversion (so that this matches the bean
reading).
  
  Revision  Changes    Path
  1.17      +35 -26    jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/AbstractBeanWriter.java
  
  Index: AbstractBeanWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/AbstractBeanWriter.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AbstractBeanWriter.java	24 Apr 2003 08:52:20 -0000	1.16
  +++ AbstractBeanWriter.java	29 Jul 2003 21:32:15 -0000	1.17
  @@ -66,6 +66,7 @@
   import java.util.HashMap;
   import java.util.Iterator;
   
  +import org.apache.commons.beanutils.ConvertUtils;
   import org.apache.commons.betwixt.AttributeDescriptor;
   import org.apache.commons.betwixt.ElementDescriptor;
   import org.apache.commons.betwixt.Descriptor;
  @@ -732,12 +733,10 @@
                       Expression expression = childDescriptors[i].getTextExpression();
                       if ( expression != null ) {
                           Object value = expression.evaluate( context );
  -                        if ( value != null ) {
  -                            String text = value.toString();
  -                            if ( text != null && text.length() > 0 ) {
  -                                bodyText(text);
  -                            }
  -                        }                
  +                        String text = convertToString( value );
  +                        if ( text != null && text.length() > 0 ) {
  +                            bodyText(text);
  +                        }               
                       }
                   }
               }
  @@ -746,12 +745,10 @@
               Expression expression = elementDescriptor.getTextExpression();
               if ( expression != null ) {
                   Object value = expression.evaluate( context );
  -                if ( value != null ) {
  -                    String text = value.toString();
  -                    if ( text != null && text.length() > 0 ) {
  -                        bodyText(text);
  -                    }
  -                }                
  +                String text = convertToString(value);
  +                if ( text != null && text.length() > 0 ) {
  +                    bodyText(text);
  +                }
               }
           }
       }
  @@ -843,12 +840,10 @@
           Expression expression = descriptor.getTextExpression();
           if ( expression != null ) {
               Object value = expression.evaluate( context );
  -            if ( value != null ) {
  -                String text = value.toString();
  -                if ( text != null && text.length() > 0 ) {
  -                    log.trace( "Element has body text which isn't empty." );
  -                    return false;
  -                }
  +            String text = convertToString(value);
  +            if ( text != null && text.length() > 0 ) {
  +                log.trace( "Element has body text which isn't empty." );
  +                return false;
               }
           }
           
  @@ -1061,9 +1056,7 @@
                       Expression expression = attributes[index].getTextExpression();
                       if ( expression != null ) {
                           Object value = expression.evaluate( context );
  -                        if (value != null) {
  -                            return value.toString();
  -                        }
  +                        return convertToString( value );
                       }
                   }
                   return "";
  @@ -1461,4 +1454,20 @@
        * @deprecated after 1.0-Alpha-1 replaced by new BeanWriter API
        */
       protected void writeIndent() throws IOException {}
  +    
  +    /**
  +      * Converts an object to a string.
  +      *
  +      * @param value the Object to represent as a String, possibly null
  +      * @return String representation, not null
  +      */
  +    private String convertToString(Object value) {
  +        if ( value != null ) {
  +            String text = ConvertUtils.convert( value );
  +            if ( text != null ) {
  +                return text;
  +            }
  +        }
  +        return "";
  +    }
   }
  
  
  

---------------------------------------------------------------------
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