| java.lang.Object com.Ostermiller.util.Browser
Browser | public class Browser (Code) | | Allows URLs to be opened in the system browser on Windows and Unix.
More information about this class is available from ostermiller.org.
author: Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities since: ostermillerutils 1.00.00 |
Field Summary | |
protected static BrowserDialog | dialog The dialog that allows user configuration of the options for this class. | public static String[] | exec A list of commands to try in order to display the url. | protected static ResourceBundle | labels Locale specific strings displayed to the user. |
Method Summary | |
public static String[] | defaultCommands() Retrieve the default commands to open a browser for this system. | public static boolean | dialogConfiguration(Frame owner) Show a dialog that allows the user to configure the
command lines used for starting a browser on their system.
Parameters: owner - The frame that owns the dialog. | public static boolean | dialogConfiguration(Frame owner, Properties props) Show a dialog that allows the user to configure the
command lines used for starting a browser on their system.
String used in the dialog are taken from the given
properties. | public static void | displayURL(String url) 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. | public static void | displayURL(String url, String namedWindow) Display the URL in the named window. | public static void | displayURLinNew(String url) Display the URL in a new window.
Uses javascript to check history.length to determine if the browser opened a
new window already. | public static void | displayURLs(String[] urls) Display the URLs, each in their own window, in the system browser. | public static void | displayURLs(String[] urls, String[] namedWindows) Display the URLs in the named windows.
If the browser opens a new window by default, this will likely cause a duplicate window
to be opened. | public static void | displayURLs(String[] urls, String namedWindow) Display the URLs the first in the given named window.
If the browser opens a new window by default, this will likely cause a duplicate window
to be opened. | public static void | displayURLsinNew(String[] urls) Display the URLs, each in their own window, in the system browser and the first in
the named window. | public static JPanel | getDialogPanel(Window parent) If you wish to add to your own dialog box rather than have a separate
one just for the browser, use this method to get a JPanel that can
be added to your own dialog.
mydialog.add(Browser.getDialogPanel(mydialog));
Browser.initPanel();
mydialog.show();
if (ok_pressed){
Browser.userOKedPanelChanges();
}
Parameters: parent - window into which panel with eventually be placed. | public static void | init() Determine appropriate commands to start a browser on the current
operating system. | public static void | initPanel() If you are using the getDialogPanel() method to create your own dialog, this
method should be called every time before you display the dialog. | public static void | load(Properties props) Load the options for this class from the given properties file.
This method is designed to work with the save(props) method. | public static void | main(String[] args) Open the url(s) specified on the command line in your browser. | public static void | save(Properties props) Save the options used to the given properties file. | public static void | setLocale(Locale locale) Set the locale used for getting localized
strings. | public static void | userOKedPanelChanges() If you are using the getDialogPanel() method to create your own dialog, this
method should be called after you display the dialog if the user pressed ok. |
dialog | protected static BrowserDialog dialog(Code) | | The dialog that allows user configuration of the options for this class.
since: ostermillerutils 1.00.00 |
exec | public static String[] exec(Code) | | 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 |
labels | protected static ResourceBundle labels(Code) | | Locale specific strings displayed to the user.
since: ostermillerutils 1.00.00 |
defaultCommands | public static String[] defaultCommands()(Code) | | Retrieve the default commands to open a browser for this system.
list of commands since: ostermillerutils 1.00.00 |
dialogConfiguration | public static boolean dialogConfiguration(Frame owner)(Code) | | Show a dialog that allows the user to configure the
command lines used for starting a browser on their system.
Parameters: owner - The frame that owns the dialog. whether or not the dialog has changed since: ostermillerutils 1.00.00 |
dialogConfiguration | public static boolean dialogConfiguration(Frame owner, Properties props)(Code) | | Show a dialog that allows the user to configure the
command lines used for starting a browser on their system.
String used in the dialog are taken from the given
properties. This dialog can be customized or displayed in
multiple languages.
Properties that are used:
com.Ostermiller.util.BrowserDialog.title
com.Ostermiller.util.BrowserDialog.description
com.Ostermiller.util.BrowserDialog.label
com.Ostermiller.util.BrowserDialog.defaults
com.Ostermiller.util.BrowserDialog.browse
com.Ostermiller.util.BrowserDialog.ok
com.Ostermiller.util.BrowserDialog.cancel
Parameters: owner - The frame that owns this dialog. Parameters: props - contains the strings used in the dialog. whether or not the dialog has changed since: ostermillerutils 1.00.00 |
displayURL | public static void displayURL(String url) throws IOException(Code) | | 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 |
displayURL | public static void displayURL(String url, String namedWindow) throws IOException(Code) | | Display the URL in the named window.
If the browser opens a new window by default, this will likely cause a duplicate window
to be opened.
Browser.init() should be called before calling this function or
Browser.exec should be set explicitly.
Parameters: url - the url to display Parameters: namedWindow - the name of the desired window. throws: IOException - if the url is not valid or the browser fails to star since: ostermillerutils 1.00.00 |
displayURLinNew | public static void displayURLinNew(String url) throws IOException(Code) | | Display the URL in a new window.
Uses javascript to check history.length to determine if the browser opened a
new window already. If it did, the url is shown in that window, if not, it is
shown in new window.
Some browsers do not allow the length of history to be viewed by a web page. In that
case, the url will be displayed in the current window.
Browser.init() should be called before calling this function or
Browser.exec should be set explicitly.
Parameters: url - the url to display in a new window. 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(Code) | | 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 |
displayURLs | public static void displayURLs(String[] urls, String[] namedWindows) throws IOException(Code) | | Display the URLs in the named windows.
If the browser opens a new window by default, this will likely cause a duplicate window
to be opened. This method relies on the browser to support javascript.
Browser.init() should be called before calling this function or
Browser.exec should be set explicitly.
Extra names for windows will be ignored, and if there are too few names, the remaining
windows will be named "_blank".
Parameters: urls - the list of urls to display Parameters: namedWindows - the list of names for the windows. 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, String namedWindow) throws IOException(Code) | | Display the URLs the first in the given named window.
If the browser opens a new window by default, this will likely cause a duplicate window
to be opened. This method relies on the browser to support javascript.
Browser.init() should be called before calling this function or
Browser.exec should be set explicitly.
Parameters: urls - the list of urls to display Parameters: namedWindow - the name of the first window to use. throws: IOException - if the url is not valid or the browser fails to star since: ostermillerutils 1.00.00 |
displayURLsinNew | public static void displayURLsinNew(String[] urls) throws IOException(Code) | | Display the URLs, each in their own window, in the system browser and the first in
the named window.
The first URL will only be opened in the named window if the browser did no
open it in a new window to begin with.
Browser.init() should be called before calling this function or
Browser.exec should be set explicitly.
An html page containing javascript will
be written to the local drive, that page will be opened, and it will
open all 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 |
getDialogPanel | public static JPanel getDialogPanel(Window parent)(Code) | | If you wish to add to your own dialog box rather than have a separate
one just for the browser, use this method to get a JPanel that can
be added to your own dialog.
mydialog.add(Browser.getDialogPanel(mydialog));
Browser.initPanel();
mydialog.show();
if (ok_pressed){
Browser.userOKedPanelChanges();
}
Parameters: parent - window into which panel with eventually be placed. the dialog since: ostermillerutils 1.02.22 |
init | public static void init()(Code) | | 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 |
initPanel | public static void initPanel()(Code) | | If you are using the getDialogPanel() method to create your own dialog, this
method should be called every time before you display the dialog.
mydialog.add(Browser.getDialogPanel(mydialog));
Browser.initPanel();
mydialog.show();
if (ok_pressed){
Browser.userOKedPanelChanges();
}
since: ostermillerutils 1.02.22 |
load | public static void load(Properties props)(Code) | | Load the options for this class from the given properties file.
This method is designed to work with the save(props) method. All
properties used will start with com.Ostermiller.util.Browser. If
no configuration is found, the default configuration will be used.
If this method is used, a call to Browser.init(); is not needed.
Parameters: props - properties file from which configuration is loaded. since: ostermillerutils 1.00.00 |
main | public static void main(String[] args)(Code) | | Open the url(s) specified on the command line in your browser.
Parameters: args - Command line arguments (URLs) |
save | public static void save(Properties props)(Code) | | Save the options used to the given properties file.
Property names used will all start with com.Ostermiller.util.Browser
Properties are saved in such a way that a call to load(props); will
restore the state of this class.
If the default commands to open a browser are being used then
they are not saved in the properties file, assuming that the user
will want to use the defaults next time even if the defaults change.
Parameters: props - properties file to which configuration is saved. since: ostermillerutils 1.00.00 |
setLocale | public static void setLocale(Locale locale)(Code) | | Set the locale used for getting localized
strings.
Parameters: locale - Locale used to for i18n. since: ostermillerutils 1.00.00 |
userOKedPanelChanges | public static void userOKedPanelChanges()(Code) | | If you are using the getDialogPanel() method to create your own dialog, this
method should be called after you display the dialog if the user pressed ok.
mydialog.add(Browser.getDialogPanel(mydialog));
Browser.initPanel();
mydialog.show();
if (ok_pressed){
Browser.userOKedPanelChanges();
}
since: ostermillerutils 1.02.22 |
|
|