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

public class Browser extends 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

    Fields
    Modifier and Type
    Field
    Description
    static String[]
    A list of commands to try in order to display the url.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String[]
    Retrieve the default commands to open a browser for this system.
    static void
    Display a URL in the system browser.
    static void
    Display the URLs, each in their own window, in the system browser.
    static void
    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 Details

    • exec

      public static 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 Details

    • Browser

      public Browser()
  • Method Details

    • 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 String[] defaultCommands()
      Retrieve the default commands to open a browser for this system.
      Since:
      ostermillerutils 1.00.00
    • displayURL

      public static void displayURL(String url) throws 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:
      IOException - if the url is not valid or the browser fails to star
      Since:
      ostermillerutils 1.00.00
    • displayURLs

      public static void displayURLs(String[] urls) throws 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:
      IOException - if the url is not valid or the browser fails to star
      Since:
      ostermillerutils 1.00.00