org.opensourcephysics.desktop.ostermiller
Class Browser

java.lang.Object
  extended by org.opensourcephysics.desktop.ostermiller.Browser

public class Browser
extends java.lang.Object

A stripped down version of the Browser class published by Stephen Ostermiller for use by the OSP project. Allows URLs to be opened in the system browser on Windows and Unix. More information about this class is available from ostermiller.org.

Since:
ostermillerutils 1.00.00
Author:
Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities

Field Summary
static java.lang.String[] exec
          A list of commands to try in order to display the url.
 
Constructor Summary
Browser()
           
 
Method Summary
static java.lang.String[] defaultCommands()
          Retrieve the default commands to open a browser for this system.
static void displayURL(java.lang.String url)
          Display a URL in the system browser.
static void displayURLs(java.lang.String[] urls)
          Display the URLs, each in their own window, in the system browser.
static void init()
          Determine appropriate commands to start a browser on the current operating system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

exec

public static java.lang.String[] exec
A list of commands to try in order to display the url. The url is put into the command using MessageFormat, so the URL will be specified as {0} in the command. Some examples of commands to try might be:
rundll32 url.dll,FileProtocolHandler {0}
netscape {0}
These commands are passed in order to exec until something works when displayURL is used.

Since:
ostermillerutils 1.00.00
Constructor Detail

Browser

public Browser()
Method Detail

init

public static void init()
Determine appropriate commands to start a browser on the current operating system. On windows:
rundll32 url.dll,FileProtocolHandler {0}
On other operating systems, the "which" command is used to test if Mozilla, netscape, and lynx(xterm) are available (in that order).

Since:
ostermillerutils 1.00.00

defaultCommands

public static java.lang.String[] defaultCommands()
Retrieve the default commands to open a browser for this system.

Since:
ostermillerutils 1.00.00

displayURL

public static void displayURL(java.lang.String url)
                       throws java.io.IOException
Display a URL in the system browser. Browser.init() should be called before calling this function or Browser.exec should be set explicitly. For security reasons, the URL will may not be passed directly to the browser as it is passed to this method. The URL may be made safe for the exec command by URLEncoding the URL before passing it.

Parameters:
url - the url to display
Throws:
java.io.IOException - if the url is not valid or the browser fails to star
Since:
ostermillerutils 1.00.00

displayURLs

public static void displayURLs(java.lang.String[] urls)
                        throws java.io.IOException
Display the URLs, each in their own window, in the system browser. Browser.init() should be called before calling this function or Browser.exec should be set explicitly. If more than one URL is given an HTML page containing JavaScript will be written to the local drive, that page will be opened, and it will open the rest of the URLs.

Parameters:
urls - the list of urls to display
Throws:
java.io.IOException - if the url is not valid or the browser fails to star
Since:
ostermillerutils 1.00.00