You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Reinhard Poetz <re...@apache.org> on 2005/03/01 09:23:52 UTC

Pattern convertor - Bug?

If I use a pattern convertor according to the documentation

<fd:convertor type="formatting">
   <fd:patterns>
     <fd:pattern>MM/dd/yyyy</fd:pattern>
     <fd:pattern locale="nl-BE">dd/MM/yyyy</fd:pattern>
     <fd:pattern locale="fr">dd-MM-yyyy</fd:pattern>
   </fd:patterns>
</fd:convertor>

I get following exception:

java.lang.IllegalArgumentException: Illegal pattern  character 'd'
	at java.text.SimpleDateFormat.translatePattern(SimpleDateFormat.java:1737)
	at java.text.SimpleDateFormat.applyLocalizedPattern(SimpleDateFormat.java:1792)
	at org.outerj.i18n.JdkDateFormat.applyLocalizedPattern(JdkDateFormat.java:23)
	at 
org.apache.cocoon.forms.datatype.convertor.FormattingDateConvertor.getDateFormat(FormattingDateConvertor.java:109)


(I've modified the birthday widget of our 'form1'-example and I'm using trunk 
checked-out yesterday. I've noticed the same problem in a 4 weeks old 2.2 
checkout too.)

Any ideas what's wrong here? Is it a bug or my mistake?

-- 
Reinhard Pötz           Independant Consultant, Trainer & (IT)-Coach 

{Software Engineering, Open Source, Web Applications, Apache Cocoon}

                                        web(log): http://www.poetz.cc
--------------------------------------------------------------------

Re: Pattern convertor - Bug?

Posted by Reinhard Poetz <re...@apache.org>.
Sylvain Wallez wrote:
> Reinhard Poetz wrote:
> 
>>
>> If I use a pattern convertor according to the documentation
>>
>> <fd:convertor type="formatting">
>>   <fd:patterns>
>>     <fd:pattern>MM/dd/yyyy</fd:pattern>
>>     <fd:pattern locale="nl-BE">dd/MM/yyyy</fd:pattern>
>>     <fd:pattern locale="fr">dd-MM-yyyy</fd:pattern>
>>   </fd:patterns>
>> </fd:convertor>
>>
>> I get following exception:
>>
>> java.lang.IllegalArgumentException: Illegal pattern  character 'd'
>>     at 
>> java.text.SimpleDateFormat.translatePattern(SimpleDateFormat.java:1737)
>>     at 
>> java.text.SimpleDateFormat.applyLocalizedPattern(SimpleDateFormat.java:1792) 
>>
>>     at 
>> org.outerj.i18n.JdkDateFormat.applyLocalizedPattern(JdkDateFormat.java:23) 
>>
>>     at 
>> org.apache.cocoon.forms.datatype.convertor.FormattingDateConvertor.getDateFormat(FormattingDateConvertor.java:109) 
>>
>>
>>
>> (I've modified the birthday widget of our 'form1'-example and I'm 
>> using trunk checked-out yesterday. I've noticed the same problem in a 
>> 4 weeks old 2.2 checkout too.)
>>
>> Any ideas what's wrong here? Is it a bug or my mistake?
> 
> 
> 
> Remove icu4j.jar from your WEB-INF/lib and retry. The date convertor 
> currently automatically uses icu4j if present and DateFormat otherwise. 
> This leads to this kind of weirdness because of the differences between 
> the two.
> 
> I plan to separate them, the current "formatting" convertor using 
> SimpleDateFormat and a new "icu4j" convertor using... icu4j!
> 
> Sylvain
> 

hmmm, icu4j wasn't in my WEB-INF/lib. Looking at gump.xml shows that cForms 
doesn't have a dependency on icu4j. I tried to add icu4j but this didn't work 
either.

-- 
Reinhard Pötz           Independant Consultant, Trainer & (IT)-Coach 

{Software Engineering, Open Source, Web Applications, Apache Cocoon}

                                        web(log): http://www.poetz.cc
--------------------------------------------------------------------

Re: Pattern convertor - Bug?

Posted by Sylvain Wallez <sy...@apache.org>.
Reinhard Poetz wrote:

>
> If I use a pattern convertor according to the documentation
>
> <fd:convertor type="formatting">
>   <fd:patterns>
>     <fd:pattern>MM/dd/yyyy</fd:pattern>
>     <fd:pattern locale="nl-BE">dd/MM/yyyy</fd:pattern>
>     <fd:pattern locale="fr">dd-MM-yyyy</fd:pattern>
>   </fd:patterns>
> </fd:convertor>
>
> I get following exception:
>
> java.lang.IllegalArgumentException: Illegal pattern  character 'd'
>     at 
> java.text.SimpleDateFormat.translatePattern(SimpleDateFormat.java:1737)
>     at 
> java.text.SimpleDateFormat.applyLocalizedPattern(SimpleDateFormat.java:1792) 
>
>     at 
> org.outerj.i18n.JdkDateFormat.applyLocalizedPattern(JdkDateFormat.java:23) 
>
>     at 
> org.apache.cocoon.forms.datatype.convertor.FormattingDateConvertor.getDateFormat(FormattingDateConvertor.java:109) 
>
>
>
> (I've modified the birthday widget of our 'form1'-example and I'm 
> using trunk checked-out yesterday. I've noticed the same problem in a 
> 4 weeks old 2.2 checkout too.)
>
> Any ideas what's wrong here? Is it a bug or my mistake?


Remove icu4j.jar from your WEB-INF/lib and retry. The date convertor 
currently automatically uses icu4j if present and DateFormat otherwise. 
This leads to this kind of weirdness because of the differences between 
the two.

I plan to separate them, the current "formatting" convertor using 
SimpleDateFormat and a new "icu4j" convertor using... icu4j!

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }


Re: Pattern convertor - Bug?

Posted by Sylvain Wallez <sy...@apache.org>.
Reinhard Poetz wrote:

>
> If I use a pattern convertor according to the documentation
>
> <fd:convertor type="formatting">
>   <fd:patterns>
>     <fd:pattern>MM/dd/yyyy</fd:pattern>
>     <fd:pattern locale="nl-BE">dd/MM/yyyy</fd:pattern>
>     <fd:pattern locale="fr">dd-MM-yyyy</fd:pattern>
>   </fd:patterns>
> </fd:convertor>
>
> I get following exception:
>
> java.lang.IllegalArgumentException: Illegal pattern  character 'd'
>     at 
> java.text.SimpleDateFormat.translatePattern(SimpleDateFormat.java:1737)
>     at 
> java.text.SimpleDateFormat.applyLocalizedPattern(SimpleDateFormat.java:1792) 
>
>     at 
> org.outerj.i18n.JdkDateFormat.applyLocalizedPattern(JdkDateFormat.java:23) 
>
>     at 
> org.apache.cocoon.forms.datatype.convertor.FormattingDateConvertor.getDateFormat(FormattingDateConvertor.java:109) 
>
>
>
> (I've modified the birthday widget of our 'form1'-example and I'm 
> using trunk checked-out yesterday. I've noticed the same problem in a 
> 4 weeks old 2.2 checkout too.)
>
> Any ideas what's wrong here? Is it a bug or my mistake?


I spent some time on this and finally found its cause.

The problem is that locale-specific patterns are applied using 
SimpleDateFormat.applyLocalizedPattern(). The difference between this 
method and applyPattern() is that the pattern is - as its name implies - 
localized and thus can potentially use other characters than the one 
specified in SimpleDateFormat's javadoc which describes only en-US.

icu4j has the same problem, but uses a different set of localized 
patterns. For example, icu4j patterns in the "fr" locale use "a" instead 
of "y" (année/year) and "j" instead of "d" (jour/day).

Weird thing is that contrarily to icu4j, the JDK localized pattern for 
"fr" is the same as "en-us", thus leading to a different behaviour as 
CForms automatically switches to icu4j if present in the classpath.

So we have here two problems:
- locale-specific patterns use a locale-specific syntax which may not be 
the one documented in the Javadocs (and I don't know where to find the 
locale-specific documentation)
- automatically switching to icu4j leads to a changing behaviour 
depending on the presence of a specific jar file in the classpath.

To solve this, I propose:
- always use applyPattern() instead of applyLocalizedPattern()
- disable the automatic switching to icu4j, and provide an additional 
"Icu4jDateConvertor".

BTW, what is the real added value of icu4j compared to java.text classes?

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }