com.huguesjohnson
Class LaunchBrowser

java.lang.Object
  extended by com.huguesjohnson.LaunchBrowser

public abstract class LaunchBrowser
extends java.lang.Object

LaunchBrowser attempts to launch the operating system default browser.

Usage examples:

String result=(new LaunchBrowser()).launch("http://www.huguesjohnson.com");

String verboseResult=(new LaunchBrowser()).launch("http://www.huguesjohnson.com",true);

String verboseResult=(new LaunchBrowser()).launch("file://c:\\some-folder\\some-file.html",true);

String verboseResult=(new LaunchBrowser()).launch("file:///some-dir/some-file.html",true);

This has only been tested on Windows 2000, if it doesn't work on another OS please set verbose to true to debug. I can just about guarantee this will not work with OS/2, the algorithm to lookup the operating system explicitly checks for Windows and MacOS with the default being UNIX/Linux. UNIX/Linux is considered the default because each "flavor" of UNIX/Linux returns a different name to the System.getProperty("os.name") call.. there is no standard name. For example, HP-UX returns "HP-UX" while Solaris returns "Solaris".

Updated 2007-07-28: Updated UNIX/Linux code with logic from BareBonesBrowserLaunch.java By Dem Pilafian (see http://www.centerkey.com/java/browser/). The Windows and MacOS logic was basically the same between the original version of this class and BareBonesBrowserLaunch.java but his UNIX/Linux logic was more reliable.

Author:
Hugues Johnson

Constructor Summary
LaunchBrowser()
           
 
Method Summary
static java.lang.String launch(java.lang.String url)
          Launches a web browser with the specified url.
static java.lang.String launch(java.lang.String url, boolean verbose)
          Launches a web browser with the specified url.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LaunchBrowser

public LaunchBrowser()
Method Detail

launch

public static java.lang.String launch(java.lang.String url)
Launches a web browser with the specified url. First tries to use current browser session, if no browser is loaded it starts a new session. See comments for the class for proper usage and known issues.

Parameters:
url - The address to open.

launch

public static java.lang.String launch(java.lang.String url,
                                      boolean verbose)
Launches a web browser with the specified url. First tries to use current browser session, if no browser is loaded it starts a new session. See comments for the class for proper usage and known issues.

Parameters:
url - The address to open.
verbose - Whether or not to return verbose output, useful for debugging. This is false if launch(url) is used.


Copyright © 2000-2007 Hugues Johnson