commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: [digester] Parsing a schema instance / parsing dates
Date Mon, 28 Apr 2003 16:10:52 GMT


On Mon, 28 Apr 2003, Karol R├╝ckschloss wrote:

> Date: Mon, 28 Apr 2003 16:38:47 +0200
> From: Karol R├╝ckschloss <karol.rueckschloss@iqnex.com>
> Reply-To: Jakarta Commons Users List <commons-user@jakarta.apache.org>
> To: commons-user@jakarta.apache.org
> Subject: [digester] Parsing a schema instance / parsing dates
>
> Hello,
>
> I have used Digester for the last couple of weeks but never validated
> against a schema before.
>
> Now I'm in a situation where I want to make Digester respect a schema
> during the parsing. More specific, there are date fields in the XML
> documents that I'm parsing with Digester.
> ...
> <startDate>2003-28-04</startDate>
> ...
> What I tried to do is to
>      digester.setSchema(...);
>      digester.setValidating(true);
>
> However, even if I put an invalid date in the <startDate/>, Digester is
> still happy about it. I would actually want an exception to be thrown.
> The setSchema(String) call doesn't seem to have any effect. Am I doing
> something wrong?
>

I'm not a Schema user, so I can't help you with this one, but ...

> Another point with the dates. It would be excellent if Digester could
> recognize elements with type="xs:date" and accept a CallMethodRule, such as
> digester.addCallMethod(
>              "root/startDate",
>              "setStartDate",
>              0,
>              new Class[] { Date.class });
> Currently, this throws an ugly exception during the parsing because
> Digester doesn't realize that 2003-28-04 is a date...
>

You can fix this yourself by registering a custom Converter for a
java.util.Date object in org.apache.commons.beanutils.Converter.  There is
not a standard converter, because there is no standard locale-independent
string representation of a date.

Alternatively, you can make your bean property of type java.sql.Date
instead of java.util.Date -- there is a standard converter for that, which
uses string format from java.sql.Date.toString().

> Any help will be mostly appreciated.
>
> KarolR
>

Craig

Mime
View raw message