-----Original Message-----
From: Christophe Grosjean
[mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 07, 2003
5:18 AM
To: [EMAIL PROTECTED]
Subject: XInclude... is it the way
to make it working ?
Hi,
I tried the XInclude
feature. I had no problem in setting the XIncludeConfiguration and the parsing
includes well
relative and absolute
URI.
But…
I want to specify files
in may classpath instead of URI like :
<xi:include
href="">
instead of
<xi:include
href="">
Setting an EntityResolver
on the parser does’nt seem to work. The parser never asks the
EntityResolver
to do its job.
Here follows the code of
the EntityResolverWrapper that wraps the user-defined EntityResolver in Xerces
code.
It seems that the pubId
and sysId are always null, so the EntityResolver job is skipped. In my case, it
is
The
XMLResourceIdentifier. getLiteralSystemId() that contains the href String.
Is it a bug in the
EntityResolverWrapper ? Do I sth wrong ?
I found a workaround by
extending the XIncludeParserConfiguration and setting an custom
XMLEntityResolver.
Christophe.
public XMLInputSource
resolveEntity(XMLResourceIdentifier resourceIdentifier)
throws XNIException, IOException {
// When both pubId and sysId are null, the user's entity resolver
// can do nothing about it. We'd better not bother calling it.
// This happens when the resourceIdentifier is a GrammarDescription,
// which describes a schema grammar of some namespace, but without
// any schema location hint. -Sg
String pubId = resourceIdentifier.getPublicId();
String sysId = resourceIdentifier.getExpandedSystemId();
if (pubId == null && sysId == null)
return null;
// resolve entity using SAX entity resolver
if (fEntityResolver != null && resourceIdentifier != null) {
try {
InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);
if (inputSource != null) {
String publicId = inputSource.getPublicId();
String systemId = inputSource.getSystemId();
String baseSystemId = resourceIdentifier.getBaseSystemId();
InputStream byteStream = inputSource.getByteStream();
Reader charStream =
inputSource.getCharacterStream();
String encoding = inputSource.getEncoding();
XMLInputSource xmlInputSource =
new XMLInputSource(publicId, systemId, baseSystemId);
xmlInputSource.setByteStream(byteStream);
xmlInputSource.setCharacterStream(charStream);
xmlInputSource.setEncoding(encoding);
return xmlInputSource;
}
}
// error resolving entity
catch (SAXException e) {
Exception ex = e.getException();
if (ex == null) {
ex = e;
}
throw new XNIException(ex);
}
}
// unable to resolve entity
return null;
}