Hi everyone,

I'm playing with Digester, trying to use it to transform XML WebDAV 
request bodies into my custom object model, and I've encountered a 
couple of problems quite early in the process.

The first is that WebDAV allows elements of arbritrary namespaces inside 
the standard elements (custom properties), and those elements need to be 
processed.

Example from the spec (RFC 2518):

   <?xml version="1.0" encoding="utf-8" ?>
   <D:propfind xmlns:D="DAV:">
     <D:prop xmlns:R="http://www.foo.bar/boxschema/";>
       <R:bigbox/>
       <R:author/>
       <R:DingALing/>
       <R:Random/>
     </D:prop>
   </D:propfind>

The structure and semantics of the elements in the "DAV:" namespace are 
well defined and reflected in the object model, but the other elements 
in to be processed, in this case by simply storing "QualifiedName" 
objects in a list.

So I've set up the rules in a RuleSet like this:

   digester.setRuleNamespaceURI("DAV:");
   digester.addRule("propfind/prop",
                    new ObjectCreateRule(Propfind.class));
   digester.addRule("propfind/prop",
                    new SetNextRule("setPropfind"));
   digester.setRuleNamespaceURI(null);
   digester.addRule("propfind/prop/?",
     new FactoryCreateRule(QualifiedNameCreationFactory.class));
   digester.addRule("propfind/prop/?",
                    new SetNextRule("addPropertyToFind"));

First thing to note is the necessity to set the rule namespace URI
to null for the rules that should process the properties. Obviously, 
those rules would match a "propfind/prop/?" combination even if the 
namespace URIs of the elements "propfind" and "prop" were not "DAV:".
I don't see a solution to that, however.

The next problem is that in QualifiedNameCreationFactory, I need access 
to the namespace URI of the current element to be able to instantiate 
the QualifiedName object. I do have access to the local name of the 
element through Digester.getCurrentElementName().

As I've found no other way to accomplish this, I've hacked Digester to 
add a getCurrentNamespaceURI() method. That modification works for me, 
but maybe there's a better solution ?

BTW, I think it would be far more natural if the namespace URI and the 
name of the element would be passed into the Rule's begin() method. 
Especially when considering the ExtendedBaseRules' parent match feature, 
where the name of the element isn't as obvious as with the standard 
Rules implementation...

[Note: I am aware that Digester is more oriented towards config files 
and such, but if some features like the one above were available, it 
would be a very good fit for my purposes]

-- 
Christopher Lenz
/=/ cmlenz at gmx.de


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

Reply via email to