Package edu.wisc.ssec.mcidasv.util
Class WebBrowser
java.lang.Object
edu.wisc.ssec.mcidasv.util.WebBrowser
A simple utility class for opening a web browser to a given link.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringIOExceptionformatting string used when all browsing methods have failed.private static final org.slf4j.LoggerLogging object.private static final StringIOExceptionformatting string used byopenOldStyle(String)when no browsers could be identified on the system.private static final StringMessage displayed to the user when all browsing methods have failed.Probe Unix-like systems for these browsers, in this order. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAttempts to use the system default browser to visiturl.private static booleanisMac()Test for whether or not the current platform is Mac OS X.private static booleanisUnix()Test for whether or not the current platform is some form of "unix" (but not OS X!).private static booleanTest for whether or not the current platform is Windows.static voidprivate static booleanopenNewStyle(String url) Use the functionality withinDesktopto try opening the user's preferred web browser.private static voidopenOldStyle(String url) UsesRuntime.exec(String)to launch the user's preferred web browser.private static booleanAttempts to launch the browser pointed at by the "idv.browser.path" IDV property, if it has been set.static booleanuseBrowserForUrl(String url) Test whether or not a given URL should be opened in a web browser.
-
Field Details
-
logger
Logging object. -
unixBrowsers
Probe Unix-like systems for these browsers, in this order. -
ALL_METHODS_ERRMSG
IOExceptionformatting string used when all browsing methods have failed.- See Also:
-
NO_BROWSER_ERRMSG
IOExceptionformatting string used byopenOldStyle(String)when no browsers could be identified on the system.- See Also:
-
THINGS_DUN_BROKE_ERRMSG
Message displayed to the user when all browsing methods have failed.- See Also:
-
-
Constructor Details
-
WebBrowser
private WebBrowser()Do not create instances ofWebBrowser.
-
-
Method Details
-
browse
Attempts to use the system default browser to visiturl. Tries looking for and executing any browser specified by the IDV property "idv.browser.path".If the property wasn't given or there was an error, try the new (as of Java 1.6) way of opening a browser.
If the previous attempts failed (or we're in 1.5), we finally try some more primitive measures.
Note: if you are trying to use this method with a
JTextPaneyou may need to turn off editing viaJTextComponent.setEditable(boolean).- Parameters:
url- URL to visit.- See Also:
-
useBrowserForUrl
Test whether or not a given URL should be opened in a web browser.- Parameters:
url- URL to test. Cannot benull.- Returns:
trueifurlbegins with either "http:" or "https:".
-
openNewStyle
Use the functionality withinDesktopto try opening the user's preferred web browser.- Parameters:
url- URL to visit.- Returns:
- Either
trueif things look ok,falseif there were problems.
-
openOldStyle
UsesRuntime.exec(String)to launch the user's preferred web browser. This method isn't really recommended unless you're stuck with Java 1.5.Note that the browsers need to be somewhere in the PATH, as this method uses the
whichcommand (also needs to be in the PATH!).- Parameters:
url- URL to visit.
-
tryUserSpecifiedBrowser
Attempts to launch the browser pointed at by the "idv.browser.path" IDV property, if it has been set.- Parameters:
url- URL to open.- Returns:
- Either
trueif the command-line was executed,falseif either the command-line wasn't launched or "idv.browser.path" was not set.
-
isMac
Test for whether or not the current platform is Mac OS X.- Returns:
- Are we shiny, happy OS X users?
-
isUnix
Test for whether or not the current platform is some form of "unix" (but not OS X!).- Returns:
- Do we perhaps think that beards and suspenders are the height of fashion?
-
isWindows
Test for whether or not the current platform is Windows.- Returns:
- Are we running Windows??
-
main
-