href = href.substring(0, hash);
} else {
fragmentId = href.substring(hash+1);
href = href.substring(0, hash);
if (!NameChecker.isValidNCName(fragmentId)) {
XPathException de = new XPathException("The fragment identifier " + Err.wrap(fragmentId) + " is not a valid NCName");
de.setErrorCode("XTRE1160");
de.setXPathContext(c);
throw de;
}
}
}
Controller controller = c.getController();
// Resolve relative URI
DocumentURI documentKey = computeDocumentKey(href, baseURI);
// see if the document is already loaded
DocumentInfo doc = config.getGlobalDocumentPool().find(documentKey);
if (doc != null) {
return doc;
}
DocumentPool pool = controller.getDocumentPool();
doc = pool.find(documentKey);
if (doc != null) {
return getFragment(doc, fragmentId, c);
}
// check that the document was not written by this transformation
if (!controller.checkUniqueOutputDestination(documentKey)) {
pool.markUnavailable(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 {
if (pool.isMarkedUnavailable(documentKey)) {
XPathException err = new XPathException(
"Document has been marked not available: " + documentKey);
err.setXPathContext(c);
err.setErrorCode("FODC0002");
throw err;
}
DocumentInfo newdoc = config.buildDocument(documentKey.toString());
controller.registerDocument(newdoc, documentKey);
controller.addUnavailableOutputDestination(documentKey);
return getFragment(newdoc, fragmentId, c);
} catch (XPathException err) {
pool.markUnavailable(documentKey);
err.maybeSetLocation(locator);
String code = (err.getCause() instanceof URI.URISyntaxException) ? "FODC0005" : "FODC0002";
err.maybeSetErrorCode(code);
controller.recoverableError(err);
return null;
}
}