Пример #1
0
  /**
   * A convenience method that filters the directory listing according to a filter, and can
   * optionally list the directory recursively.
   *
   * @param session The session
   * @param directory The directory. Note that this must be a full URL, including the host name,
   *     path name, and so on. The username and password (if needed by the VFS) is obtained from the
   *     session instance.
   * @param filter The {@link VFSFileFilter} to use for filtering.
   * @param recursive If true, subdirectories will also be listed.
   * @param comp The component that will parent error dialog boxes
   * @exception IOException if an I/O error occurred
   * @param skipBinary ignore binary files (do not return them). This will slow down the process
   *     since it will open the files
   * @param skipHidden skips hidden files, directories, and backup files. Ignores any file beginning
   *     with . or #, or ending with ~ or .bak
   * @since jEdit 4.3pre7
   */
  public String[] _listDirectory(
      Object session,
      String directory,
      VFSFileFilter filter,
      boolean recursive,
      Component comp,
      boolean skipBinary,
      boolean skipHidden)
      throws IOException {
    List<String> files = new ArrayList<String>(100);

    listFiles(
        session,
        new HashSet<String>(),
        files,
        directory,
        filter,
        recursive,
        comp,
        skipBinary,
        skipHidden);

    String[] retVal = files.toArray(new String[files.size()]);

    Arrays.sort(retVal, new StandardUtilities.StringCompare<String>(true));

    return retVal;
  } // }}}
Пример #2
0
  // {{{ loadColors() method
  private static void loadColors() {
    synchronized (lock) {
      colors = new ArrayList<ColorEntry>();

      if (!jEdit.getBooleanProperty("vfs.browser.colorize")) return;

      String glob;
      int i = 0;
      while ((glob = jEdit.getProperty("vfs.browser.colors." + i + ".glob")) != null) {
        try {
          colors.add(
              new ColorEntry(
                  Pattern.compile(StandardUtilities.globToRE(glob)),
                  jEdit.getColorProperty("vfs.browser.colors." + i + ".color", Color.black)));
        } catch (PatternSyntaxException e) {
          Log.log(Log.ERROR, VFS.class, "Invalid regular expression: " + glob);
          Log.log(Log.ERROR, VFS.class, e);
        }

        i++;
      }
    }
  } // }}}
Пример #3
0
  // {{{ recursive listFiles() method
  private void listFiles(
      Object session,
      Collection<String> stack,
      List<String> files,
      String directory,
      VFSFileFilter filter,
      boolean recursive,
      Component comp,
      boolean skipBinary,
      boolean skipHidden)
      throws IOException {
    String resolvedPath = directory;
    if (recursive && !MiscUtilities.isURL(directory)) {
      resolvedPath = MiscUtilities.resolveSymlinks(directory);
      /*
       * If looking at a symlink, do not traverse the
       * resolved path more than once.
       */
      if (!directory.equals(resolvedPath)) {
        if (stack.contains(resolvedPath)) {
          Log.log(Log.ERROR, this, "Recursion in listFiles(): " + directory);
          return;
        }
        stack.add(resolvedPath);
      }
    }

    Thread ct = Thread.currentThread();
    WorkThread wt = null;
    if (ct instanceof WorkThread) {
      wt = (WorkThread) ct;
    }

    VFSFile[] _files = _listFiles(session, directory, comp);
    if (_files == null || _files.length == 0) return;

    for (int i = 0; i < _files.length; i++) {
      if (wt != null && wt.isAborted()) break;
      VFSFile file = _files[i];
      if (skipHidden && (file.isHidden() || MiscUtilities.isBackup(file.getName()))) continue;
      if (!filter.accept(file)) continue;
      if (file.getType() == VFSFile.DIRECTORY || file.getType() == VFSFile.FILESYSTEM) {
        if (recursive) {
          String canonPath = _canonPath(session, file.getPath(), comp);
          listFiles(
              session, stack, files, canonPath, filter, recursive, comp, skipBinary, skipHidden);
        }
      } else // It's a regular file
      {
        if (skipBinary) {
          try {
            if (file.isBinary(session)) {
              Log.log(Log.NOTICE, this, file.getPath() + ": skipped as a binary file");
              continue;
            }
          } catch (IOException e) {
            Log.log(Log.ERROR, this, e);
            // may be not binary...
          }
        }
        files.add(file.getPath());
      }
    }
  } // }}}