if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("resolve(href = " + href +
", base = " + base + "); resolver = " + resolver);
}
Source xslSource = null;
try {
if (href.indexOf(":") > 1) {
xslSource = resolver.resolve(href);
} else {
// patch for a null pointer passed as base
if (base == null)
throw new IllegalArgumentException("Null pointer passed as base");
// is the base a file or a real url
if (!base.startsWith("file:")) {
int lastPathElementPos = base.lastIndexOf('/');
if (lastPathElementPos == -1) {
// this should never occur as the base should
// always be protocol:/....
return null; // we can't resolve this
} else {
xslSource = resolver.resolve(new StringBuffer(base.substring(0, lastPathElementPos))
.append("/").append(href).toString());
}
} else {
File parent = new File(base.substring(5));
File parent2 = new File(parent.getParentFile(), href);
xslSource = resolver.resolve(parent2.toURL().toExternalForm());
}
}
InputSource is = xslSource.getInputSource();
if (this.getLogger().isDebugEnabled()) {
getLogger().debug("xslSource = " + xslSource
+ ", system id = " + is.getSystemId());
}
return new StreamSource(is.getByteStream(), is.getSystemId());
} catch (ResourceNotFoundException rnfe) {
// to obtain the same behaviour as when the resource is
// transformed by the XSLT Transformer we should return null here.
return null;
} catch (java.net.MalformedURLException mue) {
return null;
} catch (IOException ioe) {
return null;
} catch (SAXException se) {
throw new TransformerException(se);
} catch (ProcessingException pe) {
throw new TransformerException(pe);
} finally {
if (xslSource != null) xslSource.recycle();
}
}