mergepath.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 730 行 · 第 1/2 页

JAVA
730
字号
    Path path = getBestPath();    return path.getNativePath();  }  /**   * Returns the URL of the best path.   */  public String getURL()  {    Path path = getBestPath();    if (! path.exists())      path = getWritePath();    return path.getURL();  }  /**   * Returns the relative path into the merge path.   */  public String getRelativePath()  {    if (_pathname.startsWith("/"))      return "." + _pathname;    else      return _pathname;  }  /**   * True if any file matching this path exists.   */  public boolean exists()  {    return getBestPath().exists();  }  /**   * True if the best path is a directory.   */  public boolean isDirectory()  {    return getBestPath().isDirectory();  }  /**   * True if the best path is a file.   */  public boolean isFile()  {    return getBestPath().isFile();  }  /**   * Returns the length of the best path.   */  public long getLength()  {    return getBestPath().getLength();  }  /**   * Returns the last modified time of the best path.   */  public long getLastModified()  {    return getBestPath().getLastModified();  }  /**   * Returns true if the best path can be read.   */  public boolean canRead()  {    return getBestPath().canRead();  }  /**   * Returns true if the best path can be written to.   */  public boolean canWrite()  {    return getBestPath().canWrite();  }  /**   * Returns all the resources matching the path.   */  public ArrayList<Path> getResources(String pathName)  {    ArrayList<Path> list = new ArrayList<Path>();    String pathname = _pathname;    // XXX: why was this here?    if (pathname.startsWith("/"))      pathname = "." + pathname;    ArrayList<Path> pathList = ((MergePath) _root)._pathList;    for (int i = 0; i < pathList.size(); i++) {      Path path = pathList.get(i);      path = path.lookup(pathname);      ArrayList<Path> subResources = path.getResources(pathName);      for (int j = 0; j < subResources.size(); j++) {        Path newPath = subResources.get(j);                if (! list.contains(newPath))          list.add(newPath);      }    }    return list;  }  /**   * Returns all the resources matching the path.   */  public ArrayList<Path> getResources()  {    ArrayList<Path> list = new ArrayList<Path>();    String pathname = _pathname;    // XXX: why?    if (pathname.startsWith("/"))      pathname = "." + pathname;    ArrayList<Path> pathList = ((MergePath) _root)._pathList;    for (int i = 0; i < pathList.size(); i++) {      Path path = pathList.get(i);      path = path.lookup(pathname);      ArrayList<Path> subResources = path.getResources();      for (int j = 0; j < subResources.size(); j++) {        Path newPath = subResources.get(j);                if (! list.contains(newPath))          list.add(newPath);      }    }    return list;  }  /**   * List the merged directories.   */  public String []list() throws IOException  {    ArrayList<String> list = new ArrayList<String>();    String pathname = _pathname;    // XXX:??    if (pathname.startsWith("/"))      pathname = "." + pathname;    ArrayList<Path> pathList = ((MergePath) _root)._pathList;    for (int i = 0; i < pathList.size(); i++) {      Path path = pathList.get(i);      path = path.lookup(pathname);      if (path.isDirectory()) {        String[]subList = path.list();        for (int j = 0; j < subList.length; j++) {          if (! list.contains(subList[j]))            list.add(subList[j]);        }      }    }    return (String []) list.toArray(new String[list.size()]);  }  /**   * XXX: Probably should mkdir in the first path   */  public boolean mkdir()    throws IOException  {    return getWritePath().mkdir();  }    /**   * XXX: Probably should mkdir in the first path   */  public boolean mkdirs()    throws IOException  {    return getWritePath().mkdirs();  }    /**   * Remove the matching path.   */  public boolean remove()    throws IOException  {    return getBestPath().remove();  }  /**   * Renames the path.   */  public boolean renameTo(Path path)    throws IOException  {    return getBestPath().renameTo(path);  }  /**   * Opens the best path for reading.   */  public StreamImpl openReadImpl() throws IOException  {    StreamImpl stream = getBestPath().openReadImpl();    stream.setPath(this);    return stream;  }  /**   * Opens the best path for writing.  XXX: If the best path doesn't   * exist, this should probably create the file in the first path.   */  public StreamImpl openWriteImpl() throws IOException  {    StreamImpl stream = getWritePath().openWriteImpl();    stream.setPath(this);    return stream;  }  /**   * Opens the best path for reading and writing.  XXX: If the best path   * doesn't exist, this should probably create the file in the first path.   */  public StreamImpl openReadWriteImpl() throws IOException  {    StreamImpl stream = getWritePath().openReadWriteImpl();    stream.setPath(this);    return stream;  }  /**   * Opens the best path for appending.  XXX: If the best path   * doesn't exist, this should probably create the file in the first path.   */  public StreamImpl openAppendImpl() throws IOException  {    StreamImpl stream = getWritePath().openAppendImpl();    stream.setPath(this);    return stream;  }  /**   * Returns the first matching path.   */  public Path getWritePath()  {    String pathname = _pathname;    // XXX:??    if (pathname.startsWith("/"))      pathname = "." + pathname;    ArrayList<Path> pathList = ((MergePath) _root)._pathList;    if (pathList.size() == 0)      return new NotFoundPath(pathname);    else {      return pathList.get(0).lookup(pathname);    }  }  /**   * Creates a dependency.   */  @Override  public PersistentDependency createDepend()  {    ArrayList<Path> pathList = ((MergePath) _root)._pathList;    if (pathList.size() == 1)      return pathList.get(0).createDepend();    DependencyList dependList = new DependencyList();        for (int i = 0; i < pathList.size(); i++) {      Path path = pathList.get(i);      Path realPath = path.lookup(_pathname);      dependList.add(realPath.createDepend());    }    return dependList;  }  /**   * Returns the first matching path.   */  public Path getBestPath()  {    if (_bestPath != null)      return _bestPath;    String pathname = _pathname;    // XXX:??    if (pathname.startsWith("/"))      pathname = "." + pathname;    ArrayList<Path> pathList = ((MergePath) _root)._pathList;    for (int i = 0; i < pathList.size(); i++) {      Path path = pathList.get(i);      Path realPath = path.lookup(pathname);      realPath.setUserPath(_userPath);      if (realPath.exists()) {        _bestPath = realPath;        return realPath;      }    }    /*    pathname = _pathname;    for (int i = 0; i < pathList.size(); i++) {      Path path = pathList.get(i);      Path realPath = path.lookup(pathname);      realPath.setUserPath(_userPath);      if (realPath.exists()) {        _bestPath = realPath;        return realPath;      }    }    */    if (pathList.size() > 0) {      Path path = pathList.get(0);      if (pathname.startsWith("/"))	pathname = "." + pathname;      Path realPath = path.lookup(pathname);      realPath.setUserPath(_userPath);            return realPath;    }    return new NotFoundPath(_userPath);  }    /**   * Returns a name for the path   */  public String toString()  {    return "MergePath[" + _pathname + "]";  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?