commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig McClanahan <craig...@gmail.com>
Subject Re: [Digester] Unable to get validation working
Date Tue, 26 Apr 2005 05:13:02 GMT
On 4/25/05, Frank W. Zammetti <fzlists@omnytex.com> wrote:
> Whew!  Got it!
> 
> Wendy, you WERE right, at least partially, in terms of the point on
> pathing... what I wound up doing was putting the DTD in a JAR in the
> webapp lib directory, so it's of course in the path.  In the code I do:
> 
> URL cURL = this.getClass().getResource("my/app/myConfig.dtd");
> digester.register("myConfig", cURL.toString());
> 
> ...where the path in the getResource() call matches the path where the
> DTD is in the JAR.

This exact same code will also work if you had your DTD at
"/WEB-INF/lib/classes/my/app/myConfig.dtd" -- because the
WEB-INF/classes directory is also placed on the classpath for you.

> 
> The last piece of the puzzle though, which took about 45 minutes of
> banging my head on the desk to figure out, was the DOCTYPE definition in
> the XML file I was trying to validate.  I had to use:
> 
> <!DOCTYPE myConfig PUBLIC "myConfig" "myConfig">
> 
> It seemed more logical to use SYSTEM, but it kept trying to pull the
> file from various locations on the local file system, as the name
> indicates).  Even when I tried to get the path to point at the actual
> file in WEB-INF for instance though, it would never work for one reason
> or another.  This, even though it doesn't seem right to me (and maybe
> it's not!) *does* work.
> 

PUBLIC is definitely what you want for this sort of thing.  There's
also conventional formats for the public identifier and system
identifier if this DTD was going to be a public thing ... but it
doesn't matter for application private things.

> Cool, one step closer to completion!
> 

Now that you got this working (sorry I didn't get a chance to respond
earlier) ... there actually is a way to access resources that are in
WEB-INF but not in the classpath.  That's because ServletContext has
getResource() and getResourceAsStream() methods just like Class does.

    ServletContext context = ...;
    URL cURL = context.getResource("/WEB-INF/myConfig.dtd");
    digester.register("myConfig", cURL.toString());

> Frank

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message