private boolean isSubfile(File root, File selection) { if (selection == null || "".equals(selection.getPath())) return false; if (selection.equals(root)) return true; return isSubfile(root, selection.getParentFile()); }
private boolean isSubfile(File root, File selection) { if(selection == null || "".equals(selection.getPath())) return false; if(selection.equals(root)) return true; return isSubfile(root, selection.getParentFile()); }
public void setObject(String location) { if (location != null) { File dataDirectory = canonicalize(rootDir); File file = canonicalize(new File(location)); if (isSubfile(dataDirectory, file)) { File curr = file; String path = null; // paranoid check to avoid infinite loops while (curr != null && !curr.equals(dataDirectory)) { if (path == null) { path = curr.getName(); } else { path = curr.getName() + "/" + path; } curr = curr.getParentFile(); } location = "file:" + path; } else { File dataFile = Files.url(rootDir, location); if (dataFile != null && !dataFile.equals(file)) { // relative to the data directory, does not need fixing } else { location = "file://" + file.getAbsolutePath(); } } } delegate.setObject(location); }
public void setObject(Object object) { String location = (String) object; File dataDirectory = canonicalize(GeoserverDataDirectory.getGeoserverDataDirectory()); File file = canonicalize(new File(location)); if(isSubfile(dataDirectory, file)) { File curr = file; String path = null; // paranoid check to avoid infinite loops while(curr != null && !curr.equals(dataDirectory)){ if(path == null) { path = curr.getName(); } else { path = curr.getName() + "/" + path; } curr = curr.getParentFile(); } location = "file:" + path; } else if(!GeoserverDataDirectory.findDataFile(location).equals(file)) { // relative to the data directory, does not need fixing } else { location = "file://" + file.getAbsolutePath(); } delegate.setObject(location); }