commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject [digester] relative path in a jar
Date Tue, 20 Jun 2006 11:02:33 GMT
Hi Eitan,

On Tue, 2006-06-20 at 09:55 +0200, Eitan Gur wrote:
> Hi all
> I just noticed I wasn't clean - my question is related to the Digester project.

The convention on this (shared) list is to put the commons project at
the start of the subject line. I've changed this email's subject

Unfortunately not a lot of people use the xmlrules module so advice is a
little difficult to get for it. I don't use it myself, but here's what I
can see from looking at the source code. For further details you may
need to look at the source code yourself; it isn't too difficult.

The main class involved in processing xml rule input files is:
which can be seen here:

The <include> tag is processed by the nested IncludeRule class (xmlrules
uses Digester rules to process the rules.xml files :-). The critical bit
is this:
  String fileName = attributes.getValue("path");
which in turn does this:
   ClassLoader cl = ....
   URL fileURL = cl.getResource(fileName);
   fileName = fileURL.toExternalForm();
   Digester digester = new Digester();

Because the cl.getResource(fileName) is just passing the "path" property
read from the include tag, it therefore looks to me like this code
allows <include> to reference other files in the classpath (including in
jars), but that it doesn't support paths *relative* to the file [1]
doing the including; you have to do:
  <include path="foo/bar1/sub1.xml"/>
even when the including xml is foo/master.xml.
(NOTE: this is just my understanding from looking at the source code).

If you really need this functionality, it looks like you'll have to
create a customised DigesterRuleParser implementation.

If you do implement this, and are willing to contribute that improvement
back to the Digester project then I'm sure that would be appreciated. I
could probably find time to review it/commit it, but don't have any
particular interest in writing this functionality myself.

Any particular reas

[1] actually, the thing doing the including isn't a "file" in your case,
but a "resource" bundled inside a jar.

> I have a question regarding the <include> element, specifically when I want to
include a file in a jar-packed application.
> I'm using JBoss application server, and I want to use digester in my application. As
it's packed in a jar (which is packed in an ear), I need to use relative paths for the rules
xml files.
> I have a master rules file, and several other included files, residing in subfolders
(of the master file), something like:
> foo/master.xml ->
>             bar1/sub1.xml
>             bar2/sub2.xml
> (where bar1 and bar2 are subfolders of foo).
> The master.xml should look something like this:
> <digester-rules>
>             <include path="[What should be the path of sub1.xml???]" />
>             <include path="[What should be the path of sub2.xml???]" />
> </digester-rules>
> I managed to resolve the relative path issue for the master file from the source code
(using getClass().getResource()), but I don't know how to resolve this issue for the <include>
elements in the master file.
> Thanks for your help.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message