edu.stanford.ejalbert.launching.misc
Class UnixNetscapeBrowserLaunching

java.lang.Object
  extended byedu.stanford.ejalbert.launching.misc.UnixNetscapeBrowserLaunching
All Implemented Interfaces:
IBrowserLaunching
Direct Known Subclasses:
SunOSBrowserLaunching

public class UnixNetscapeBrowserLaunching
extends Object
implements IBrowserLaunching

Tries several browsers (mozilla, netscape, firefox, opera, and konqueror). Most users will have at least one of these installed. The types are defined in /edu/stanford/ejalbert/launching/misc/linuxUnixConfig.properties.

Author:
Markus Gebhard, Jeff Chapman

Field Summary
static String CONFIGFILE_LINUX_UNIX
          config file for linux/unix
protected  AbstractLogger logger
           
 
Fields inherited from interface edu.stanford.ejalbert.launching.IBrowserLaunching
BROWSER_DEFAULT, BROWSER_SYSTEM_PROPERTY, PROP_KEY_BROWSER_PREFIX, PROP_KEY_DELIMITER, PROTOCOL_FILE, PROTOCOL_HTTP, PROTOCOL_MAILTO
 
Constructor Summary
UnixNetscapeBrowserLaunching(AbstractLogger logger, String configFile)
          Sets the logger and config file name.
 
Method Summary
protected  StandardUnixBrowser getBrowser(String key)
          Provides access the browsers map for extending classes.
 List getBrowserList()
          Returns a list of browsers to be used for browser targetting.
 boolean getNewWindowPolicy()
          Returns the policy used for opening a url in a browser.
 void initialize()
          Uses the which command to find out which browsers are available.
 void openUrl(List browsers, String urlString)
          Allows user to target several browsers.
 void openUrl(String urlString)
          Opens a url in one of the available browsers.
 void openUrl(String browser, String urlString)
          Opens a url in the specified browser.
protected  boolean openUrlWithBrowser(UnixBrowser unixBrowser, String urlString)
          Attempts to open a url with the specified browser.
 void setNewWindowPolicy(boolean forceNewWindow)
          Sets the policy used for opening a url in a browser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIGFILE_LINUX_UNIX

public static final String CONFIGFILE_LINUX_UNIX
config file for linux/unix

See Also:
Constant Field Values

logger

protected final AbstractLogger logger
Constructor Detail

UnixNetscapeBrowserLaunching

public UnixNetscapeBrowserLaunching(AbstractLogger logger,
                                    String configFile)
Sets the logger and config file name.

Parameters:
logger - AbstractLogger
configFile - String
Method Detail

getBrowser

protected StandardUnixBrowser getBrowser(String key)
Provides access the browsers map for extending classes.

Parameters:
key - String
Returns:
StandardUnixBrowser

openUrlWithBrowser

protected boolean openUrlWithBrowser(UnixBrowser unixBrowser,
                                     String urlString)
                              throws BrowserLaunchingExecutionException
Attempts to open a url with the specified browser. This is a utility method called by the openUrl methods.

Parameters:
unixBrowser - UnixBrowser
urlString - String
Returns:
boolean
Throws:
BrowserLaunchingExecutionException

initialize

public void initialize()
                throws BrowserLaunchingInitializingException
Uses the which command to find out which browsers are available. The available browsers are put into the unixBrowsers map using displayName => StandardUnixBrowser mappings.

Specified by:
initialize in interface IBrowserLaunching
Throws:
BrowserLaunchingInitializingException

openUrl

public void openUrl(String urlString)
             throws UnsupportedOperatingSystemException,
                    BrowserLaunchingExecutionException,
                    BrowserLaunchingInitializingException
Opens a url in one of the available browsers.

Specified by:
openUrl in interface IBrowserLaunching
Parameters:
urlString - String
Throws:
BrowserLaunchingExecutionException
UnsupportedOperatingSystemException
BrowserLaunchingInitializingException

openUrl

public void openUrl(String browser,
                    String urlString)
             throws UnsupportedOperatingSystemException,
                    BrowserLaunchingExecutionException,
                    BrowserLaunchingInitializingException
Opens a url in the specified browser. If the call to the specified browser fails, the method falls through to the non-targetted version.

Specified by:
openUrl in interface IBrowserLaunching
Parameters:
browser - String
urlString - String
Throws:
UnsupportedOperatingSystemException
BrowserLaunchingExecutionException
BrowserLaunchingInitializingException

openUrl

public void openUrl(List browsers,
                    String urlString)
             throws UnsupportedOperatingSystemException,
                    BrowserLaunchingExecutionException,
                    BrowserLaunchingInitializingException
Allows user to target several browsers. The names of potential browsers can be accessed via the getBrowserList method.

The browsers from the list will be tried in order (first to last) until one of the calls succeeds. If all the calls to the requested browsers fail, the code will fail over to the default browser.

Specified by:
openUrl in interface IBrowserLaunching
Parameters:
browsers - List
urlString - String
Throws:
UnsupportedOperatingSystemException
BrowserLaunchingExecutionException
BrowserLaunchingInitializingException

getBrowserList

public List getBrowserList()
Returns a list of browsers to be used for browser targetting. This list will always contain at least one item--the BROWSER_DEFAULT.

Specified by:
getBrowserList in interface IBrowserLaunching
Returns:
List

getNewWindowPolicy

public boolean getNewWindowPolicy()
Returns the policy used for opening a url in a browser.

If the policy is true, an attempt will be made to force the url to be opened in a new instance (window) of the browser.

If the policy is false, the url may open in a new window or a new tab.

Most browsers on Unix/Linux systems have command line options to support this feature.

Specified by:
getNewWindowPolicy in interface IBrowserLaunching
Returns:
boolean

setNewWindowPolicy

public void setNewWindowPolicy(boolean forceNewWindow)
Sets the policy used for opening a url in a browser.

Specified by:
setNewWindowPolicy in interface IBrowserLaunching
Parameters:
forceNewWindow - boolean