private static String relativize(URI cwdUri, URI srcUri, boolean isDir) { String uriPath = srcUri.getPath(); String cwdPath = cwdUri.getPath(); if (cwdPath.equals(uriPath)) { return Path.CUR_DIR; } // find common ancestor int lastSep = findLongestDirPrefix(cwdPath, uriPath, isDir); StringBuilder relPath = new StringBuilder(); // take the remaining path fragment after the ancestor if (lastSep < uriPath.length()) { relPath.append(uriPath.substring(lastSep+1)); } // if cwd has a path fragment after the ancestor, convert them to ".." if (lastSep < cwdPath.length()) { while (lastSep != -1) { if (relPath.length() != 0) relPath.insert(0, Path.SEPARATOR); relPath.insert(0, ".."); lastSep = cwdPath.indexOf(Path.SEPARATOR, lastSep+1); } } return relPath.toString(); }
private static String relativize(URI cwdUri, URI srcUri, boolean isDir) { String uriPath = srcUri.getPath(); String cwdPath = cwdUri.getPath(); if (cwdPath.equals(uriPath)) { return Path.CUR_DIR; } // find common ancestor int lastSep = findLongestDirPrefix(cwdPath, uriPath, isDir); StringBuilder relPath = new StringBuilder(); // take the remaining path fragment after the ancestor if (lastSep < uriPath.length()) { relPath.append(uriPath.substring(lastSep+1)); } // if cwd has a path fragment after the ancestor, convert them to ".." if (lastSep < cwdPath.length()) { while (lastSep != -1) { if (relPath.length() != 0) relPath.insert(0, Path.SEPARATOR); relPath.insert(0, ".."); lastSep = cwdPath.indexOf(Path.SEPARATOR, lastSep+1); } } return relPath.toString(); }
private static String relativize(URI cwdUri, URI srcUri, boolean isDir) { String uriPath = srcUri.getPath(); String cwdPath = cwdUri.getPath(); if (cwdPath.equals(uriPath)) { return Path.CUR_DIR; } // find common ancestor int lastSep = findLongestDirPrefix(cwdPath, uriPath, isDir); StringBuilder relPath = new StringBuilder(); // take the remaining path fragment after the ancestor if (lastSep < uriPath.length()) { relPath.append(uriPath.substring(lastSep+1)); } // if cwd has a path fragment after the ancestor, convert them to ".." if (lastSep < cwdPath.length()) { while (lastSep != -1) { if (relPath.length() != 0) relPath.insert(0, Path.SEPARATOR); relPath.insert(0, ".."); lastSep = cwdPath.indexOf(Path.SEPARATOR, lastSep+1); } } return relPath.toString(); }
private static String relativize(URI cwdUri, URI srcUri, boolean isDir) { String uriPath = srcUri.getPath(); String cwdPath = cwdUri.getPath(); if (cwdPath.equals(uriPath)) { return Path.CUR_DIR; } // find common ancestor int lastSep = findLongestDirPrefix(cwdPath, uriPath, isDir); StringBuilder relPath = new StringBuilder(); // take the remaining path fragment after the ancestor if (lastSep < uriPath.length()) { relPath.append(uriPath.substring(lastSep+1)); } // if cwd has a path fragment after the ancestor, convert them to ".." if (lastSep < cwdPath.length()) { while (lastSep != -1) { if (relPath.length() != 0) relPath.insert(0, Path.SEPARATOR); relPath.insert(0, ".."); lastSep = cwdPath.indexOf(Path.SEPARATOR, lastSep+1); } } return relPath.toString(); }
private static String relativize(URI cwdUri, URI srcUri, boolean isDir) { String uriPath = srcUri.getPath(); String cwdPath = cwdUri.getPath(); if (cwdPath.equals(uriPath)) { return Path.CUR_DIR; } // find common ancestor int lastSep = findLongestDirPrefix(cwdPath, uriPath, isDir); StringBuilder relPath = new StringBuilder(); // take the remaining path fragment after the ancestor if (lastSep < uriPath.length()) { relPath.append(uriPath.substring(lastSep+1)); } // if cwd has a path fragment after the ancestor, convert them to ".." if (lastSep < cwdPath.length()) { while (lastSep != -1) { if (relPath.length() != 0) relPath.insert(0, Path.SEPARATOR); relPath.insert(0, ".."); lastSep = cwdPath.indexOf(Path.SEPARATOR, lastSep+1); } } return relPath.toString(); }