public Enumeration GetEnumRootList(String deviceDir) {
    FileConnection fc = null;
    InputStream is = null;
    Enumeration enumTraverse = null;

    try {
      fc = (FileConnection) Connector.open(sFileSchema + deviceDir);

      if (fc == null) {
        SetMessages("[!] ERROR: fc == null.");
        System.out.println(GetMessages());
        return null;
      }
      if (!fc.exists()) {
        SetMessages("[!] ERROR: !fc.exists().");
        System.out.println(GetMessages());
        return null;
      }

      enumTraverse = fc.list();
    } catch (IOException ioex) {
      SetMessages(ioex.toString());
      ioex.printStackTrace();
    } catch (Exception ex) {
      SetMessages(ex.toString());
      ex.printStackTrace();
    } finally {
      try {
        if (is != null) {
          is.close();
        }

        if (fc != null) {
          fc.close();
        }
      } catch (IOException ioex) {
        SetMessages(ioex.toString());
        ioex.printStackTrace();
      } catch (Exception ex) {
        SetMessages(ex.toString());
        ex.printStackTrace();
      }
    }

    return enumTraverse;
  }
Exemplo n.º 2
0
 private void displayCurrentRoot() {
   try {
     setTitle(currentRoot.getURL());
     deleteAll();
     append(UPPER_DIR, null);
     Enumeration listOfDirs = currentRoot.list("*", false);
     while (listOfDirs.hasMoreElements()) {
       String currentDir = (String) listOfDirs.nextElement();
       if (currentDir.endsWith(FILE_SEPARATOR)) {
         append(currentDir, null);
       } else {
         append(currentDir, null);
       }
     }
   } catch (IOException e) {
   } catch (SecurityException e) {
   }
 }
Exemplo n.º 3
0
  private boolean getRootContent(String rootDir) {
    // #if polish.api.pdaapi
    try {
      // #debug debug
      logger.debug("List of files and directories under " + rootDir + ":");
      FileConnection fc = (FileConnection) Connector.open(rootDir, Connector.READ);
      // Get a filtered list of all files and directories.
      // True means: include hidden files.
      // To list just visible files and directories, use
      // list() with no arguments.
      if (!fc.exists()) {
        url = "file:///";
        return false;
      }
      if (!fc.isDirectory()) {
        // If it is not a directory,
        // Then we assume it must be an
        // Ok selection
        selectEntry();
        return true;
      }

      list = createEmptyList();
      urlList.removeAllElements();
      list.append(".", null);
      urlList.addElement(url);
      list.append("..", null);
      // urlList.addElement(url + "Directory Up");
      urlList.addElement(url);
      String fileName;
      String suffix;
      // #if polish.android
      // workaround for J2MEPolish 2.3 bug, jkpj 2012-03-15
      Enumeration filelist = fc.list("*", false);
      // #else
      Enumeration filelist = fc.list();
      // #endif
      while (filelist.hasMoreElements()) {
        fileName = (String) filelist.nextElement();
        // #debug debug
        logger.debug("found file: " + fileName);
        // add files too if not choose dir only
        // #if polish.android
        // was workaround for J2MEPolish before 2.3
        // FileConnection fc2 = (FileConnection) Connector.open(url + fileName);
        // if (fc2.isDirectory()) {
        //	fileName += "/";
        //	fc2.close();
        // }
        // #endif

        // only add entries matching the criteria
        boolean matching = false;
        if (fileName.endsWith("/")) {
          matching = true;
        } else if (chooseType != CHOOSE_DIRONLY) {
          // when there's no suffix to check for, each file is matching
          if (suffixes == null) {
            matching = true;
            // otherwise check if one of the ;-separated suffixes matches
          } else {
            for (int i = 0; i < suffixes.size(); i++) {
              suffix = (String) suffixes.elementAt(i);
              if (fileName.toLowerCase().endsWith(suffix.toLowerCase())) {
                matching = true;
              }
            }
          }
        }

        // insert matching entries in the appropriate list at the right index to have them sorted
        if (matching) {
          // System.out.println("Adding " + fileName);
          if (fileName.endsWith("/")) {
            dirs.insertElementAt(fileName, getSortIdx(dirs, fileName));
          } else {
            files.insertElementAt(fileName, getSortIdx(files, fileName));
          }
        }
      }

      // add sorted directory names to list and urlList
      for (int i = 0; i < dirs.size(); i++) {
        fileName = (String) dirs.elementAt(i);
        list.append(fileName, null);
        urlList.addElement(url + fileName);
      }
      dirs.removeAllElements();
      // add sorted filenames to list and urlList
      for (int i = 0; i < files.size(); i++) {
        fileName = (String) files.elementAt(i);
        list.append(fileName, null);
        urlList.addElement(url + fileName);
      }
      files.removeAllElements();

      fc.close();
      show();
    } catch (IOException ioe) {
      logger.error(ioe.getMessage());
    } catch (SecurityException e) {
      logger.error(e.getMessage());
    }
    // #endif
    return true;
  }