credentials = new SimpleCredentials(basic[0], basic[1].toCharArray());
} else {
throw new LoginException();
}
ContentSession session = repository.login(credentials, null);
try {
Root root = session.getLatestRoot();
request.setAttribute("root", root);
// Find the longest part of the given path that matches
// an existing node. The tail part might be used when
// creating new nodes or when exposing virtual resources.
// Note that we need to traverse the path in reverse
// direction as some parent nodes may be read-protected.
String head = request.getPathInfo();
String tail = "";
Tree tree = root.getTree(head);
while (!tree.exists()) {
if (tree.isRoot()) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
tail = "/" + tree.getName() + tail;
tree = tree.getParent();
}
request.setAttribute("tree", tree);
request.setAttribute("path", tail);
super.service(request, response);
} finally {
session.close();
}
} catch (NoSuchWorkspaceException e) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} catch (LoginException e) {
response.setHeader("WWW-Authenticate", "Basic realm=\"Oak\"");