コード例 #1
0
 /**
  * Uses the which command to find out which browsers are available. The available browsers are put
  * into the unixBrowsers map using displayName => StandardUnixBrowser mappings.
  *
  * @todo what do we do if there are no browsers available?
  * @throws BrowserLaunchingInitializingException
  */
 public void initialize() throws BrowserLaunchingInitializingException {
   try {
     URL configUrl = getClass().getResource(configFileName);
     if (configUrl == null) {
       throw new BrowserLaunchingInitializingException(
           "unable to find config file: " + configFileName);
     }
     StringBuffer potentialBrowserNames = new StringBuffer();
     Properties configProps = new Properties();
     configProps.load(configUrl.openStream());
     String sepChar = configProps.getProperty(PROP_KEY_DELIMITER);
     Iterator keysIter = configProps.keySet().iterator();
     while (keysIter.hasNext()) {
       String key = (String) keysIter.next();
       if (key.startsWith(PROP_KEY_BROWSER_PREFIX)) {
         StandardUnixBrowser browser =
             new StandardUnixBrowser(sepChar, configProps.getProperty(key));
         if (this.isBrowserAvailable(browser, logger)) {
           unixBrowsers.put(browser.getBrowserDisplayName(), browser);
         } else {
           if (potentialBrowserNames.length() > 0) {
             potentialBrowserNames.append("; ");
           }
           potentialBrowserNames.append(browser.getBrowserDisplayName());
         }
       }
     }
     if (unixBrowsers.size() == 0) {
       // no browser installed
       throw new BrowserLaunchingInitializingException(
           "one of the supported browsers must be installed: " + potentialBrowserNames);
     }
     logger.info(unixBrowsers.keySet().toString());
     unixBrowsers = Collections.unmodifiableMap(unixBrowsers);
   } catch (IOException ioex) {
     throw new BrowserLaunchingInitializingException(ioex);
   }
 }