You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stefan Arentz <st...@powerdns.com> on 2002/05/01 19:20:48 UTC

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 <vi...@mail.qic-software.com>
>> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
>>      vijay@mail.qic-software.com
>> To: struts-user@jakarta.apache.org
>> 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>vijay@qic-software.com</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?

  Stefan


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Help required on Digester class

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 1 May 2002, Stefan Arentz wrote:

> Date: Wed, 1 May 2002 20:55:20 +0200
> From: Stefan Arentz <st...@powerdns.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Re: Help required on Digester class
>
>
> On Wednesday, May 1, 2002, at 08:23  PM, Craig R. McClanahan wrote:
>
> ...
>
> >> 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.
>
> Hmm. I had not thought about the property setter. My problem is that I
> need to give feedback to the user about where exactly in the XML
> document the wrong input was given. Preferably with a line number. Is
> there a way to get that information from the parser, or is all that
> logic buried deep in the Digester class?
>

You could do this by firing a SAXException that will get rippled up.
You'd probably also need to provide your own ErrorHandler interface so
that such errors were not fatal to the parsing (if they were, you'd only
detect the first one).

>   Stefan
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Help required on Digester class

Posted by Stefan Arentz <st...@powerdns.com>.
On Wednesday, May 1, 2002, at 08:23  PM, Craig R. McClanahan wrote:

...

>> 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.

Hmm. I had not thought about the property setter. My problem is that I 
need to give feedback to the user about where exactly in the XML 
document the wrong input was given. Preferably with a line number. Is 
there a way to get that information from the parser, or is all that 
logic buried deep in the Digester class?

  Stefan


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Help required on Digester class

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 1 May 2002, Stefan Arentz wrote:

> Date: Wed, 1 May 2002 19:20:48 +0200
> From: Stefan Arentz <st...@powerdns.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> 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 <vi...@mail.qic-software.com>
> >> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
> >>      vijay@mail.qic-software.com
> >> To: struts-user@jakarta.apache.org
> >> 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>vijay@qic-software.com</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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>