Class WebBrowser

java.lang.Object
edu.wisc.ssec.mcidasv.util.WebBrowser

public final class WebBrowser extends Object
A simple utility class for opening a web browser to a given link.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    IOException formatting string used when all browsing methods have failed.
    private static final org.slf4j.Logger
    Logging object.
    private static final String
    IOException formatting string used by openOldStyle(String) when no browsers could be identified on the system.
    private static final String
    Message displayed to the user when all browsing methods have failed.
    private static final List<String>
    Probe Unix-like systems for these browsers, in this order.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Do not create instances of WebBrowser.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Attempts to use the system default browser to visit url.
    private static boolean
    Test for whether or not the current platform is Mac OS X.
    private static boolean
    Test for whether or not the current platform is some form of "unix" (but not OS X!).
    private static boolean
    Test for whether or not the current platform is Windows.
    static void
    main(String[] args)
     
    private static boolean
    Use the functionality within Desktop to try opening the user's preferred web browser.
    private static void
    Uses Runtime.exec(String) to launch the user's preferred web browser.
    private static boolean
    Attempts to launch the browser pointed at by the "idv.browser.path" IDV property, if it has been set.
    static boolean
    Test whether or not a given URL should be opened in a web browser.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • WebBrowser

      private WebBrowser()
      Do not create instances of WebBrowser.
  • Method Details

    • browse

      public static void browse(String url)
      Attempts to use the system default browser to visit url. 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 JTextPane you may need to turn off editing via JTextComponent.setEditable(boolean).

      Parameters:
      url - URL to visit.
      See Also:
    • useBrowserForUrl

      public static boolean useBrowserForUrl(String url)
      Test whether or not a given URL should be opened in a web browser.
      Parameters:
      url - URL to test. Cannot be null.
      Returns:
      true if url begins with either "http:" or "https:".
    • openNewStyle

      private static boolean openNewStyle(String url)
      Use the functionality within Desktop to try opening the user's preferred web browser.
      Parameters:
      url - URL to visit.
      Returns:
      Either true if things look ok, false if there were problems.
    • openOldStyle

      private static void openOldStyle(String url)
      Uses Runtime.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 which command (also needs to be in the PATH!).

      Parameters:
      url - URL to visit.
    • tryUserSpecifiedBrowser

      private static boolean tryUserSpecifiedBrowser(String url)
      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 true if the command-line was executed, false if either the command-line wasn't launched or "idv.browser.path" was not set.
    • isMac

      private static boolean isMac()
      Test for whether or not the current platform is Mac OS X.
      Returns:
      Are we shiny, happy OS X users?
    • isUnix

      private static boolean 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

      private static boolean isWindows()
      Test for whether or not the current platform is Windows.
      Returns:
      Are we running Windows??
    • main

      public static void main(String[] args)