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); }
private String sourceURL(String url) { File baseDirectory = dataDir().getResourceLoader().getBaseDirectory(); File file = Files.url(baseDirectory, url); if (file != null) { return Paths.convert(baseDirectory, file); } return url; }
private String source(URL url) { File baseDirectory = dataDir().getResourceLoader().getBaseDirectory(); if (url.getProtocol().equals("file")) { File file = Files.url(baseDirectory, url.toExternalForm()); if (file != null && !file.isAbsolute()) { return Paths.convert(baseDirectory, file); } } return url.toExternalForm(); }