@Override
protected Item perform() throws RepositoryException {
if (depth < 0) {
throw new ItemNotFoundException(this + ": Invalid ancestor depth (" + depth + ')');
} else if (depth == 0) {
NodeDelegate nd = sessionDelegate.getRootNode();
if (nd == null) {
throw new AccessDeniedException("Root node is not accessible.");
}
return sessionContext.createNodeOrNull(nd);
}
String path = dlg.getPath();
int slash = 0;
for (int i = 0; i < depth - 1; i++) {
slash = PathUtils.getNextSlash(path, slash + 1);
if (slash == -1) {
throw new ItemNotFoundException(this + ": Invalid ancestor depth (" + depth + ')');
}
}
slash = PathUtils.getNextSlash(path, slash + 1);
if (slash == -1) {
return ItemImpl.this;
}
NodeDelegate nd = sessionDelegate.getNode(path.substring(0, slash));
if (nd == null) {
throw new AccessDeniedException(this + ": Ancestor access denied (" + depth + ')');
}
return sessionContext.createNodeOrNull(nd);
}