コード例 #1
0
ファイル: ZipLister.java プロジェクト: shrekwang/jvifm
  private void changeCurrentNode() {

    boolean hasMatchSelectedName = false;
    FileObject[] children = null;
    try {
      children = currentFileObject.getChildren();
    } catch (Exception e) {
      e.printStackTrace();
    }
    if (children == null) return;

    sortFiles(children);

    String selectedName = historyManager.getSelectedItem(currentFileObject.getName().getPath());
    table.removeAll();
    TableItem item;

    for (int i = 0; i < children.length; i++) {
      FileName fileName = children[i].getName();

      if (fileName.getBaseName().equals(selectedName)) {
        currentRow = i;
        hasMatchSelectedName = true;
      }

      item = new TableItem(table, SWT.NONE);
      item.setData("fileObject", children[i]);
      item.setText(fileName.getBaseName());

      try {
        FileType fileType = children[i].getType();
        FileContent fileContent = children[i].getContent();

        if (fileType.equals(FileType.FOLDER)) {
          item.setImage(folderImage);
          item.setText(1, "--");
          item.setText(2, StringUtil.formatDate(fileContent.getLastModifiedTime()));
        } else {
          item.setImage(fileImage);
          item.setText(1, StringUtil.formatSize(fileContent.getSize()));
          item.setText(2, StringUtil.formatDate(fileContent.getLastModifiedTime()));
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    if (!hasMatchSelectedName) currentRow = 0;
    table.setSelection(currentRow);
    table.setFocus();
  }
コード例 #2
0
  public void init() throws FileSystemException {
    super.init();

    // Build the index
    List strongRef = new ArrayList(100);
    Enumeration entries = getZipFile().entries();
    while (entries.hasMoreElements()) {
      ZipEntry entry = (ZipEntry) entries.nextElement();
      FileName name =
          getFileSystemManager().resolveName(getRootName(), UriParser.encode(entry.getName()));

      // Create the file
      ZipFileObject fileObj;
      if (entry.isDirectory() && getFileFromCache(name) != null) {
        fileObj = (ZipFileObject) getFileFromCache(name);
        fileObj.setZipEntry(entry);
        continue;
      }

      fileObj = createZipFileObject(name, entry);
      putFileToCache(fileObj);
      strongRef.add(fileObj);
      fileObj.holdObject(strongRef);

      // Make sure all ancestors exist
      // TODO - create these on demand
      ZipFileObject parent = null;
      for (FileName parentName = name.getParent();
          parentName != null;
          fileObj = parent, parentName = parentName.getParent()) {
        // Locate the parent
        parent = (ZipFileObject) getFileFromCache(parentName);
        if (parent == null) {
          parent = createZipFileObject(parentName, null);
          putFileToCache(parent);
          strongRef.add(parent);
          parent.holdObject(strongRef);
        }

        // Attach child to parent
        parent.attachChild(fileObj.getName());
      }
    }
  }
コード例 #3
0
  private synchronized FileObject resolveFile(final FileName name, final boolean useCache)
      throws FileSystemException {
    if (!rootName.getRootURI().equals(name.getRootURI())) {
      throw new FileSystemException(
          "vfs.provider/mismatched-fs-for-name.error",
          new Object[] {name, rootName, name.getRootURI()});
    }

    // [email protected] ==> use getFileFromCache
    FileObject file;
    if (useCache) {
      file = getFileFromCache(name);
    } else {
      file = null;
    }
    // FileObject file = (FileObject) files.get(name);
    if (file == null) {
      try {
        synchronized (this) {
          file = createFile(name);
        }
      } catch (Exception e) {
        throw new FileSystemException("vfs.provider/resolve-file.error", name, e);
      }

      file = decorateFileObject(file);

      // [email protected] ==> use putFileToCache
      if (useCache) {
        putFileToCache(file);
      }
      // files.put(name, file);
    }

    /** resync the file information if requested */
    if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE)) {
      file.refresh();
    }
    return file;
  }
コード例 #4
0
 protected AbstractFileSystem(
     final FileName rootName,
     final FileObject parentLayer,
     final FileSystemOptions fileSystemOptions) {
   // this.parentLayer = parentLayer;
   this.parentLayer = parentLayer;
   this.rootName = rootName;
   this.fileSystemOptions = fileSystemOptions;
   FileSystemConfigBuilder builder = DefaultFileSystemConfigBuilder.getInstance();
   String uri = builder.getRootURI(fileSystemOptions);
   if (uri == null) {
     uri = rootName.getURI();
   }
   this.rootURI = uri;
 }