in src/main/java/org/apache/sling/testing/mock/jcr/ResourceUtil.java [116:155]
public static String getParent(String path) {
if ("/".equals(path)) {
return null;
}
// normalize path (remove . and ..)
path = normalize(path);
// if normalized to root, there is no parent
if (path == null || "/".equals(path)) {
return null;
}
String workspaceName = null;
final int wsSepPos = path.indexOf(":/");
if (wsSepPos != -1) {
workspaceName = path.substring(0, wsSepPos);
path = path.substring(wsSepPos + 1);
}
// find the last slash, after which to cut off
int lastSlash = path.lastIndexOf('/');
if (lastSlash < 0) {
// no slash in the path
return null;
} else if (lastSlash == 0) {
// parent is root
if (workspaceName != null) {
return workspaceName + ":/";
}
return "/";
}
String parentPath = path.substring(0, lastSlash);
if (workspaceName != null) {
return workspaceName + ":" + parentPath;
}
return parentPath;
}