You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Dimitri Frederickx <di...@aircrew.be> on 2005/12/30 14:41:11 UTC
[Digester] How to map html-td elements to methods?
Hi, I've used commons digester in a few applications, but now I want to do a
mapping that is a little bit tricky.
This is an extract of my xml (xhtlm) file:
<tbody>
<tr>
<td class="command">open</td>
<td class="target">./tests/html/test_open.html</td>
<td class="value"> </td>
</tr>
<tr>
<td class="command">verifyLocation</td>
<td class="target">/tests/html/test_open.html</td>
<td class="value"> </td>
</tr>
</tbody>
This is a part of my java source file:
public class Test {
private String command;
private String target;
private String value;
public void setCommand(String functionName) {
this.command = functionName;
}
public void setTarget(String target) {
this.target = target;
}
public void setValue(String value) {
this.value = value;
}
}
I want that the value of the class-attribute maps to the property (and
method name), and the value of the tag must be the value to pass to this
method.
Is there a way to do this with digester? Does anyone has done something like
this? It would help me a lot, because I'm really stuck at this moment.
Regards,
Dimitri
RE: [Digester] How to map html-td elements to methods?
Posted by Simon Kitching <sk...@apache.org>.
Hi Dimitri,
Adding custom rules using the xml-rules module is quite awkward. That's
one of the reasons I dislike xml-rules. I recommend you avoid it, and
write your rules using java.
http://wiki.apache.org/jakarta-commons/Digester/FAQ/XmlRulesOrNotXmlRules
Regards,
Simon
On Fri, 2005-12-30 at 23:49 +0100, Dimitri Frederickx wrote:
> Thanks a lot, I'll try to make my own rule. To add a rule, do I always have
> to do that in java the way you described it, or can I also add the rule by
> configuring it in the xml-file? Normally I always describe my rules in xml,
> and this way a can keep all the rules at one place. Can I do that or does it
> has to be in java?
>
> Regards,
> Dimitri
>
>
> -----Original Message-----
> From: Simon Kitching [mailto:skitching@apache.org]
> Sent: vrijdag 30 december 2005 23:40
> To: Jakarta Commons Users List
> Subject: Re: [Digester] How to map html-td elements to methods?
>
> On Fri, 2005-12-30 at 14:41 +0100, Dimitri Frederickx wrote:
>
> > <td class="command">open</td>
> > <td class="target">./tests/html/test_open.html</td>
> >
> >
> > I want that the value of the class-attribute maps to the property (and
> > method name), and the value of the tag must be the value to pass to this
> > method.
> >
> > Is there a way to do this with digester? Does anyone has done something
> like
> > this? It would help me a lot, because I'm really stuck at this moment.
>
> I don't believe there is an existing rule that does exactly what you
> want, but you should be able to create your own rule to achieve your
> goal. I would suggest starting with BeanPropertySetterRule, then
> modifying the begin method so that it saves away the target property
> name in a member variable for later use. Using member variables like
> that isn't actually a good idea in general (doesn't work when rules are
> nested) but in this case it's fine as this rule won't be nested.
>
> Don't be concerned about creating your own rule; that's not unusual, nor
> particularly difficult.
>
> Once you've got your custom rule class, just add it do digester like:
> digester.addRule("tbody/tr/td", new MyNewRule());
>
> Regards,
>
> Simon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
RE: [Digester] How to map html-td elements to methods?
Posted by Dimitri Frederickx <di...@aircrew.be>.
Thanks a lot, I'll try to make my own rule. To add a rule, do I always have
to do that in java the way you described it, or can I also add the rule by
configuring it in the xml-file? Normally I always describe my rules in xml,
and this way a can keep all the rules at one place. Can I do that or does it
has to be in java?
Regards,
Dimitri
-----Original Message-----
From: Simon Kitching [mailto:skitching@apache.org]
Sent: vrijdag 30 december 2005 23:40
To: Jakarta Commons Users List
Subject: Re: [Digester] How to map html-td elements to methods?
On Fri, 2005-12-30 at 14:41 +0100, Dimitri Frederickx wrote:
> <td class="command">open</td>
> <td class="target">./tests/html/test_open.html</td>
>
>
> I want that the value of the class-attribute maps to the property (and
> method name), and the value of the tag must be the value to pass to this
> method.
>
> Is there a way to do this with digester? Does anyone has done something
like
> this? It would help me a lot, because I'm really stuck at this moment.
I don't believe there is an existing rule that does exactly what you
want, but you should be able to create your own rule to achieve your
goal. I would suggest starting with BeanPropertySetterRule, then
modifying the begin method so that it saves away the target property
name in a member variable for later use. Using member variables like
that isn't actually a good idea in general (doesn't work when rules are
nested) but in this case it's fine as this rule won't be nested.
Don't be concerned about creating your own rule; that's not unusual, nor
particularly difficult.
Once you've got your custom rule class, just add it do digester like:
digester.addRule("tbody/tr/td", new MyNewRule());
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Digester] How to map html-td elements to methods?
Posted by Simon Kitching <sk...@apache.org>.
On Fri, 2005-12-30 at 14:41 +0100, Dimitri Frederickx wrote:
> <td class="command">open</td>
> <td class="target">./tests/html/test_open.html</td>
>
>
> I want that the value of the class-attribute maps to the property (and
> method name), and the value of the tag must be the value to pass to this
> method.
>
> Is there a way to do this with digester? Does anyone has done something like
> this? It would help me a lot, because I'm really stuck at this moment.
I don't believe there is an existing rule that does exactly what you
want, but you should be able to create your own rule to achieve your
goal. I would suggest starting with BeanPropertySetterRule, then
modifying the begin method so that it saves away the target property
name in a member variable for later use. Using member variables like
that isn't actually a good idea in general (doesn't work when rules are
nested) but in this case it's fine as this rule won't be nested.
Don't be concerned about creating your own rule; that's not unusual, nor
particularly difficult.
Once you've got your custom rule class, just add it do digester like:
digester.addRule("tbody/tr/td", new MyNewRule());
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org