예제 #1
1
  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);
  }
예제 #2
0
  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;
  }
예제 #3
0
  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();
  }