commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Digester and Struts...
Date Mon, 25 Feb 2002 17:21:45 GMT
There is a part of this that is parser-related and part that is Digester
related.  See intermixed responses below.

On Mon, 25 Feb 2002, Keith Chew wrote:

> Date: Mon, 25 Feb 2002 18:07:18 +1300
> From: Keith Chew <keith.chew@jungledrum.co.nz>
> Reply-To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> Subject: Digester and Struts...
>
> Hi
>
> I have having a problem with the Digester package. Using Struts, I have
> edited the struts-config.xml file to:
>
> <?xml version="1.0"?>
> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
> Configuration 1.0//EN"
>           "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd" [
>
>     <!ENTITY part1 SYSTEM "file:part1.xml">
>     <!ENTITY part2 SYSTEM "file:part2.xml">
>     <!ENTITY part3 SYSTEM "file:part3.xml">
> ]>
>

The above URLs assume that your webapp is running in an unpacked directory
that can be accessed with file I/O -- a dubious assumption in many servlet
containers.  Try a relative URL like this:

    <!ENTITY part1 SYSTEM "part1.xml">

instead.  That way, the URL is explicitly recognized as being relative to
the owning document, whatever it's URL is -- and it won't be a file URL if
you do something like this to create the input stream:

  InputStream is =
    getServletContext().getResourceAsStream("/WEB-INF/struts-config.xml");

This is what Struts does.

> <struts-config>
> 	<form-beans>
>         &part1;
> 	</form-beans>
>
> 	<global-forwards>
>         &part2;
> 	</global-forwards>
>
> 	<action-mappings>
>         &part3;
> 	</action-mappings>
> </struts-config>
>
> where part1.xml, part2.xml and part3.xml are in the same folder as
> struts-config.xml.
>
> I get the exception File part1.xml cannot be found.
>
> I have reported this to the Xerces mailing list and they said that before
> parsing the file, you need to set the systemId, eg:
>
> source.setSystemId("file:" + getServletConfig().getAbsolutePath() + "/" +
> fileName);
>

Well, this doesn't exactly work because there is no "getAbsolutePath()"
method on the ServletConfig interface.  The closest analog would be:

  source.setSystemId("file:" + getServletContext().getRealPath("/") + "/"
    + fileName);

However, that still sticks you with using file i/o exclusively -- and this
solution doesn't help you for Struts in any case because it doesn't use
the InputSource option for processing input.

You're much better off using actual relative URLs, as described above.

> This will allow the part1.xml, part2.xml and part3.xml to be found. Looking
> at the Digester class, it does not do this. Can we fix this problem?
>
> Keith
>

Craig


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message