} else {
try {
DbCollection rootColl = DbCollection.getRootCollection();
catalog = rootColl.listDocuments(dynEnv);
} catch (DbException e) {
throw new XQueryException("failed loading default collection", e);
}
}
} else {
Item arg = argv.getItem(0);
String argStr = arg.stringValue();
final String unescapedArg = XMLUtils.unescapeXML(argStr);
if(unescapedArg.endsWith(".catalog")) {
URI baseUri = dynEnv.getStaticContext().getBaseURI();
if(baseUri == null) { // TODO REVIEWME workaround
baseUri = dynEnv.getStaticContext().getSystemBaseURI();
}
URI resolved = baseUri.resolve(unescapedArg);
final URL colurl;
try {
colurl = resolved.toURL();
} catch (MalformedURLException e) {
throw new DynamicError("Invalid uri: " + argStr);
}
DocumentManager docmgr = dynEnv.getDocumentManager();
DTMDocument doc = docmgr.loadDocument(colurl, dynEnv);
catalog = resolveCatalog(doc, dynEnv);
} else if(unescapedArg.startsWith("/")) {
DbCollection coll = DbCollection.getCollection(unescapedArg);
if(coll == null) {
catalog = Collections.emptyMap();
} else {
final String filter = DbCollection.getDocumentFilterExp(unescapedArg);
try {
catalog = coll.listDocuments(filter, true, dynEnv);
} catch (DbException e) {
throw new XQueryException("failed loading collection: " + unescapedArg, e);
}
}
} else {
throw new XQueryException("Illeagl collection name: " + unescapedArg);
}
}
Profiler profiler = dynEnv.getProfiler();
final Collection<DTMDocument> docs = catalog.values();
final NodeSequence<DTMDocument> ret = new NodeSequence<DTMDocument>(dynEnv);