Пример #1
0
  private void browseWinReflect(final URL url) throws LaunchFailedException {
    boolean findOpenNew = false;
    // First check if we could find command for verb opennew
    String verbCmd = WinUtility.getVerbCommand(url, DesktopConstants.VERB_OPENNEW);
    if (verbCmd != null) {
      findOpenNew = true;
    } else {
      // If no opennew verb command find, then check open verb command
      verbCmd = WinUtility.getVerbCommand(url, DesktopConstants.VERB_OPEN);
    }

    if (verbCmd != null) {
      boolean result;
      try {
        if (findOpenNew) {
          // If there is opennew verb command, use this one
          result = winShellExecute(url.toString(), DesktopConstants.VERB_OPENNEW);
        } else {
          // else use open verb command
          result = winShellExecute(url.toString(), DesktopConstants.VERB_OPEN);
        }
      } catch (Exception e) {
        final LaunchFailedException ex =
            new LaunchFailedException("Reflection error: " + e.getMessage());
        ex.initCause(e);
        throw ex;
      }

      if (!result) {
        throw new LaunchFailedException("Failed to launch the default browser");
      }
    } else {
      throw new LaunchFailedException("No default browser associated with this URL");
    }
  }
Пример #2
0
  private void browseWinRundll(final URL url) throws LaunchFailedException {
    final String[] call = new String[3];
    call[0] = "rundll32.exe";
    call[1] = "url.dll,FileProtocolHandler";
    call[2] = url.toString();

    try {
      final Process rundll = Runtime.getRuntime().exec(call);
      final int retVal = rundll.waitFor();
      logger.debug("rundll32.exe call returned " + retVal);
    } catch (Exception e) {
      final LaunchFailedException ex =
          new LaunchFailedException(
              "error executing " + Arrays.toString(call) + ": " + e.getMessage());
      ex.initCause(e);
      throw ex;
    }
  }