protected static String getHierarchy(XPathPseudoParser parser, String contextPath, Database db) throws DBException, Exception {
StringBuffer result = new StringBuffer();
String path = parser.getPath();
Collection col;
if (!path.equals("")) {
col = db.getCollection(parser.getPath());
} else {
col = db;
}
if (col == null) {
result.append("Collection not found! " + parser.getPath());
return result.toString();
}
String[] cols = col.listCollections();
String dbLoc = parser.getDatabase();
String parserPath = parser.getPath();
StringBuffer baseHref = new StringBuffer();
baseHref.append("<a href=\"" + contextPath + "/?/" + dbLoc);
if(parserPath.startsWith("/") || dbLoc.endsWith("/")) {
baseHref.append(parserPath);
} else {
baseHref.append("/" + parserPath);
}
for (int i = 0; i < cols.length; i++) {
result.append(baseHref);
if(!baseHref.toString().endsWith("/")) {
result.append("/");
}
result.append(cols[i]);
result.append("\">");
result.append(cols[i]);
result.append("</a><br>");
}
try {
String[] docs = col.listDocuments();
for (int i = 0; i < docs.length; i++) {
result.append(baseHref);
result.append("&");
result.append(docs[i]);
result.append("\">");