throw new XPathException("Fragment identifier not supported for preloaded documents");
}
// Resolve relative URI
String documentKey;
URIResolver resolver = config.getURIResolver();
if (resolver instanceof RelativeURIResolver) {
try {
documentKey = ((RelativeURIResolver)resolver).makeAbsolute(href, baseURI);
} catch (TransformerException e) {
documentKey = '/' + href;
baseURI = "";
}
} else {
if (baseURI==null) { // no base URI available
try {
// the href might be an absolute URL
documentKey = (new URI(href)).toString();
} catch (URISyntaxException err) {
// it isn't; but the URI resolver might know how to cope
documentKey = '/' + href;
baseURI = "";
}
} else if (href.length() == 0) {
// common case in XSLT, which java.net.URI#resolve() does not handle correctly
documentKey = baseURI;
} else {
try {
URI uri = new URI(baseURI).resolve(href);
documentKey = uri.toString();
} catch (URISyntaxException err) {
documentKey = baseURI + "/../" + href;
} catch (IllegalArgumentException err) {
documentKey = baseURI + "/../" + href;
}
}
}
// see if the document is already loaded
DocumentInfo doc = config.getGlobalDocumentPool().find(documentKey);
if (doc != null) {
return doc;
}
try {
// Get a Source from the URIResolver
URIResolver r = resolver;
Source source = null;
if (r != null) {
try {
source = r.resolve(href, baseURI);
} catch (Exception ex) {
XPathException de = new XPathException("Exception thrown by URIResolver", ex);
if (config.isTraceExternalFunctions()) {
ex.printStackTrace();
}
de.setLocator(locator);
throw de;
}
}
// if a user URI resolver returns null, try the standard one
// (Note, the standard URI resolver never returns null)
if (source==null && !(r instanceof NonDelegatingURIResolver)) {
r = config.getSystemURIResolver();
source = r.resolve(href, baseURI);
}
//System.err.println("URI resolver returned " + source.getClass() + " " + source.getSystemId());
source = config.getSourceResolver().resolveSource(source, config);
//System.err.println("Resolved source " + source.getClass() + " " + source.getSystemId());