Source inputSource = null;
try {
inputSource = this.resolver.resolveURI(directory);
String systemId = inputSource.getURI();
if (!systemId.startsWith(FILE)) {
throw new ResourceNotFoundException(systemId + " does not denote a directory");
}
// This relies on systemId being of the form "file://..."
File directoryFile = new File(new URL(systemId).getFile());
if (!directoryFile.isDirectory()) {
throw new ResourceNotFoundException(directory + " is not a directory.");
}
this.contentHandler.startDocument();
this.contentHandler.startPrefixMapping(PREFIX, URI);
Stack ancestors = getAncestors(directoryFile);
addAncestorPath(directoryFile, ancestors);
this.contentHandler.endPrefixMapping(PREFIX);
this.contentHandler.endDocument();
} catch (SourceException se) {
throw SourceUtil.handle(se);
} catch (IOException ioe) {
throw new ResourceNotFoundException("Could not read directory " + directory, ioe);
} finally {
this.resolver.release(inputSource);
}
}