}
}
// see if the document is already loaded
DocumentInfo doc = config.getGlobalDocumentPool().find(documentKey);
if (doc != null) {
return doc;
}
doc = controller.getDocumentPool().find(documentKey);
if (doc != null) {
return getFragment(doc, fragmentId, c);
}
// check that the document was not written by this transformation
if (!controller.checkUniqueOutputDestination(documentKey)) {
XPathException err = new XPathException("Cannot read a document that was written during the same transformation: " + documentKey);
err.setXPathContext(c);
err.setErrorCode("XTRE1500");
throw err;
}
try {
// Get a Source from the URIResolver
Source source;
if (resolver instanceof RelativeURIResolver) {
try {
source = ((RelativeURIResolver)resolver).dereference(documentKey);
} catch (Exception ex) {
XPathException de = new XPathException("Exception thrown by URIResolver", ex);
if (controller.getConfiguration().isTraceExternalFunctions()) {
ex.printStackTrace();
}
de.setLocator(locator);
throw de;
}
} else {
try {
source = resolver.resolve(href, baseURI);
} catch (Exception ex) {
XPathException de = new XPathException("Exception thrown by URIResolver", ex);
if (controller.getConfiguration().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 && !(resolver instanceof NonDelegatingURIResolver)) {
resolver = controller.getStandardURIResolver();
if (resolver instanceof RelativeURIResolver) {
source = ((RelativeURIResolver)resolver).dereference(documentKey);
} else {
source = resolver.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());
DocumentInfo newdoc;
if (source instanceof NodeInfo || source instanceof DOMSource) {
NodeInfo startNode = controller.prepareInputTree(source);
newdoc = startNode.getDocumentRoot();
} else {
Builder b = controller.makeBuilder();