in src/main/java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java [416:443]
private static String getRelativePath(File root, File current, File other) throws Exception {
if (current.equals(other)) {
return "";
}
String rootPath = root.getCanonicalPath();
String currentPath = current.getCanonicalPath();
StringBuilder builder = new StringBuilder();
while (!rootPath.equals(currentPath)) {
current = current.getParentFile();
currentPath = current.getCanonicalPath();
builder.append("../");
}
String otherPath = other.getCanonicalPath();
if (rootPath.equals(otherPath)) {
// nothing to do
} else if (otherPath.startsWith(rootPath)) {
String name = otherPath.substring(rootPath.length() + 1);
builder.append(name);
builder.append("/");
} else {
throw new RuntimeException("Non-relative locations: " + rootPath + " " + otherPath);
}
return builder.toString();
}