Class BrowserUtil


  • public class BrowserUtil
    extends java.lang.Object
    The BrowserUtil class provides one static method - openUrlInDefaultBrowser, which opens the given URL in the default web browser for the current user of the system. Current implementation supports Windows, Linux and some Unix systems.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String[] __browserLauncher
      The command that launches system browser
      private static int __osId
      The internal ID of the OS we are running on
      private static java.lang.String FIRST_WINDOWS_PARAMETER
      The first parameter that needs to be passed into Runtime.exec() to open the default web browser on Windows.
      private static int MAC_OS
      JVM constant for MacOS JVM
      private static int OTHER
      JVM constant for any other platform
      private static java.lang.String SECOND_WINDOWS_PARAMETER
      The second parameter for Runtime.exec() on Windows.
      private static java.lang.String THIRD_WINDOWS_PARAMETER
      The third parameter for Runtime.exec() on Windows.
      private static int WINDOWS_9x
      JVM constant for any Windows 9x JVM
      private static int WINDOWS_NT
      JVM constant for any Windows NT JVM
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private BrowserUtil()
      This class should be never be instantiated; this just ensures so.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void main​(java.lang.String[] args)
      For testing only.
      static java.lang.Process openUrlInDefaultBrowser​(java.lang.String url)
      Attempts to open the default web browser to the given URL.
      • Methods inherited from class java.lang.Object

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

      • __osId

        private static int __osId
        The internal ID of the OS we are running on
      • __browserLauncher

        private static java.lang.String[] __browserLauncher
        The command that launches system browser
      • WINDOWS_NT

        private static final int WINDOWS_NT
        JVM constant for any Windows NT JVM
        See Also:
        Constant Field Values
      • WINDOWS_9x

        private static final int WINDOWS_9x
        JVM constant for any Windows 9x JVM
        See Also:
        Constant Field Values
      • OTHER

        private static final int OTHER
        JVM constant for any other platform
        See Also:
        Constant Field Values
      • FIRST_WINDOWS_PARAMETER

        private static final java.lang.String FIRST_WINDOWS_PARAMETER
        The first parameter that needs to be passed into Runtime.exec() to open the default web browser on Windows.
        See Also:
        Constant Field Values
      • SECOND_WINDOWS_PARAMETER

        private static final java.lang.String SECOND_WINDOWS_PARAMETER
        The second parameter for Runtime.exec() on Windows.
        See Also:
        Constant Field Values
      • THIRD_WINDOWS_PARAMETER

        private static final java.lang.String THIRD_WINDOWS_PARAMETER
        The third parameter for Runtime.exec() on Windows. This is a "title" parameter that the command line expects. Setting this parameter allows URLs containing spaces to work.
        See Also:
        Constant Field Values
    • Constructor Detail

      • BrowserUtil

        private BrowserUtil()
        This class should be never be instantiated; this just ensures so.
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
        For testing only.
        Parameters:
        args - [url_to_open]
      • openUrlInDefaultBrowser

        public static java.lang.Process openUrlInDefaultBrowser​(java.lang.String url)
                                                         throws java.lang.Exception
        Attempts to open the default web browser to the given URL.
        Parameters:
        url - The URL to open
        Returns:
        Returns the process browser object or null if no browser could be found. On MacOs null is returned in any case.
        Throws:
        java.lang.Exception - If the available web browser does not run