private Source getSource(InputStream is, Resource resource)
throws ParserConfigurationException, SAXException {
// todo: is this comment still relevant ??
// FIXME: need to use a SAXSource as the source for the transform
// so we can plug in our own entity resolver
Source src = null;
if (entityResolver != null) {
if (getFactory().getFeature(SAXSource.FEATURE)) {
SAXParserFactory spFactory = SAXParserFactory.newInstance();
spFactory.setNamespaceAware(true);
XMLReader reader = spFactory.newSAXParser().getXMLReader();
reader.setEntityResolver(entityResolver);
src = new SAXSource(reader, new InputSource(is));
} else {
throw new IllegalStateException("xcatalog specified, but "
+ "parser doesn't support SAX");
}
} else {
// WARN: Don't use the StreamSource(File) ctor. It won't work with
// xalan prior to 2.2 because of systemid bugs.
src = new StreamSource(is);
}
// The line below is a hack: the system id must an URI, but it is not
// cleat to get the URI of an resource, so just set the name of the
// resource as a system id
src.setSystemId(resourceToURI(resource));
return src;
}