コード例 #1
0
 private WindowsBrowser getBrowserFromRegistryEntry(
     Regor regor, int key, String subKey, String exeKey, Map exesToBrowserObjs)
     throws RegistryErrorException {
   WindowsBrowser winBrowser = null;
   int key2 = regor.openKey(key, subKey);
   List values = regor.listValueNames(key2);
   // boolean fndPath = false;
   for (int x = 0; values != null && x < values.size() && winBrowser == null; x++) {
     byte[] buf = regor.readValue(key2, (String) values.get(x));
     String path = buf != null ? Regor.parseValue(buf) : "";
     String lpath = path.toLowerCase();
     if (lpath.endsWith(exeKey)) {
       winBrowser = (WindowsBrowser) exesToBrowserObjs.get(exeKey);
       // get path to exe and set it in winBrowser object
       StringTokenizer tokenizer = new StringTokenizer(path, "\\", false);
       StringBuffer pathBuf = new StringBuffer();
       int tokCnt = tokenizer.countTokens();
       // we want to ignore the last token
       for (int idx = 1; idx < tokCnt; idx++) {
         pathBuf.append(tokenizer.nextToken());
         pathBuf.append('\\');
       }
       winBrowser.setPathToExe(pathBuf.toString());
     }
   }
   return winBrowser;
 }
コード例 #2
0
 /**
  * Secondary method for browser discovery.
  *
  * <p>Uses IE to get the path to the Program Files directory; then gets a list of the sub dirs and
  * checks them against the remaining browsers.
  *
  * @param iePath String
  * @param browsersAvailable Map
  * @param tmpBrowsersToCheck List
  */
 private Map processFilePathsForBrowsers(List tmpBrowsersToCheck) {
   logger.debug("finding available browsers in program files path");
   logger.debug("browsers to check: " + tmpBrowsersToCheck);
   Map browsersAvailable = new HashMap();
   File progFilesPath = getProgramFilesPath();
   if (progFilesPath != null) {
     logger.debug("program files path: " + progFilesPath.getPath());
     File[] subDirs = progFilesPath.listFiles(new DirFileFilter());
     int subDirsCnt = subDirs != null ? subDirs.length : 0;
     // create and populate map of dir names to win browser objects
     Iterator iter = tmpBrowsersToCheck.iterator();
     Map dirNameToBrowser = new HashMap();
     while (iter.hasNext()) {
       WindowsBrowser wBrowser = (WindowsBrowser) iter.next();
       dirNameToBrowser.put(wBrowser.getSubDirName(), wBrowser);
     }
     // iterate over subdirs and compare to map entries
     for (int idx = 0; idx < subDirsCnt && !tmpBrowsersToCheck.isEmpty(); idx++) {
       if (dirNameToBrowser.containsKey(subDirs[idx].getName())) {
         WindowsBrowser wBrowser = (WindowsBrowser) dirNameToBrowser.get(subDirs[idx].getName());
         // need to search folder and sub-folders for exe to find
         // the full path
         String exeName = wBrowser.getBrowserApplicationName() + ".exe";
         File fullPathToExe = findExeFilePath(subDirs[idx], exeName);
         if (fullPathToExe != null) {
           logger.debug(
               "Adding browser " + wBrowser.getBrowserDisplayName() + " to available list.");
           wBrowser.setPathToExe(fullPathToExe.getPath());
           logger.debug(wBrowser.getPathToExe());
           // adding display and exe for backward compatibility and
           // ease of use if someone passes in the name of an exe
           browsersAvailable.put(wBrowser.getBrowserDisplayName(), wBrowser);
           browsersAvailable.put(wBrowser.getBrowserApplicationName(), wBrowser);
           tmpBrowsersToCheck.remove(wBrowser);
         }
       }
     }
   }
   return browsersAvailable;
 }