You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ug...@apache.org on 2005/12/15 12:24:04 UTC

svn commit: r357004 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor: FormattingDateConvertor.java FormattingDateConvertorBuilder.java Icu4jDateConvertor.java Icu4jDateConvertorBuilder.java

Author: ugo
Date: Thu Dec 15 03:23:56 2005
New Revision: 357004

URL: http://svn.apache.org/viewcvs?rev=357004&view=rev
Log:
[Forms] Added "lenient" attribute to date convertors.

Modified:
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertor.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertorBuilder.java

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java?rev=357004&r1=357003&r2=357004&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java Thu Dec 15 03:23:56 2005
@@ -39,6 +39,9 @@
  * 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>Date parsing can be configured to be lenient or not by specifying a <code>lenient</code>
+ * boolean attribute. By default, parsing is lenient.
+ *
  * @version $Id$
  */
 public class FormattingDateConvertor implements Convertor {
@@ -50,6 +53,8 @@
     private LocaleMap localizedPatterns;
     /** Non-locale specific formatting pattern. */
     private String nonLocalizedPattern;
+    /** Should date parsing be lenient or not? */
+    private boolean lenient;
 
     public static final String DATE = "date";
     public static final String TIME = "time";
@@ -59,6 +64,7 @@
         this.style = DateFormat.SHORT;
         this.variant = DATE;
         this.localizedPatterns = new LocaleMap();
+        this.lenient = true;
     }
 
     public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
@@ -84,6 +90,7 @@
             if (formatCache != null)
                 formatCache.store(dateFormat);
         }
+        dateFormat.setLenient(lenient);
         return dateFormat;
     }
 
@@ -112,6 +119,7 @@
         else if (nonLocalizedPattern != null)
             dateFormat.applyPattern(nonLocalizedPattern);
 
+        dateFormat.setLenient(lenient);
         return dateFormat;
     }
 
@@ -141,6 +149,10 @@
 
     public void setNonLocalizedPattern(String pattern) {
         this.nonLocalizedPattern = pattern;
+    }
+
+    public void setLenient(boolean lenient) {
+        this.lenient = lenient;
     }
 
     private static final String CONVERTOR_EL = "convertor";

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java?rev=357004&r1=357003&r2=357004&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java Thu Dec 15 03:23:56 2005
@@ -60,6 +60,17 @@
             }
         }
 
+        String lenient = configElement.getAttribute("lenient");
+        if (!lenient.equals("")) {
+            if (lenient.equals("false") || lenient.equals("no")) {
+                convertor.setLenient(false);
+            } else if (lenient.equals("true") || lenient.equals("yes")) {
+                convertor.setLenient(true);
+            } else {
+                throw new Exception("Invalid value \"" + lenient + "\" for lenient attribute at " + DomHelper.getLocation(configElement));
+            }
+        }
+
         Element patternsEl = DomHelper.getChildElement(configElement, FormsConstants.DEFINITION_NS, "patterns", false);
         if (patternsEl != null) {
             Element patternEl[] = DomHelper.getChildElements(patternsEl, FormsConstants.DEFINITION_NS, "pattern");

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertor.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertor.java?rev=357004&r1=357003&r2=357004&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertor.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertor.java Thu Dec 15 03:23:56 2005
@@ -40,6 +40,9 @@
  * 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>Date parsing can be configured to be lenient or not by specifying a <code>lenient</code>
+ * boolean attribute. By default, parsing is lenient.
+ *
  * @version $Id$
  */
 public class Icu4jDateConvertor implements Convertor {
@@ -54,6 +57,8 @@
     private LocaleMap localizedPatterns;
     /** Non-locale specific formatting pattern. */
     private String nonLocalizedPattern;
+    /** Should date parsing be lenient or not? */
+    private boolean lenient;
 
     public static final String DATE = "date";
     public static final String TIME = "time";
@@ -63,6 +68,7 @@
         this.style = DateFormat.SHORT;
         this.variant = DATE;
         this.localizedPatterns = new LocaleMap();
+        this.lenient = true;
     }
 
     public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
@@ -88,6 +94,7 @@
             if (formatCache != null)
                 formatCache.store(dateFormat);
         }
+        dateFormat.setLenient(lenient);
         return dateFormat;
     }
 
@@ -116,6 +123,7 @@
         else if (nonLocalizedPattern != null)
             dateFormat.applyPattern(nonLocalizedPattern);
 
+        dateFormat.setLenient(lenient);
         return dateFormat;
     }
 
@@ -145,6 +153,10 @@
 
     public void setNonLocalizedPattern(String pattern) {
         this.nonLocalizedPattern = pattern;
+    }
+
+    public void setLenient(boolean lenient) {
+        this.lenient = lenient;
     }
 
     private static final String CONVERTOR_EL = "convertor";

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertorBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertorBuilder.java?rev=357004&r1=357003&r2=357004&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertorBuilder.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor/Icu4jDateConvertorBuilder.java Thu Dec 15 03:23:56 2005
@@ -61,6 +61,17 @@
             }
         }
 
+        String lenient = configElement.getAttribute("lenient");
+        if (!lenient.equals("")) {
+            if (lenient.equals("false") || lenient.equals("no")) {
+                convertor.setLenient(false);
+            } else if (lenient.equals("true") || lenient.equals("yes")) {
+                convertor.setLenient(true);
+            } else {
+                throw new Exception("Invalid value \"" + lenient + "\" for lenient attribute at " + DomHelper.getLocation(configElement));
+            }
+        }
+
         Element patternsEl = DomHelper.getChildElement(configElement, FormsConstants.DEFINITION_NS, "patterns", false);
         if (patternsEl != null) {
             Element patternEl[] = DomHelper.getChildElements(patternsEl, FormsConstants.DEFINITION_NS, "pattern");



Re: svn commit: r357004 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor: FormattingDateConvertor.java FormattingDateConvertorBuilder.java Icu4jDateConvertor.java Icu4jDateConvertorBuilder.java

Posted by Bertrand Delacretaz <bd...@apache.org>.
Le 15 déc. 05, à 15:03, Ugo Cei a écrit :

> ...Great. I have registered, but now I think someone has to give me 
> the necessary karma for editing, right? My username is "ugo"...

I've added the doc-editors and doc-committers roles to user "ugo".

-Bertrand

Re: svn commit: r357004 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor: FormattingDateConvertor.java FormattingDateConvertorBuilder.java Icu4jDateConvertor.java Icu4jDateConvertorBuilder.java

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 15/dic/05, alle ore 13:53, Bertrand Delacretaz ha scritto:

> Le 15 déc. 05, à 12:39, Ugo Cei a écrit :
>> Now, I'd like to document this, but cocoon.zones.apache.org is  
>> down :(
>
> It's back, I have restarted the services.

Great. I have registered, but now I think someone has to give me the  
necessary karma for editing, right? My username is "ugo".

	Ugo


-- 
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/



Re: svn commit: r357004 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor: FormattingDateConvertor.java FormattingDateConvertorBuilder.java Icu4jDateConvertor.java Icu4jDateConvertorBuilder.java

Posted by Bertrand Delacretaz <bd...@apache.org>.
Le 15 déc. 05, à 12:39, Ugo Cei a écrit :
> Now, I'd like to document this, but cocoon.zones.apache.org is down :(

It's back, I have restarted the services.

-Bertrand

Re: svn commit: r357004 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor: FormattingDateConvertor.java FormattingDateConvertorBuilder.java Icu4jDateConvertor.java Icu4jDateConvertorBuilder.java

Posted by Antonio Gallardo <ag...@agssa.net>.
Sylvain Wallez wrote:

> Hmm... forbidding "12-32-2005" seems more like a bug fix to me than a 
> backwards incompatible change !

+1

On the user list often people ask why cforms quietly compute the right 
date without notice. The expected behavior is a Invalid Date error message.

Best Regards,

Antonio Gallardo.


Re: svn commit: r357004 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor: FormattingDateConvertor.java FormattingDateConvertorBuilder.java Icu4jDateConvertor.java Icu4jDateConvertorBuilder.java

Posted by Sylvain Wallez <sy...@apache.org>.
Ugo Cei wrote:
>
> Il giorno 19/dic/05, alle ore 13:43, Sylvain Wallez ha scritto:
>
>> Do we really need yet another configuration option? I didn't knew 
>> about this date format's leniency, and IMO the date convertor 
>> shouldn't be lenient since "12-32-2005" is obviously an invalid 
>> input. So what about simply always set lenient to false?
>
> The problem is that the default leniency for DateFormat is true, so 
> setting it to false would break backward compatibility (even if it's 
> admittedly improbable that someone would have relied on this behavior).

Hmm... forbidding "12-32-2005" seems more like a bug fix to me than a 
backwards incompatible change !

> With my fix, we have one more option, but omitting it gives exactly 
> the same behavior as before.
>
> All in all, I don't have a strong opinion on this, so we might do a 
> quick informal vote and let people decide.

+1 for always setting lenient to false!

Sylvain

-- 
Sylvain Wallez                        Anyware Technologies
http://bluxte.net                     http://www.anyware-tech.com
Apache Software Foundation Member     Research & Technology Director


Re: svn commit: r357004 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor: FormattingDateConvertor.java FormattingDateConvertorBuilder.java Icu4jDateConvertor.java Icu4jDateConvertorBuilder.java

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 19/dic/05, alle ore 13:43, Sylvain Wallez ha scritto:

> Do we really need yet another configuration option? I didn't knew  
> about this date format's leniency, and IMO the date convertor  
> shouldn't be lenient since "12-32-2005" is obviously an invalid  
> input. So what about simply always set lenient to false?

The problem is that the default leniency for DateFormat is true, so  
setting it to false would break backward compatibility (even if it's  
admittedly improbable that someone would have relied on this  
behavior). With my fix, we have one more option, but omitting it  
gives exactly the same behavior as before.

All in all, I don't have a strong opinion on this, so we might do a  
quick informal vote and let people decide.

	Ugo


-- 
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/



Re: svn commit: r357004 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor: FormattingDateConvertor.java FormattingDateConvertorBuilder.java Icu4jDateConvertor.java Icu4jDateConvertorBuilder.java

Posted by Sylvain Wallez <sy...@apache.org>.
Ugo Cei wrote:
>
> Il giorno 15/dic/05, alle ore 12:24, ugo@apache.org ha scritto:
>
>> Author: ugo
>> Date: Thu Dec 15 03:23:56 2005
>> New Revision: 357004
>>
>> URL: http://svn.apache.org/viewcvs?rev=357004&view=rev
>> Log:
>> [Forms] Added "lenient" attribute to date convertors.
>
> What this change does is adding a new "lenient" attribute to the 
> CForms date convertors (formatting AND icu4j). By default, "lenient" 
> is true and what this means is that a date like "12-32-2005" (Dec. 
> 32nd) is silently converted to "01-01-2006" due to the way Java's 
> DateFormat class works.
>
> But if you set lenient="false", a date like that will be rejected and 
> will not pass validation.

Do we really need yet another configuration option? I didn't knew about 
this date format's leniency, and IMO the date convertor shouldn't be 
lenient since "12-32-2005" is obviously an invalid input. So what about 
simply always set lenient to false?

Sylvain

-- 
Sylvain Wallez                        Anyware Technologies
http://bluxte.net                     http://www.anyware-tech.com
Apache Software Foundation Member     Research & Technology Director


Re: svn commit: r357004 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/datatype/convertor: FormattingDateConvertor.java FormattingDateConvertorBuilder.java Icu4jDateConvertor.java Icu4jDateConvertorBuilder.java

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 15/dic/05, alle ore 12:24, ugo@apache.org ha scritto:

> Author: ugo
> Date: Thu Dec 15 03:23:56 2005
> New Revision: 357004
>
> URL: http://svn.apache.org/viewcvs?rev=357004&view=rev
> Log:
> [Forms] Added "lenient" attribute to date convertors.

What this change does is adding a new "lenient" attribute to the  
CForms date convertors (formatting AND icu4j). By default, "lenient"  
is true and what this means is that a date like "12-32-2005" (Dec.  
32nd) is silently converted to "01-01-2006" due to the way Java's  
DateFormat class works.

But if you set lenient="false", a date like that will be rejected and  
will not pass validation.

Now, I'd like to document this, but cocoon.zones.apache.org is down :(

	Ugo

-- 
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/