You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2005/03/11 11:41:30 UTC

svn commit: r157067 - in cocoon/branches/BRANCH_2_1_X: ./ src/blocks/forms/conf/ src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/

Author: sylvain
Date: Fri Mar 11 02:41:26 2005
New Revision: 157067

URL: http://svn.apache.org/viewcvs?view=rev&rev=157067
Log:
No automatic switch to ICU4J for date formatting

Modified:
    cocoon/branches/BRANCH_2_1_X/gump.xml
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/conf/forms-datatype.xconf
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingFloatConvertor.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingIntegerConvertor.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingLongConvertor.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/gump.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/gump.xml?view=diff&r1=157066&r2=157067
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/gump.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/gump.xml Fri Mar 11 02:41:26 2005
@@ -820,6 +820,7 @@
     <depend project="nekodtd"/>
     <depend project="daisy-util"/>
     <depend project="daisy-htmlcleaner"/>
+    <depend project="icu4j"/>
 
     <library name="xreporter-expression"/>
     <library name="jakarta-oro"/>
@@ -827,6 +828,7 @@
     <library name="nekodtd"/>
     <library name="daisy-util"/>
     <library name="daisy-htmlcleaner"/>
+    <library name="icu4j"/>
 
     <work nested="build/cocoon-@@DATE@@/blocks/forms/test"/>
     <work nested="tools/anttasks"/>

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/conf/forms-datatype.xconf
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/conf/forms-datatype.xconf?view=diff&r1=157066&r2=157067
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/conf/forms-datatype.xconf (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/conf/forms-datatype.xconf Fri Mar 11 02:41:26 2005
@@ -62,6 +62,7 @@
         <convertors default="formatting" plain="millis">
           <convertor name="formatting" src="org.apache.cocoon.forms.datatype.convertor.FormattingDateConvertorBuilder"/>
           <convertor name="millis" src="org.apache.cocoon.forms.datatype.convertor.MillisDateConvertorBuilder"/>
+          <convertor name="icu4j" src="org.apache.cocoon.forms.datatype.convertor.Icu4jDateConvertorBuilder"/>
         </convertors>
       </datatype>
       <datatype name="boolean" src="org.apache.cocoon.forms.datatype.typeimpl.BooleanTypeBuilder">

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java?view=diff&r1=157066&r2=157067
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java Fri Mar 11 02:41:26 2005
@@ -15,8 +15,6 @@
  */
 package org.apache.cocoon.forms.datatype.convertor;
 
-import org.outerj.i18n.DateFormat;
-import org.outerj.i18n.I18nSupport;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 import org.apache.cocoon.forms.Constants;
@@ -24,7 +22,9 @@
 
 import java.util.Locale;
 import java.util.Date;
+import java.text.DateFormat;
 import java.text.ParseException;
+import java.text.SimpleDateFormat;
 
 /**
  * A Convertor for {@link java.util.Date Date} objects backed by the
@@ -39,11 +39,6 @@
  * pattern for nl-BE will be sought, then one for nl, and if that is not
  * found, finally the locale-independent formatting pattern will be used.
  *
- * <p><strong>NOTE:</strong> the earlier statement about the fact that this class uses java.text.SimpleDateFormat
- * is not entirely correct. In fact, it uses a small wrapper class that will either delegate to
- * java.text.SimpleDateFormat or com.ibm.icu.text.SimpleDateFormat. The com.ibm version will automatically
- * be used if it is present on the classpath, otherwise the java.text version will be used.
- *
  * @version $Id$
  */
 public class FormattingDateConvertor implements Convertor {
@@ -61,13 +56,13 @@
     public static final String DATE_TIME = "datetime";
 
     public FormattingDateConvertor() {
-        this.style = java.text.DateFormat.SHORT;
+        this.style = DateFormat.SHORT;
         this.variant = DATE;
         this.localizedPatterns = new LocaleMap();
     }
 
     public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
-        DateFormat dateFormat = getDateFormat(locale, formatCache);
+        SimpleDateFormat dateFormat = getDateFormat(locale, formatCache);
         try {
             return new ConversionResult(dateFormat.parse(value));
         } catch (ParseException e) {
@@ -76,14 +71,14 @@
     }
 
     public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache) {
-        DateFormat dateFormat = getDateFormat(locale, formatCache);
+        SimpleDateFormat dateFormat = getDateFormat(locale, formatCache);
         return dateFormat.format((Date)value);
     }
 
-    private final DateFormat getDateFormat(Locale locale, Convertor.FormatCache formatCache) {
-        DateFormat dateFormat = null;
+    private final SimpleDateFormat getDateFormat(Locale locale, Convertor.FormatCache formatCache) {
+        SimpleDateFormat dateFormat = null;
         if (formatCache != null)
-            dateFormat = (DateFormat)formatCache.get();
+            dateFormat = (SimpleDateFormat)formatCache.get();
         if (dateFormat == null) {
             dateFormat = getDateFormat(locale);
             if (formatCache != null)
@@ -92,21 +87,28 @@
         return dateFormat;
     }
 
-    protected DateFormat getDateFormat(Locale locale) {
-        DateFormat dateFormat = null;
+    protected SimpleDateFormat getDateFormat(Locale locale) {
+        SimpleDateFormat dateFormat = null;
 
         if (this.variant.equals(DATE)) {
-            dateFormat = I18nSupport.getInstance().getDateFormat(style, locale);
+            //dateFormat = I18nSupport.getInstance().getDateFormat(style, locale);
+            dateFormat = (SimpleDateFormat)DateFormat.getDateInstance(style, locale);
         } else if (this.variant.equals(TIME)) {
-            dateFormat = I18nSupport.getInstance().getTimeFormat(style, locale);
+            //dateFormat = I18nSupport.getInstance().getTimeFormat(style, locale);
+            dateFormat = (SimpleDateFormat)DateFormat.getTimeInstance(style, locale);
         } else if (this.variant.equals(DATE_TIME)) {
-            dateFormat = I18nSupport.getInstance().getDateTimeFormat(style, style, locale);
+            //dateFormat = I18nSupport.getInstance().getDateTimeFormat(style, style, locale);
+            dateFormat = (SimpleDateFormat)DateFormat.getDateTimeInstance(style, style, locale);
         }
 
         String pattern = (String)localizedPatterns.get(locale);
 
         if (pattern != null)
-            dateFormat.applyLocalizedPattern(pattern);
+            // Note: this was previously using applyLocalizedPattern() which allows to use
+            // a locale-specific pattern syntax, e.g. in french "j" (jour) for "d" and
+            // "a" (annee) for "y". But the localized pattern syntax is very little known and thus
+            // led to some weird pattern syntax error messages.
+            dateFormat.applyPattern(pattern);
         else if (nonLocalizedPattern != null)
             dateFormat.applyPattern(nonLocalizedPattern);
 

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java?view=diff&r1=157066&r2=157067
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java Fri Mar 11 02:41:26 2005
@@ -15,12 +15,12 @@
  */
 package org.apache.cocoon.forms.datatype.convertor;
 
-import org.outerj.i18n.I18nSupport;
-import org.outerj.i18n.DecimalFormat;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
 import java.util.Locale;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
 import java.text.ParseException;
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -38,11 +38,6 @@
  * pattern for nl-BE will be sought, then one for nl, and if that is not
  * found, finally the locale-independent formatting pattern will be used.
  *
- * <p>Note: the earlier statement about the fact that this class uses java.text.DecimalFormat
- * is not entirely correct. In fact, it uses a small wrapper class that will either delegate to
- * java.text.DecimalFormat or com.ibm.icu.text.DecimalFormat. The com.ibm version will automatically
- * be used if it is present on the classpath, otherwise the java.text version will be used.
- *
  * @version $Id$
  */
 public class FormattingDecimalConvertor implements Convertor {
@@ -113,23 +108,26 @@
 
         switch (variant) {
             case INTEGER:
-                decimalFormat = I18nSupport.getInstance().getIntegerFormat(locale);
+                decimalFormat = (DecimalFormat)NumberFormat.getNumberInstance(locale);
+                decimalFormat.setMaximumFractionDigits(0);
+                decimalFormat.setDecimalSeparatorAlwaysShown(false);
+                decimalFormat.setParseIntegerOnly(true);
                 break;
             case NUMBER:
-                decimalFormat = I18nSupport.getInstance().getNumberFormat(locale);
+                decimalFormat = (DecimalFormat)NumberFormat.getNumberInstance(locale);
                 break;
             case CURRENCY:
-                decimalFormat = I18nSupport.getInstance().getCurrencyFormat(locale);
+                decimalFormat = (DecimalFormat)NumberFormat.getCurrencyInstance(locale);
                 break;
             case PERCENT:
-                decimalFormat = I18nSupport.getInstance().getPercentFormat(locale);
+                decimalFormat = (DecimalFormat)NumberFormat.getPercentInstance(locale);
                 break;
         }
 
         String pattern = (String)localizedPatterns.get(locale);
 
         if (pattern != null) {
-            decimalFormat.applyLocalizedPattern(pattern);
+            decimalFormat.applyPattern(pattern);
         } else if (nonLocalizedPattern != null) {
             decimalFormat.applyPattern(nonLocalizedPattern);
         }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java?view=diff&r1=157066&r2=157067
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java Fri Mar 11 02:41:26 2005
@@ -15,9 +15,8 @@
  */
 package org.apache.cocoon.forms.datatype.convertor;
 
-import org.outerj.i18n.DecimalFormat;
-
 import java.util.Locale;
+import java.text.DecimalFormat;
 import java.text.ParseException;
 
 /**

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingFloatConvertor.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingFloatConvertor.java?view=diff&r1=157066&r2=157067
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingFloatConvertor.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingFloatConvertor.java Fri Mar 11 02:41:26 2005
@@ -15,9 +15,8 @@
  */
 package org.apache.cocoon.forms.datatype.convertor;
 
-import org.outerj.i18n.DecimalFormat;
-
 import java.util.Locale;
+import java.text.DecimalFormat;
 import java.text.ParseException;
 
 /**

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingIntegerConvertor.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingIntegerConvertor.java?view=diff&r1=157066&r2=157067
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingIntegerConvertor.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingIntegerConvertor.java Fri Mar 11 02:41:26 2005
@@ -15,9 +15,8 @@
  */
 package org.apache.cocoon.forms.datatype.convertor;
 
-import org.outerj.i18n.DecimalFormat;
-
 import java.util.Locale;
+import java.text.DecimalFormat;
 import java.text.ParseException;
 
 /**

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingLongConvertor.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingLongConvertor.java?view=diff&r1=157066&r2=157067
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingLongConvertor.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingLongConvertor.java Fri Mar 11 02:41:26 2005
@@ -15,9 +15,8 @@
  */
 package org.apache.cocoon.forms.datatype.convertor;
 
-import org.outerj.i18n.DecimalFormat;
-
 import java.util.Locale;
+import java.text.DecimalFormat;
 import java.text.ParseException;
 
 /**

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?view=diff&r1=157066&r2=157067
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Fri Mar 11 02:41:26 2005
@@ -202,6 +202,13 @@
 
   <changes>
   <release version="@version@" date="@date@">
+   <action dev="SW" type="update">
+     CForms: separate <code>FormattingDateConvertor</code> that uses
+     <code>java.text.SimpleDateFormat</code> and <code>Icu4jDateFormatter</code>
+     that uses ICU4J. There was previously an automatic switch to ICU4J if the
+     library was present in the classpath, which sometimes caused some strange
+     results are it behaves a bit differently.
+   </action>
    <action dev="BD" type="fix">
      Tour block: fix "shapes" sample using if/else in flowscript
      instead of switch.