Author: sylvain
Date: Fri Mar 11 06:04:07 2005
New Revision: 157080

URL: http://svn.apache.org/viewcvs?view=rev&rev=157080
Log:
Separate java.text and icu4j formatting

Added:
    
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertor.java
   (with props)
    
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertorBuilder.java
   (with props)
Modified:
    
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/acting/HandleFormSubmitAction.java
    
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java
    
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java
    
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java
    
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingFloatConvertor.java
    
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingIntegerConvertor.java
    
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingLongConvertor.java
    cocoon/trunk/gump.xml
    cocoon/trunk/status.xml

Modified: 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/acting/HandleFormSubmitAction.java
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/acting/HandleFormSubmitAction.java?view=diff&r1=157079&r2=157080
==============================================================================
--- 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/acting/HandleFormSubmitAction.java
 (original)
+++ 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/acting/HandleFormSubmitAction.java
 Fri Mar 11 06:04:07 2005
@@ -83,7 +83,7 @@
 
             if (finished) {
                 return Collections.EMPTY_MAP;
-            } 
+            }
             return null;
         } finally {
             resolver.release(source);

Modified: 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java?view=diff&r1=157079&r2=157080
==============================================================================
--- 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java
 (original)
+++ 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java
 Fri Mar 11 06:04:07 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 [EMAIL PROTECTED] 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/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java?view=diff&r1=157079&r2=157080
==============================================================================
--- 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java
 (original)
+++ 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java
 Fri Mar 11 06:04:07 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 {
@@ -67,6 +62,8 @@
     }
 
     public ConversionResult convertFromString(String value, Locale locale, 
Convertor.FormatCache formatCache) {
+        // Some locales (e.g. "fr") produce non-breaking spaces sent back as 
space by the browser
+        value = value.replace(' ', (char)160);
         DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
         Number decimalValue;
         try {
@@ -113,23 +110,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/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java?view=diff&r1=157079&r2=157080
==============================================================================
--- 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java
 (original)
+++ 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java
 Fri Mar 11 06:04:07 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;
 
 /**
@@ -36,6 +35,8 @@
     }
 
     public ConversionResult convertFromString(String value, Locale locale, 
Convertor.FormatCache formatCache) {
+        // Some locales (e.g. "fr") produce non-breaking spaces sent back as 
space by the browser
+        value = value.replace(' ', (char)160);
         DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
         try {
             Number decimalValue = decimalFormat.parse(value);

Modified: 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingFloatConvertor.java
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingFloatConvertor.java?view=diff&r1=157079&r2=157080
==============================================================================
--- 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingFloatConvertor.java
 (original)
+++ 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingFloatConvertor.java
 Fri Mar 11 06:04:07 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;
 
 /**
@@ -36,6 +35,8 @@
     }
 
     public ConversionResult convertFromString(String value, Locale locale, 
Convertor.FormatCache formatCache) {
+        // Some locales (e.g. "fr") produce non-breaking spaces sent back as 
space by the browser
+        value = value.replace(' ', (char)160);
         DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
         try {
             Number decimalValue = decimalFormat.parse(value);

Modified: 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingIntegerConvertor.java
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingIntegerConvertor.java?view=diff&r1=157079&r2=157080
==============================================================================
--- 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingIntegerConvertor.java
 (original)
+++ 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingIntegerConvertor.java
 Fri Mar 11 06:04:07 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;
 
 /**
@@ -37,6 +36,8 @@
     }
 
     public ConversionResult convertFromString(String value, Locale locale, 
Convertor.FormatCache formatCache) {
+        // Some locales (e.g. "fr") produce non-breaking spaces sent back as 
space by the browser
+        value = value.replace(' ', (char)160);
         DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
         try {
             Number decimalValue = decimalFormat.parse(value);

Modified: 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingLongConvertor.java
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingLongConvertor.java?view=diff&r1=157079&r2=157080
==============================================================================
--- 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingLongConvertor.java
 (original)
+++ 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingLongConvertor.java
 Fri Mar 11 06:04:07 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;
 
 /**
@@ -36,6 +35,8 @@
     }
 
     public ConversionResult convertFromString(String value, Locale locale, 
Convertor.FormatCache formatCache) {
+        // Some locales (e.g. "fr") produce non-breaking spaces sent back as 
space by the browser
+        value = value.replace(' ', (char)160);
         DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
         try {
             Number decimalValue = decimalFormat.parse(value);

Added: 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertor.java
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertor.java?view=auto&rev=157080
==============================================================================
--- 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertor.java
 (added)
+++ 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertor.java
 Fri Mar 11 06:04:07 2005
@@ -0,0 +1,163 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.datatype.convertor;
+
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Locale;
+
+import org.apache.cocoon.forms.Constants;
+import org.apache.cocoon.xml.AttributesImpl;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+import com.ibm.icu.text.DateFormat;
+import com.ibm.icu.text.SimpleDateFormat;
+
+/**
+ * A Convertor for [EMAIL PROTECTED] java.util.Date Date} objects backed by 
ICU4J's
+ * [EMAIL PROTECTED] com.ibm.icu.text.SimpleDateFormat} class.
+ *
+ * <p>It can be configured to use one of three <strong>variants</strong>: date,
+ * time or datetime and one of four <strong>styles</strong>: long, full, 
medium or short.
+ *
+ * <p>Alternatively, a <strong>formatting pattern</strong> can be used. This 
can either be a locale-dependent
+ * or locale-independent formatting pattern. When looking up a formatting 
pattern, a mechansim
+ * similar to resource bundle lookup is used. Suppose the locale is nl-BE, 
then first a formatting
+ * 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.
+ *
+ * @version $Id$
+ */
+public class Icu4jDateConvertor implements Convertor {
+    //FIXME: the only difference of this class with FormattingDateConvertor is 
the use of com.ibm.icu.text.SimpleDateFormat
+    // --> refactor to have it extend FormattingDateConvertor
+
+    /** See [EMAIL PROTECTED] #setStyle}. */
+    private int style;
+    /** See [EMAIL PROTECTED] #setVariant}. */
+    private String variant;
+    /** Locale-specific formatting patterns. */
+    private LocaleMap localizedPatterns;
+    /** Non-locale specific formatting pattern. */
+    private String nonLocalizedPattern;
+
+    public static final String DATE = "date";
+    public static final String TIME = "time";
+    public static final String DATE_TIME = "datetime";
+
+    public Icu4jDateConvertor() {
+        this.style = DateFormat.SHORT;
+        this.variant = DATE;
+        this.localizedPatterns = new LocaleMap();
+    }
+
+    public ConversionResult convertFromString(String value, Locale locale, 
Convertor.FormatCache formatCache) {
+        SimpleDateFormat dateFormat = getDateFormat(locale, formatCache);
+        try {
+            return new ConversionResult(dateFormat.parse(value));
+        } catch (ParseException e) {
+            return ConversionResult.create("date." + this.variant);
+        }
+    }
+
+    public String convertToString(Object value, Locale locale, 
Convertor.FormatCache formatCache) {
+        SimpleDateFormat dateFormat = getDateFormat(locale, formatCache);
+        return dateFormat.format((Date)value);
+    }
+
+    private final SimpleDateFormat getDateFormat(Locale locale, 
Convertor.FormatCache formatCache) {
+        SimpleDateFormat dateFormat = null;
+        if (formatCache != null)
+            dateFormat = (SimpleDateFormat)formatCache.get();
+        if (dateFormat == null) {
+            dateFormat = getDateFormat(locale);
+            if (formatCache != null)
+                formatCache.store(dateFormat);
+        }
+        return dateFormat;
+    }
+
+    protected SimpleDateFormat getDateFormat(Locale locale) {
+        SimpleDateFormat dateFormat = null;
+
+        if (this.variant.equals(DATE)) {
+            //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 = (SimpleDateFormat)DateFormat.getTimeInstance(style, 
locale);
+        } else if (this.variant.equals(DATE_TIME)) {
+            //dateFormat = I18nSupport.getInstance().getDateTimeFormat(style, 
style, locale);
+            dateFormat = 
(SimpleDateFormat)DateFormat.getDateTimeInstance(style, style, locale);
+        }
+
+        String pattern = (String)localizedPatterns.get(locale);
+
+        if (pattern != null)
+            // 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);
+
+        return dateFormat;
+    }
+
+    public Class getTypeClass() {
+        return Date.class;
+    }
+
+    /**
+     *
+     * @param style one of the constants FULL, LONG, MEDIUM or SHORT defined 
in the [EMAIL PROTECTED] Date} class.
+     */
+    public void setStyle(int style) {
+        this.style = style;
+    }
+
+    public void setVariant(String variant) {
+        if (DATE.equals(variant) || TIME.equals(variant) || 
DATE_TIME.equals(variant)) {
+            this.variant = variant;
+        } else {
+            throw new IllegalArgumentException("Invalid value for variant 
parameter.");
+        }
+    }
+
+    public void addFormattingPattern(Locale locale, String pattern) {
+        localizedPatterns.put(locale, pattern);
+    }
+
+    public void setNonLocalizedPattern(String pattern) {
+        this.nonLocalizedPattern = pattern;
+    }
+
+    private static final String CONVERTOR_EL = "convertor";
+
+    public void generateSaxFragment(ContentHandler contentHandler, Locale 
locale) throws SAXException {
+        String pattern = getDateFormat(locale).toPattern();
+
+        if (pattern != null) {
+            AttributesImpl attrs = new AttributesImpl();
+            attrs.addCDATAAttribute("pattern", pattern);
+            attrs.addCDATAAttribute("variant", this.variant);
+            contentHandler.startElement(Constants.INSTANCE_NS, CONVERTOR_EL, 
Constants.INSTANCE_PREFIX_COLON + CONVERTOR_EL, attrs);
+            contentHandler.endElement(Constants.INSTANCE_NS, CONVERTOR_EL, 
Constants.INSTANCE_PREFIX_COLON + CONVERTOR_EL);
+        }
+    }
+}

Propchange: 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertor.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertorBuilder.java
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertorBuilder.java?view=auto&rev=157080
==============================================================================
--- 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertorBuilder.java
 (added)
+++ 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertorBuilder.java
 Fri Mar 11 06:04:07 2005
@@ -0,0 +1,83 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.datatype.convertor;
+
+import java.util.Locale;
+
+import org.apache.cocoon.forms.Constants;
+import org.apache.cocoon.forms.util.DomHelper;
+import org.apache.cocoon.i18n.I18nUtils;
+import org.w3c.dom.Element;
+
+import com.ibm.icu.text.DateFormat;
+
+/**
+ * Builds [EMAIL PROTECTED] Icu4jDateConvertor}s.
+ *
+ * @version $Id$
+ */
+public class Icu4jDateConvertorBuilder implements ConvertorBuilder {
+    public Convertor build(Element configElement) throws Exception {
+        Icu4jDateConvertor convertor = new Icu4jDateConvertor();
+
+        if (configElement == null)
+            return convertor;
+
+        String style = configElement.getAttribute("style");
+        if (!style.equals("")) {
+            if (style.equals("short"))
+                convertor.setStyle(DateFormat.SHORT);
+            else if (style.equals("medium"))
+                convertor.setStyle(DateFormat.MEDIUM);
+            else if (style.equals("long"))
+                convertor.setStyle(DateFormat.LONG);
+            else if (style.equals("full"))
+                convertor.setStyle(DateFormat.FULL);
+            else
+                throw new Exception("Invalid value \"" + style + "\" for style 
attribute at " + DomHelper.getLocation(configElement));
+        }
+
+        String variant = configElement.getAttribute("variant");
+        if (!variant.equals("")) {
+            if (variant.equals(Icu4jDateConvertor.DATE) ||
+                    variant.equals(Icu4jDateConvertor.TIME) ||
+                    variant.equals(Icu4jDateConvertor.DATE_TIME)) {
+                convertor.setVariant(variant);
+            } else {
+                throw new Exception("Invalid value \"" + variant + "\" for 
variant attribute at " + DomHelper.getLocation(configElement));
+            }
+        }
+
+        Element patternsEl = DomHelper.getChildElement(configElement, 
Constants.DEFINITION_NS, "patterns", false);
+        if (patternsEl != null) {
+            Element patternEl[] = DomHelper.getChildElements(patternsEl, 
Constants.DEFINITION_NS, "pattern");
+            for (int i = 0; i < patternEl.length; i++) {
+                String locale = patternEl[i].getAttribute("locale");
+                String pattern = DomHelper.getElementText(patternEl[i]);
+                if (pattern.equals(""))
+                    throw new Exception("pattern element does not contain any 
content at " + DomHelper.getLocation(patternEl[i]));
+                if (locale.equals(""))
+                    convertor.setNonLocalizedPattern(pattern);
+                else {
+                    Locale loc = I18nUtils.parseLocale(locale);
+                    convertor.addFormattingPattern(loc, pattern);
+                }
+            }
+        }
+
+        return convertor;
+    }
+}

Propchange: 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertorBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertorBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/gump.xml
URL: 
http://svn.apache.org/viewcvs/cocoon/trunk/gump.xml?view=diff&r1=157079&r2=157080
==============================================================================
--- cocoon/trunk/gump.xml (original)
+++ cocoon/trunk/gump.xml Fri Mar 11 06:04:07 2005
@@ -788,6 +788,7 @@
     <depend project="nekodtd"/>
     <depend project="daisy-util"/>
     <depend project="daisy-htmlcleaner"/>
+    <depend project="icu4j"/>
 
     <library name="xreporter-expression"/>
     <library name="jakarta-oro"/>
@@ -795,6 +796,7 @@
     <library name="nekodtd"/>
     <library name="daisy-util"/>
     <library name="daisy-htmlcleaner"/>
+    <library name="icu4j"/>
 
     <work nested="build/cocoon-@@DATE@@/blocks/forms/dest"/>
     <work nested="build/cocoon-@@DATE@@/blocks/forms/test"/>

Modified: cocoon/trunk/status.xml
URL: 
http://svn.apache.org/viewcvs/cocoon/trunk/status.xml?view=diff&r1=157079&r2=157080
==============================================================================
--- cocoon/trunk/status.xml (original)
+++ cocoon/trunk/status.xml Fri Mar 11 06:04:07 2005
@@ -437,6 +437,13 @@
    </action>
  </release>
  <release version="2.1.7" date="TBD">
+   <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="VG" type="update">
      Build: Added exclude.all.blocks and include.all.blocks properties
      to quickly toggle all blocks on or off.


Reply via email to