You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Romualdo Rubens de Freitas <ro...@gmail.com> on 2007/10/19 21:14:14 UTC

$$$ [Digester] Converting String do java.util.Date $$$

Hi All,

I'm facing a problem with date conversion. My XML document has an element whose
value has the format dd/MM/yyyy (brazilian date format). When Digester
tries to convert
the value to a date I get an exception stating:
<code>
19/10/2007 16:05:31
org.apache.commons.beanutils.converters.DateTimeConverter toDate
WARNING:     DateConverter does not support default String to 'Date' conversion.
19/10/2007 16:05:32
org.apache.commons.beanutils.converters.DateTimeConverter toDate
WARNING:     (N.B. Re-configure Converter or use alternative implementation)
19/10/2007 16:05:32 org.apache.commons.digester.Digester endElement
SEVERE: End event threw exception
org.apache.commons.beanutils.ConversionException: DateConverter does
not support default String to 'Date' conversion.
</code>

In the middle of the msgs above there is one that called my attention:
N.B. Re-configure Converter or use alternative implementation

According BeanUtils docs I can do that, but I didn't find any
information on how to do that
with Digester.

Debugging Digester source code I've found
DateTimeConverter.convertToType() method
that has the following "if (useLocaleFormat) ..." which, I guess,
could do the job, but I
don't know how to setup locale info so that the conversion can be done.

Besides that, I could use Calendar, but I don't know how to use it, too.

Any help (with Date conversions and Calendar types) would be appreciated.

TIA.

-- 
Romualdo Rubens de Freitas

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: $$$ [Digester] Converting String do java.util.Date $$$

Posted by Romualdo Rubens de Freitas <ro...@gmail.com>.
Simon,

Thanks a lot, again.

Best regards.

2007/10/19, simon <si...@chello.at>:
> On Fri, 2007-10-19 at 17:10 -0300, Romualdo Rubens de Freitas wrote:
> > Hi Simon,
> >
> > Thanks a lot for your quick answer.
> >
> > Yes, I was debugging Digester source code to see where my XML document was
> > failing and I've found that code at
> > org.apache.commons.beanutils.converters.DateTimeConverter.convertToType()
> > method.
> >
> > As I said that method has an if statement with the boolean condition:
> > useLocaleFormat
> >
> > Your tip is cool, I can register my own conversion object, but I think
> > it's possible to
> > configure the conversion made by BeanUtils so that my date format can
> > be recognized as
> > BeanUtils docs state, but I don't know how nor where 'cause this
> > configuration must be
> > made with Digester (I think).
> >
> > Can you help with date contents in XML elements/attributes, too ???
>
> At least in earlier releases, BeanUtils deliberately did NOT register a
> date converter object because there are so many different date formats,
> and no obvious "standard" one.
>
> I vaguely remember something about the very latest BeanUtils release and
> dates; maybe this has changed. I suggest checking the release notes.
>
> But for further info about setting up BeanUtils I suggest you post a new
> email with [beanutils] in the subject, rather than digester. Configuring
> this is nothing to do with Digester at all - as I said, Digester calls
> ConvertUtils.convert, and that is all it does. What happens then is up
> to the beanutils library.
>
> Exactly the same logic applies to both element-body-text and attributes;
> BeanUtils handles all converting, using the singleton objects that are
> accessed via the static beanutils methods. And those are configured by
> calling beanutils static methods, not via digester.
>
>  Regards,
>
> Simon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>


-- 
Romualdo Rubens de Freitas

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: $$$ [Digester] Converting String do java.util.Date $$$

Posted by simon <si...@chello.at>.
On Fri, 2007-10-19 at 17:10 -0300, Romualdo Rubens de Freitas wrote:
> Hi Simon,
> 
> Thanks a lot for your quick answer.
> 
> Yes, I was debugging Digester source code to see where my XML document was
> failing and I've found that code at
> org.apache.commons.beanutils.converters.DateTimeConverter.convertToType()
> method.
> 
> As I said that method has an if statement with the boolean condition:
> useLocaleFormat
> 
> Your tip is cool, I can register my own conversion object, but I think
> it's possible to
> configure the conversion made by BeanUtils so that my date format can
> be recognized as
> BeanUtils docs state, but I don't know how nor where 'cause this
> configuration must be
> made with Digester (I think).
> 
> Can you help with date contents in XML elements/attributes, too ???

At least in earlier releases, BeanUtils deliberately did NOT register a
date converter object because there are so many different date formats,
and no obvious "standard" one. 

I vaguely remember something about the very latest BeanUtils release and
dates; maybe this has changed. I suggest checking the release notes.

But for further info about setting up BeanUtils I suggest you post a new
email with [beanutils] in the subject, rather than digester. Configuring
this is nothing to do with Digester at all - as I said, Digester calls
ConvertUtils.convert, and that is all it does. What happens then is up
to the beanutils library.

Exactly the same logic applies to both element-body-text and attributes;
BeanUtils handles all converting, using the singleton objects that are
accessed via the static beanutils methods. And those are configured by
calling beanutils static methods, not via digester.

 Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: $$$ [Digester] Converting String do java.util.Date $$$

Posted by Romualdo Rubens de Freitas <ro...@gmail.com>.
Hi Simon,

Thanks a lot for your quick answer.

Yes, I was debugging Digester source code to see where my XML document was
failing and I've found that code at
org.apache.commons.beanutils.converters.DateTimeConverter.convertToType()
method.

As I said that method has an if statement with the boolean condition:
useLocaleFormat

Your tip is cool, I can register my own conversion object, but I think
it's possible to
configure the conversion made by BeanUtils so that my date format can
be recognized as
BeanUtils docs state, but I don't know how nor where 'cause this
configuration must be
made with Digester (I think).

Can you help with date contents in XML elements/attributes, too ???

TIA.

2007/10/19, simon <si...@chello.at>:
> On Fri, 2007-10-19 at 16:14 -0300, Romualdo Rubens de Freitas wrote:
> > Hi All,
> >
> > I'm facing a problem with date conversion. My XML document has an element whose
> > value has the format dd/MM/yyyy (brazilian date format). When Digester
> > tries to convert
> > the value to a date I get an exception stating:
> > <code>
> > 19/10/2007 16:05:31
> > org.apache.commons.beanutils.converters.DateTimeConverter toDate
> > WARNING:     DateConverter does not support default String to 'Date' conversion.
> > 19/10/2007 16:05:32
> > org.apache.commons.beanutils.converters.DateTimeConverter toDate
> > WARNING:     (N.B. Re-configure Converter or use alternative implementation)
> > 19/10/2007 16:05:32 org.apache.commons.digester.Digester endElement
>
> Just use
>   ConvertUtils.register(converter, Date.class)
> where converter is your own implementation that handles dates however
> you want. Digester simply calls the static beanutils method
> ConvertUtils.convert.
>
> Ideally, digester would have a ConvertUtils *instance* rather than
> relying on the static singleton but that's old history. And in practice
> no-one has ever cared.
>
> > SEVERE: End event threw exception
> > org.apache.commons.beanutils.ConversionException: DateConverter does
> > not support default String to 'Date' conversion.
> > </code>
> >
> > In the middle of the msgs above there is one that called my attention:
> > N.B. Re-configure Converter or use alternative implementation
> >
> > According BeanUtils docs I can do that, but I didn't find any
> > information on how to do that
> > with Digester.
> >
> > Debugging Digester source code I've found
> > DateTimeConverter.convertToType() method
> > that has the following "if (useLocaleFormat) ..." which, I guess,
> > could do the job, but I
> > don't know how to setup locale info so that the conversion can be done.
>
> Hmm.. I don't remember any code like that. What class is that in? Are
> you sure you're not looking at code inside beanutils?
>
>
> Regards,
>
> Simon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>


-- 
Romualdo Rubens de Freitas

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: $$$ [Digester] Converting String do java.util.Date $$$

Posted by simon <si...@chello.at>.
On Fri, 2007-10-19 at 16:14 -0300, Romualdo Rubens de Freitas wrote:
> Hi All,
> 
> I'm facing a problem with date conversion. My XML document has an element whose
> value has the format dd/MM/yyyy (brazilian date format). When Digester
> tries to convert
> the value to a date I get an exception stating:
> <code>
> 19/10/2007 16:05:31
> org.apache.commons.beanutils.converters.DateTimeConverter toDate
> WARNING:     DateConverter does not support default String to 'Date' conversion.
> 19/10/2007 16:05:32
> org.apache.commons.beanutils.converters.DateTimeConverter toDate
> WARNING:     (N.B. Re-configure Converter or use alternative implementation)
> 19/10/2007 16:05:32 org.apache.commons.digester.Digester endElement

Just use
  ConvertUtils.register(converter, Date.class)
where converter is your own implementation that handles dates however
you want. Digester simply calls the static beanutils method
ConvertUtils.convert.

Ideally, digester would have a ConvertUtils *instance* rather than
relying on the static singleton but that's old history. And in practice
no-one has ever cared.

> SEVERE: End event threw exception
> org.apache.commons.beanutils.ConversionException: DateConverter does
> not support default String to 'Date' conversion.
> </code>
> 
> In the middle of the msgs above there is one that called my attention:
> N.B. Re-configure Converter or use alternative implementation
> 
> According BeanUtils docs I can do that, but I didn't find any
> information on how to do that
> with Digester.
> 
> Debugging Digester source code I've found
> DateTimeConverter.convertToType() method
> that has the following "if (useLocaleFormat) ..." which, I guess,
> could do the job, but I
> don't know how to setup locale info so that the conversion can be done.

Hmm.. I don't remember any code like that. What class is that in? Are
you sure you're not looking at code inside beanutils?


Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org