On Wed, 1 May 2002, Stefan Arentz wrote:

> Date: Wed, 1 May 2002 19:20:48 +0200
> From: Stefan Arentz <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: Struts Users Mailing List <[EMAIL PROTECTED]>
> Subject: Re: Help required on Digester class
>
>
> On Tuesday, April 30, 2002, at 05:24  PM, Craig R. McClanahan wrote:
>
> >
> >
> > On Tue, 30 Apr 2002, Vijay Arokayaraj wrote:
> >
> >> Date: Tue, 30 Apr 2002 05:18:39 -0700
> >> From: Vijay Arokayaraj <[EMAIL PROTECTED]>
> >> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>,
> >>      [EMAIL PROTECTED]
> >> To: [EMAIL PROTECTED]
> >> Subject: Help required on Digester class
> >>
> >> Hi all,
> >> I am new to struts. My question is do we have to use the Digester
> >> class to actually read any of the XML files? If so how do I actually
> >> map an XML file into a class object (class here represents a model)
> >> when the XML file has got multiple elements in them and is not
> >> attribuite oriented . For example
> >>
> >> <?xml version="1.0"?>
> >>       <user>
> >>             <name>vijay</name>
> >>              <mail>[EMAIL PROTECTED]</mail>
> >>        </user>
> >>
> >
> > One way to do this would be to define a Digester rule for each nested
> > property name:
> >
> >   digester.addObjectCreate("user", "com.mycompany.MyUserClass");
> >   digester.addCallMethod("user/name", "setName", 0);
> >   digester.addCallMethod("user/mail", "setMail", 0);
>
> Yup. This works fine. Digester is a great tool! One thing I'm looking at
> is how to combine it with a set of regular expression rules for the
> elements and attributes. Something like:
>
>   <command id="123">
>     <user username="stefan"/>
>   </command>
>
> With a property list:
>
>   command.id=/^\d+$/
>   user.username=/^[a-z0-9]+$/
>
> And make this part of the validation process. I'm interested in your
> thoughts about this. Is this something to add to the Digester core code
> or something that I should move to my own classes?
>

Do you mean that you want to ensure that the attributes match those
patterns?  Personally, I think that's a little out of scope for Digester,
although you could probably do it by implementing your own matching
algorithm in an org.apache.commons.digester.Rules implementation (either
don't select the rules on mismatched patterns, or throw an exception or
something).  Another alternative would be to throw an exception in the
property setter of the beans being created.

>   Stefan
>

Craig



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to