kiwi.ui
Class WebBrowser

java.lang.Object
  extended bykiwi.ui.WebBrowser

public class WebBrowser
extends java.lang.Object

A class that represents a web browser and provides URL opening capability. This class allows a Java program to open a URL in a web browser. It currently works on Windows and UNIX systems.

On Windows, the URL is opened in the default browser by invoking the command:

 rundll32 url.dll,FileProtocolHandler url
 
This calling convention works on most variants of Windows, from Windows 98 to Windows 2000. It has not been tested on Windows XP.

On UNIX, this class can launch (or send a remote command to) any Netscape-compatible browser which supports the ``-remote'' switch; this includes Netscape itself, Mozilla, and possibly other browsers. An attempt is first made to open the URL in a running browser, via a command like:

 netscape -remote openURL(url)
 
and if that fails, an attempt is then made to launch the browser, via a command like:
 netscape url
 
In the case of an error, an exception is thrown.

On MacOS, the equivalent result can be achieved by using the method:

 com.apple.mrj.MRJUtils.openURL(String url) throws IOException
 
Since this call relies on an OS-specific class library, MacOS support has not been added to this class, as doing so would break the compilation on non-MacOS systems.

Since:
Kiwi 1.3.4
Author:
Mark Lindner

Field Summary
private  java.lang.String browserPath
           
private static java.lang.String[] unixBrowsers
           
private static java.lang.String[] unixCommands
           
private  boolean windows
           
private static java.lang.String[] windowsBrowsers
           
private static java.lang.String[] windowsCommands
           
 
Constructor Summary
WebBrowser()
          Construct a new WebBrowser, with no browser path specified.
 
Method Summary
private  boolean isWindows()
           
 void openURL(java.lang.String url)
          Open the specified URL in the web browser.
private  void openURL(java.lang.String url, java.lang.String browser, java.lang.String[] commandList)
           
 void openURL(java.net.URL url)
          Open the specified URL in the web browser.
 void setBrowserPath(java.lang.String path)
          Specify the path to a Netscape-compatible browser (such as Netscape, Mozilla, or any other browser that supports the ``-remote'' switch).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

windows

private boolean windows

browserPath

private java.lang.String browserPath

unixCommands

private static final java.lang.String[] unixCommands

unixBrowsers

private static final java.lang.String[] unixBrowsers

windowsCommands

private static final java.lang.String[] windowsCommands

windowsBrowsers

private static final java.lang.String[] windowsBrowsers
Constructor Detail

WebBrowser

public WebBrowser()
Construct a new WebBrowser, with no browser path specified. An attempt will be made to use mozilla or netscape, in that order. It will be assumed that a browser binary can be found in the command search path.

Method Detail

setBrowserPath

public void setBrowserPath(java.lang.String path)
Specify the path to a Netscape-compatible browser (such as Netscape, Mozilla, or any other browser that supports the ``-remote'' switch). It is assumed (but not required) that path is an absolute path to a browser executable.

This method has no effect on Windows systems.

Parameters:
path - The path to the browser.

openURL

public void openURL(java.net.URL url)
             throws java.io.IOException
Open the specified URL in the web browser.

Parameters:
url - The URL to open.
Throws:
java.io.IOException - If the browser could not be launched.

openURL

public void openURL(java.lang.String url)
             throws java.io.IOException
Open the specified URL in the web browser.

Parameters:
url - The URL to open.
Throws:
java.io.IOException - If the browser could not be launched.

openURL

private void openURL(java.lang.String url,
                     java.lang.String browser,
                     java.lang.String[] commandList)
              throws java.io.IOException
Throws:
java.io.IOException

isWindows

private boolean isWindows()