}
// Check if this DOM has already been added to the multiplexer
int mask = multiplexer.getDocumentMask(uri);
if (mask != -1) {
DOM newDom = ((DOMAdapter)multiplexer.getDOMAdapter(uri))
.getDOMImpl();
if (newDom instanceof DOMEnhancedForDTM) {
return new SingletonIterator(((DOMEnhancedForDTM)newDom)
.getDocument(),
true);
}
}
// Check if we can get the DOM from a DOMCache
DOMCache cache = translet.getDOMCache();
DOM newdom;
mask = multiplexer.nextMask(); // peek
if (cache != null) {
newdom = cache.retrieveDocument(base, originalUri, translet);
if (newdom == null) {
final Exception e = new FileNotFoundException(originalUri);
throw new TransletException(e);
}
} else {
String accessError = SecuritySupport.checkAccess(uri, translet.getAllowedProtocols(), XalanConstants.ACCESS_EXTERNAL_ALL);
if (accessError != null) {
ErrorMsg msg = new ErrorMsg(ErrorMsg.ACCESSING_XSLT_TARGET_ERR,
SecuritySupport.sanitizePath(uri), accessError);
throw new Exception(msg.toString());
}
// Parse the input document and construct DOM object
// Trust the DTMManager to pick the right parser and
// set up the DOM correctly.
XSLTCDTMManager dtmManager = (XSLTCDTMManager)multiplexer
.getDTMManager();
DOMEnhancedForDTM enhancedDOM =
(DOMEnhancedForDTM) dtmManager.getDTM(new StreamSource(uri),
false, null, true, false,
translet.hasIdCall(), cacheDOM);
newdom = enhancedDOM;
// Cache the stylesheet DOM in the Templates object
if (cacheDOM) {
TemplatesImpl templates = (TemplatesImpl)translet.getTemplates();
if (templates != null) {
templates.setStylesheetDOM(enhancedDOM);
}
}
translet.prepassDocument(enhancedDOM);
enhancedDOM.setDocumentURI(uri);
}
// Wrap the DOM object in a DOM adapter and add to multiplexer
final DOMAdapter domAdapter = translet.makeDOMAdapter(newdom);
multiplexer.addDOMAdapter(domAdapter);
// Create index for any key elements
translet.buildKeys(domAdapter, null, null, newdom.getDocument());
// Return a singleton iterator containing the root node
return new SingletonIterator(newdom.getDocument(), true);
} catch (Exception e) {
throw e;
}
}