com.isti.util
Class BasicLaunchBrowser

java.lang.Object
  extended by com.isti.util.BasicLaunchBrowser
All Implemented Interfaces:
ILaunchBrowser

public class BasicLaunchBrowser
extends java.lang.Object
implements ILaunchBrowser

Basic Browser Launch. Utility class to open a web page from a Swing application in the user's default browser. Supports: Mac OS X, GNU/Linux, Unix, Windows XP/Vista/7 This code was lifted from www.centerkey.com/java/browser


Field Summary
static java.lang.String[] WEB_BROWSERS
          The web browsers for Unix/Linux.
 
Fields inherited from interface com.isti.util.ILaunchBrowser
NO_ERROR
 
Constructor Summary
BasicLaunchBrowser()
          Creates a launch browser.
BasicLaunchBrowser(java.lang.String[] browsers, boolean useDesktopFlag)
          Creates a launch browser.
 
Method Summary
static void browse(java.lang.String urlStr)
          Attempts to use the Desktop library from JDK 1.6+ to open a browser.
 java.lang.String getErrorMessage()
          Returns message string for last error (or 'No error' if none).
static boolean isDesktopAvailable()
          Determines if the desktop is available.
static boolean isDesktopAvailable(java.lang.String javaVersionString)
          Determines if the desktop is available.
protected  java.lang.String launch()
          Launch the browser.
protected  java.lang.String launch(java.lang.String urlStr)
          Launch the browser.
static void main(java.lang.String[] args)
           
 boolean showURL(java.lang.String urlStr)
          Displays the given URL address string in a browser window.
 boolean showURL(java.lang.String urlStr, java.lang.String titleStr)
          Displays the given URL address string in a browser window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEB_BROWSERS

public static final java.lang.String[] WEB_BROWSERS
The web browsers for Unix/Linux.

Constructor Detail

BasicLaunchBrowser

public BasicLaunchBrowser()
Creates a launch browser.


BasicLaunchBrowser

public BasicLaunchBrowser(java.lang.String[] browsers,
                          boolean useDesktopFlag)
Creates a launch browser.

Parameters:
browsers - the web browsers for Unix/Linux.
useDesktopFlag - true to use the java.awt.Desktop, false otherwise.
See Also:
WEB_BROWSERS, isDesktopAvailable()
Method Detail

browse

public static void browse(java.lang.String urlStr)
                   throws java.lang.Exception
Attempts to use the Desktop library from JDK 1.6+ to open a browser.

Parameters:
urlStr - a string containing the URL.
Throws:
java.lang.Exception - if error.
See Also:
isDesktopAvailable()

getErrorMessage

public java.lang.String getErrorMessage()
Returns message string for last error (or 'No error' if none).

Specified by:
getErrorMessage in interface ILaunchBrowser
Returns:
message string for last error (or 'No error' if none).

isDesktopAvailable

public static boolean isDesktopAvailable()
Determines if the desktop is available.

Returns:
boolean true if the desktop is available, false otherwise.

isDesktopAvailable

public static boolean isDesktopAvailable(java.lang.String javaVersionString)
Determines if the desktop is available.

Parameters:
javaVersionString - the Java version string.
Returns:
boolean true if the desktop is available, false otherwise.
See Also:
UtilFns.getJavaVersion()

showURL

public boolean showURL(java.lang.String urlStr)
Displays the given URL address string in a browser window.

Specified by:
showURL in interface ILaunchBrowser
Parameters:
urlStr - a string containing the URL.
Returns:
true if successful; false if error (in which case an error message may be fetched via the 'getErrorMessage()' method).

showURL

public boolean showURL(java.lang.String urlStr,
                       java.lang.String titleStr)
Displays the given URL address string in a browser window.

Specified by:
showURL in interface ILaunchBrowser
Parameters:
urlStr - a string containing the URL.
titleStr - a string used to select a target browser window or null if none.
Returns:
true if successful; false if error (in which case an error message may be fetched via the 'getErrorMessage()' method).

launch

protected java.lang.String launch()
Launch the browser.

Returns:
null if successful; an error message if error.

launch

protected java.lang.String launch(java.lang.String urlStr)
Launch the browser.

Parameters:
urlStr - the URL string.
Returns:
null if successful; an error message if error.

main

public static void main(java.lang.String[] args)