You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by di...@apache.org on 2003/01/19 11:50:55 UTC

cvs commit: jakarta-turbine-maven/src/java/org/apache/maven DVSLFormatter.java

dion        2003/01/19 02:50:55

  Modified:    src/java/org/apache/maven DVSLFormatter.java
  Log:
  Fix formatter so that the pattern is used.
  
  Revision  Changes    Path
  1.9       +27 -7     jakarta-turbine-maven/src/java/org/apache/maven/DVSLFormatter.java
  
  Index: DVSLFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/DVSLFormatter.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DVSLFormatter.java	31 Dec 2002 07:00:00 -0000	1.8
  +++ DVSLFormatter.java	19 Jan 2003 10:50:55 -0000	1.9
  @@ -58,12 +58,16 @@
   
   import java.text.DecimalFormat;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +
   /**
    * Formatting tool for use with the DVSL toolbox.  This class contains
    * static methods to assist in formatting needs that can't be done or
    * shouldn't be done in a DVSL stylesheet.
    *
    * @author <a href="mailto:pete-apache-dev@kazmier.com">Pete Kazmier</a>
  + * @author <a href="mailto:dion@apache.org">dIon Gillard</a>
    * @version $Id$
    */
   public class DVSLFormatter
  @@ -72,6 +76,11 @@
        * Instance of a formatter.
        */
       private static DecimalFormat formatter = new DecimalFormat();
  +    
  +    /**
  +     * Log for debug output
  +     */
  +    private static Log LOG = LogFactory.getLog(DVSLFormatter.class);
   
       /**
        * Formats a string as a number using the specified pattern.
  @@ -89,6 +98,7 @@
        */
       public static final String formatNumber( String value, String pattern )
       {
  +        LOG.debug("value = '" + value + "', pattern = '" + pattern + "'");
           if ( pattern == null || value == null )
           {
               return "<error formatting: '" + value + "' with '" + pattern + "'>";
  @@ -98,16 +108,26 @@
   
           try
           {
  -            // What the fuck is wrong with this thing. What a complete fucking
  -            // piece of utter shit. Can Sun fucking do anything right?!?
  -            // Enabling this causes allows absolutely nothing to work correctly.
  -            // Go check out the javadoc on this too, what crap. Just crap.
  -            //formatter.applyPattern( pattern );
  +            formatter = new DecimalFormat(pattern);
  +            Number valueAsNumber = Double.valueOf(value.trim());
  +            
  +            if (pattern.indexOf(".") != -1 || pattern.indexOf("%") != -1)
  +            {
  +                // parse as a decimal
  +                ret = formatter.format( valueAsNumber.doubleValue() );
  +            }
  +            else
  +            {
  +                // parse as an integer
  +                formatter.setParseIntegerOnly(true);
  +                ret = formatter.format(valueAsNumber.longValue());
  +            }
  +            LOG.debug("ret='" + ret + "'");
   
  -            ret = formatter.format( formatter.parse( value ).doubleValue() );
           }
           catch ( Exception e )
           {
  +            LOG.error("<error formatting: '" + value + "' with '" + pattern + "'>", e);
               return "<error formatting: '" + value + "' with '" + pattern + "'>";
           }