Class Browser
java.lang.Object
org.opensourcephysics.desktop.ostermiller.Browser
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]
Retrieve the default commands to open a browser for this system.static void
displayURL
(String url) Display a URL in the system browser.static void
displayURLs
(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.
-
Field Details
-
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
Retrieve the default commands to open a browser for this system.- Since:
- ostermillerutils 1.00.00
-
displayURL
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
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
-