On Mon, 10 Jun 2002, Struts Newsgroup wrote:
> Date: Mon, 10 Jun 2002 01:10:02 -0700
> From: Struts Newsgroup <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Struts Digester question...
>
> Subject: Struts Digester question...
> From: "Scott Curtis" <[EMAIL PROTECTED]>
> ===
> Hi,
>
> When I start my server and Struts loads I am seeing the following line in
> the console:
>
> register('-//Apache Software Foundation//DTD Struts Configuration 1.0//EN',
> 'classloader:/org/apache/struts/resources/struts-config_1_0.dtd'
>
> I am not 100% sure what this is doing which is the first problem. I guess it
> is somehow adding the DTD to the classpath so that it is accessible from
> within xml files using the dtd name (struts-config_1_0.dtd) rather than a
> full path/URL to the dtd file.
>
> I would like to add my own DTD in a similar way so that xml files that I
> pass into the system can access it by it's name and not require a full path
> to the dtd file. If the above line of code doesn't do what I have suggested
> is there a way to add a DTD in the manner I have suggested so that the xml
> files to be validated against it can reference it by it's name only and not
> the full URL/path?
>
> Hope that makes some sense to someone out there! :-)
>
If you look inside Digester, you will find that that it uses a SAX parser,
via the JAXP APIs. SAX lets you register an "EntityHandler" object that
is called during the parse when a <!DOCTYPE> is encountered. As you might
surmize, the registration noted by the log message is telling Digester
"whenever you see the public identifier of the Struts configuration file
DTD, use this copy instead of going out to the Internet."
The important issue, though, is where the second URL came from -- if the
resource is inside your webapp, you *must* ask your servlet container for
the URL of the requested resource. There are two basic options:
(1) Resource file somewhere within your webapp (i.e. "/WEB-INF/mydtd.dtd")
Digester digester = ...;
digester.register("... public id for my DTD ...",
context.getResource("/WEB-INF/mydtd.dtd").toString());
(2) Resource file somewhere in the class path (this is what Struts
does ... the DTD it is loading is in the org/apache/struts/resources
package in struts.jar):
Digester digester = ...;
URL url = this.getClass().getResource("/path/to/mydtd.dtd");
digester.register("... public id for my DTD ...",
url.toString());
As long as your XML documents have a DOCTYPE with a public identifier that
matches the first argument to the register() method, then the XML parser
will use the URL passed as the second argument to retrieve the DTD,
instead of paying attention to any system identifier in the DOCTYPE.
> Thanks
> - scott
>
Craig
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>