Formatting changes
[jalview.git] / src / jalview / util / BrowserLauncher.java
index 12d6f02..6bac25b 100755 (executable)
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
-*/\r
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ */\r
 package jalview.util;\r
 \r
-import java.io.File;\r
-import java.io.IOException;\r
-\r
-import java.lang.reflect.Constructor;\r
-import java.lang.reflect.Field;\r
-import java.lang.reflect.InvocationTargetException;\r
-import java.lang.reflect.Method;\r
-\r
-\r
-/**
- * BrowserLauncher is a class that provides one static method, openURL, which opens the default
- * web browser for the current user of the system to the given URL.  It may support other
- * protocols depending on the system -- mailto, ftp, etc. -- but that has not been rigorously
- * tested and is not guaranteed to work.
- * <p>
- * Yes, this is platform-specific code, and yes, it may rely on classes on certain platforms
- * that are not part of the standard JDK.  What we're trying to do, though, is to take something
- * that's frequently desirable but inherently platform-specific -- opening a default browser --
- * and allow programmers (you, for example) to do so without worrying about dropping into native
- * code or doing anything else similarly evil.
- * <p>
- * Anyway, this code is completely in Java and will run on all JDK 1.1-compliant systems without
- * modification or a need for additional libraries.  All classes that are required on certain
- * platforms to allow this to run are dynamically loaded at runtime via reflection and, if not
- * found, will not cause this to do anything other than returning an error when opening the
- * browser.
- * <p>
- * There are certain system requirements for this class, as it's running through Runtime.exec(),
- * which is Java's way of making a native system call.  Currently, this requires that a Macintosh
- * have a Finder which supports the GURL event, which is true for Mac OS 8.0 and 8.1 systems that
- * have the Internet Scripting AppleScript dictionary installed in the Scripting Additions folder
- * in the Extensions folder (which is installed by default as far as I know under Mac OS 8.0 and
- * 8.1), and for all Mac OS 8.5 and later systems.  On Windows, it only runs under Win32 systems
- * (Windows 95, 98, and NT 4.0, as well as later versions of all).  On other systems, this drops
- * back from the inherently platform-sensitive concept of a default browser and simply attempts
- * to launch Netscape via a shell command.
- * <p>
- * This code is Copyright 1999-2001 by Eric Albert (ejalbert\@cs.stanford.edu) and may be
- * redistributed or modified in any form without restrictions as long as the portion of this
- * comment from this paragraph through the end of the comment is not removed.  The author
- * requests that he be notified of any application, applet, or other binary that makes use of
- * this code, but that's more out of curiosity than anything and is not required.  This software
- * includes no warranty.  The author is not repsonsible for any loss of data or functionality
- * or any adverse or unexpected effects of using this software.
- * <p>
- * Credits:
- * <br>Steven Spencer, JavaWorld magazine (<a href="http://www.javaworld.com/javaworld/javatips/jw-javatip66.html">Java Tip 66</a>)
- * <br>Thanks also to Ron B. Yeh, Eric Shapiro, Ben Engber, Paul Teitlebaum, Andrea Cantatore,
- * Larry Barowski, Trevor Bedzek, Frank Miedrich, and Ron Rabakukk
- *
- * @author Eric Albert (<a href="mailto:ejalbert@cs.stanford.edu">ejalbert@cs.stanford.edu</a>)
- * @version 1.4b1 (Released June 20, 2001)
- */\r
-public class BrowserLauncher {\r
-    /**
- * The Java virtual machine that we are running on.  Actually, in most cases we only care
- * about the operating system, but some operating systems require us to switch on the VM. */\r
-    private static int jvm;\r
-\r
-    /** The browser for the system */\r
-    private static Object browser;\r
-\r
-    /**
- * Caches whether any classes, methods, and fields that are not part of the JDK and need to
- * be dynamically loaded at runtime loaded successfully.
- * <p>
- * Note that if this is <code>false</code>, <code>openURL()</code> will always return an
- * IOException.
+import java.io.*;\r
+import java.lang.reflect.*;\r
+\r
+/**\r
+ * BrowserLauncher is a class that provides one static method, openURL, which opens the default\r
+ * web browser for the current user of the system to the given URL.  It may support other\r
+ * protocols depending on the system -- mailto, ftp, etc. -- but that has not been rigorously\r
+ * tested and is not guaranteed to work.\r
+ * <p>\r
+ * Yes, this is platform-specific code, and yes, it may rely on classes on certain platforms\r
+ * that are not part of the standard JDK.  What we're trying to do, though, is to take something\r
+ * that's frequently desirable but inherently platform-specific -- opening a default browser --\r
+ * and allow programmers (you, for example) to do so without worrying about dropping into native\r
+ * code or doing anything else similarly evil.\r
+ * <p>\r
+ * Anyway, this code is completely in Java and will run on all JDK 1.1-compliant systems without\r
+ * modification or a need for additional libraries.  All classes that are required on certain\r
+ * platforms to allow this to run are dynamically loaded at runtime via reflection and, if not\r
+ * found, will not cause this to do anything other than returning an error when opening the\r
+ * browser.\r
+ * <p>\r
+ * There are certain system requirements for this class, as it's running through Runtime.exec(),\r
+ * which is Java's way of making a native system call.  Currently, this requires that a Macintosh\r
+ * have a Finder which supports the GURL event, which is true for Mac OS 8.0 and 8.1 systems that\r
+ * have the Internet Scripting AppleScript dictionary installed in the Scripting Additions folder\r
+ * in the Extensions folder (which is installed by default as far as I know under Mac OS 8.0 and\r
+ * 8.1), and for all Mac OS 8.5 and later systems.  On Windows, it only runs under Win32 systems\r
+ * (Windows 95, 98, and NT 4.0, as well as later versions of all).  On other systems, this drops\r
+ * back from the inherently platform-sensitive concept of a default browser and simply attempts\r
+ * to launch Netscape via a shell command.\r
+ * <p>\r
+ * This code is Copyright 1999-2001 by Eric Albert (ejalbert\@cs.stanford.edu) and may be\r
+ * redistributed or modified in any form without restrictions as long as the portion of this\r
+ * comment from this paragraph through the end of the comment is not removed.  The author\r
+ * requests that he be notified of any application, applet, or other binary that makes use of\r
+ * this code, but that's more out of curiosity than anything and is not required.  This software\r
+ * includes no warranty.  The author is not repsonsible for any loss of data or functionality\r
+ * or any adverse or unexpected effects of using this software.\r
+ * <p>\r
+ * Credits:\r
+ * <br>Steven Spencer, JavaWorld magazine (<a href="http://www.javaworld.com/javaworld/javatips/jw-javatip66.html">Java Tip 66</a>)\r
+ * <br>Thanks also to Ron B. Yeh, Eric Shapiro, Ben Engber, Paul Teitlebaum, Andrea Cantatore,\r
+ * Larry Barowski, Trevor Bedzek, Frank Miedrich, and Ron Rabakukk\r
+ *\r
+ * @author Eric Albert (<a href="mailto:ejalbert@cs.stanford.edu">ejalbert@cs.stanford.edu</a>)\r
+ * @version 1.4b1 (Released June 20, 2001)\r
  */\r
-    private static boolean loadedWithoutErrors;\r
+public class BrowserLauncher\r
+{\r
+  /**\r
+   * The Java virtual machine that we are running on.  Actually, in most cases we only care\r
+   * about the operating system, but some operating systems require us to switch on the VM. */\r
+  private static int jvm;\r
 \r
-    /** The com.apple.mrj.MRJFileUtils class */\r
-    private static Class mrjFileUtilsClass;\r
+  /** The browser for the system */\r
+  private static Object browser;\r
 \r
-    /** The com.apple.mrj.MRJOSType class */\r
-    private static Class mrjOSTypeClass;\r
+  /**\r
+   * Caches whether any classes, methods, and fields that are not part of the JDK and need to\r
+   * be dynamically loaded at runtime loaded successfully.\r
+   * <p>\r
+   * Note that if this is <code>false</code>, <code>openURL()</code> will always return an\r
+   * IOException.\r
+   */\r
+  private static boolean loadedWithoutErrors;\r
 \r
-    /** The com.apple.MacOS.AEDesc class */\r
-    private static Class aeDescClass;\r
+  /** The com.apple.mrj.MRJFileUtils class */\r
+  private static Class mrjFileUtilsClass;\r
 \r
-    /** The &lt;init&gt;(int) method of com.apple.MacOS.AETarget */\r
-    private static Constructor aeTargetConstructor;\r
+  /** The com.apple.mrj.MRJOSType class */\r
+  private static Class mrjOSTypeClass;\r
 \r
-    /** The &lt;init&gt;(int, int, int) method of com.apple.MacOS.AppleEvent */\r
-    private static Constructor appleEventConstructor;\r
+  /** The com.apple.MacOS.AEDesc class */\r
+  private static Class aeDescClass;\r
 \r
-    /** The &lt;init&gt;(String) method of com.apple.MacOS.AEDesc */\r
-    private static Constructor aeDescConstructor;\r
+  /** The &lt;init&gt;(int) method of com.apple.MacOS.AETarget */\r
+  private static Constructor aeTargetConstructor;\r
 \r
-    /** The findFolder method of com.apple.mrj.MRJFileUtils */\r
-    private static Method findFolder;\r
+  /** The &lt;init&gt;(int, int, int) method of com.apple.MacOS.AppleEvent */\r
+  private static Constructor appleEventConstructor;\r
 \r
-    /** The getFileCreator method of com.apple.mrj.MRJFileUtils */\r
-    private static Method getFileCreator;\r
+  /** The &lt;init&gt;(String) method of com.apple.MacOS.AEDesc */\r
+  private static Constructor aeDescConstructor;\r
 \r
-    /** The getFileType method of com.apple.mrj.MRJFileUtils */\r
-    private static Method getFileType;\r
+  /** The findFolder method of com.apple.mrj.MRJFileUtils */\r
+  private static Method findFolder;\r
 \r
-    /** The openURL method of com.apple.mrj.MRJFileUtils */\r
-    private static Method openURL;\r
+  /** The getFileCreator method of com.apple.mrj.MRJFileUtils */\r
+  private static Method getFileCreator;\r
 \r
-    /** The makeOSType method of com.apple.MacOS.OSUtils */\r
-    private static Method makeOSType;\r
+  /** The getFileType method of com.apple.mrj.MRJFileUtils */\r
+  private static Method getFileType;\r
 \r
-    /** The putParameter method of com.apple.MacOS.AppleEvent */\r
-    private static Method putParameter;\r
+  /** The openURL method of com.apple.mrj.MRJFileUtils */\r
+  private static Method openURL;\r
 \r
-    /** The sendNoReply method of com.apple.MacOS.AppleEvent */\r
-    private static Method sendNoReply;\r
+  /** The makeOSType method of com.apple.MacOS.OSUtils */\r
+  private static Method makeOSType;\r
 \r
-    /** Actually an MRJOSType pointing to the System Folder on a Macintosh */\r
-    private static Object kSystemFolderType;\r
+  /** The putParameter method of com.apple.MacOS.AppleEvent */\r
+  private static Method putParameter;\r
 \r
-    /** The keyDirectObject AppleEvent parameter type */\r
-    private static Integer keyDirectObject;\r
+  /** The sendNoReply method of com.apple.MacOS.AppleEvent */\r
+  private static Method sendNoReply;\r
 \r
-    /** The kAutoGenerateReturnID AppleEvent code */\r
-    private static Integer kAutoGenerateReturnID;\r
+  /** Actually an MRJOSType pointing to the System Folder on a Macintosh */\r
+  private static Object kSystemFolderType;\r
 \r
-    /** The kAnyTransactionID AppleEvent code */\r
-    private static Integer kAnyTransactionID;\r
+  /** The keyDirectObject AppleEvent parameter type */\r
+  private static Integer keyDirectObject;\r
 \r
-    /** The linkage object required for JDirect 3 on Mac OS X. */\r
-    private static Object linkage;\r
+  /** The kAutoGenerateReturnID AppleEvent code */\r
+  private static Integer kAutoGenerateReturnID;\r
 \r
-    /** The framework to reference on Mac OS X */\r
-    private static final String JDirect_MacOSX = "/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/HIToolbox";\r
+  /** The kAnyTransactionID AppleEvent code */\r
+  private static Integer kAnyTransactionID;\r
 \r
-    /** JVM constant for MRJ 2.0 */\r
-    private static final int MRJ_2_0 = 0;\r
+  /** The linkage object required for JDirect 3 on Mac OS X. */\r
+  private static Object linkage;\r
 \r
-    /** JVM constant for MRJ 2.1 or later */\r
-    private static final int MRJ_2_1 = 1;\r
+  /** The framework to reference on Mac OS X */\r
+  private static final String JDirect_MacOSX = "/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/HIToolbox";\r
 \r
-    /** JVM constant for Java on Mac OS X 10.0 (MRJ 3.0) */\r
-    private static final int MRJ_3_0 = 3;\r
+  /** JVM constant for MRJ 2.0 */\r
+  private static final int MRJ_2_0 = 0;\r
 \r
-    /** JVM constant for MRJ 3.1 */\r
-    private static final int MRJ_3_1 = 4;\r
+  /** JVM constant for MRJ 2.1 or later */\r
+  private static final int MRJ_2_1 = 1;\r
 \r
-    /** JVM constant for any Windows NT JVM */\r
-    private static final int WINDOWS_NT = 5;\r
+  /** JVM constant for Java on Mac OS X 10.0 (MRJ 3.0) */\r
+  private static final int MRJ_3_0 = 3;\r
 \r
-    /** JVM constant for any Windows 9x JVM */\r
-    private static final int WINDOWS_9x = 6;\r
+  /** JVM constant for MRJ 3.1 */\r
+  private static final int MRJ_3_1 = 4;\r
 \r
-    /** JVM constant for any other platform */\r
-    private static final int OTHER = -1;\r
+  /** JVM constant for any Windows NT JVM */\r
+  private static final int WINDOWS_NT = 5;\r
 \r
-    /**
- * The file type of the Finder on a Macintosh.  Hardcoding "Finder" would keep non-U.S. English
- * systems from working properly.
- */\r
-    private static final String FINDER_TYPE = "FNDR";\r
+  /** JVM constant for any Windows 9x JVM */\r
+  private static final int WINDOWS_9x = 6;\r
 \r
-    /**
- * The creator code of the Finder on a Macintosh, which is needed to send AppleEvents to the
- * application.
- */\r
-    private static final String FINDER_CREATOR = "MACS";\r
+  /** JVM constant for any other platform */\r
+  private static final int OTHER = -1;\r
 \r
-    /** The name for the AppleEvent type corresponding to a GetURL event. */\r
-    private static final String GURL_EVENT = "GURL";\r
+  /**\r
+   * The file type of the Finder on a Macintosh.  Hardcoding "Finder" would keep non-U.S. English\r
+   * systems from working properly.\r
+   */\r
+  private static final String FINDER_TYPE = "FNDR";\r
 \r
-    /**
- * The first parameter that needs to be passed into Runtime.exec() to open the default web
- * browser on Windows.
- */\r
-    private static final String FIRST_WINDOWS_PARAMETER = "/c";\r
+  /**\r
+   * The creator code of the Finder on a Macintosh, which is needed to send AppleEvents to the\r
+   * application.\r
+   */\r
+  private static final String FINDER_CREATOR = "MACS";\r
 \r
-    /** The second parameter for Runtime.exec() on Windows. */\r
-    private static final String SECOND_WINDOWS_PARAMETER = "start";\r
+  /** The name for the AppleEvent type corresponding to a GetURL event. */\r
+  private static final String GURL_EVENT = "GURL";\r
 \r
-    /**
- * 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.
- */\r
-    private static final String THIRD_WINDOWS_PARAMETER = "\"\"";\r
+  /**\r
+   * The first parameter that needs to be passed into Runtime.exec() to open the default web\r
+   * browser on Windows.\r
+   */\r
+  private static final String FIRST_WINDOWS_PARAMETER = "/c";\r
 \r
-    /**
- * The shell parameters for Netscape that opens a given URL in an already-open copy of Netscape
- * on many command-line systems.
- */\r
-    private static final String NETSCAPE_REMOTE_PARAMETER = "-remote";\r
-    private static final String NETSCAPE_OPEN_PARAMETER_START = "openURL(";\r
-    private static final String NETSCAPE_OPEN_NEW_WINDOW = ", new-window";\r
-    private static final String NETSCAPE_OPEN_PARAMETER_END = ")";\r
+  /** The second parameter for Runtime.exec() on Windows. */\r
+  private static final String SECOND_WINDOWS_PARAMETER = "start";\r
 \r
-    /**
- * The message from any exception thrown throughout the initialization process.
- */\r
-    private static String errorMessage;\r
+  /**\r
+   * The third parameter for Runtime.exec() on Windows.  This is a "title"\r
+   * parameter that the command line expects.  Setting this parameter allows\r
+   * URLs containing spaces to work.\r
+   */\r
+  private static final String THIRD_WINDOWS_PARAMETER = "\"\"";\r
 \r
-    /**
- * An initialization block that determines the operating system and loads the necessary
- * runtime data.
- */\r
-    static {\r
-        loadedWithoutErrors = true;\r
-\r
-        String osName = System.getProperty("os.name");\r
-\r
-        if (osName.startsWith("Mac OS")) {\r
-            String mrjVersion = System.getProperty("mrj.version");\r
-            String majorMRJVersion = mrjVersion.substring(0, 3);\r
-\r
-            try {\r
-                double version = Double.valueOf(majorMRJVersion).doubleValue();\r
-\r
-                if (version == 2) {\r
-                    jvm = MRJ_2_0;\r
-                } else if ((version >= 2.1) && (version < 3)) {\r
-                    // Assume that all 2.x versions of MRJ work the same.  MRJ 2.1 actually\r
-                    // works via Runtime.exec() and 2.2 supports that but has an openURL() method\r
-                    // as well that we currently ignore.\r
-                    jvm = MRJ_2_1;\r
-                } else if (version == 3.0) {\r
-                    jvm = MRJ_3_0;\r
-                } else if (version >= 3.1) {\r
-                    // Assume that all 3.1 and later versions of MRJ work the same.\r
-                    jvm = MRJ_3_1;\r
-                } else {\r
-                    loadedWithoutErrors = false;\r
-                    errorMessage = "Unsupported MRJ version: " + version;\r
-                }\r
-            } catch (NumberFormatException nfe) {\r
-                loadedWithoutErrors = false;\r
-                errorMessage = "Invalid MRJ version: " + mrjVersion;\r
-            }\r
-        } else if (osName.startsWith("Windows")) {\r
-            if (osName.indexOf("9") != -1) {\r
-                jvm = WINDOWS_9x;\r
-            } else {\r
-                jvm = WINDOWS_NT;\r
-            }\r
-        } else {\r
-            jvm = OTHER;\r
-        }\r
+  /**\r
+   * The shell parameters for Netscape that opens a given URL in an already-open copy of Netscape\r
+   * on many command-line systems.\r
+   */\r
+  private static final String NETSCAPE_REMOTE_PARAMETER = "-remote";\r
+  private static final String NETSCAPE_OPEN_PARAMETER_START = "openURL(";\r
+  private static final String NETSCAPE_OPEN_NEW_WINDOW = ", new-window";\r
+  private static final String NETSCAPE_OPEN_PARAMETER_END = ")";\r
+\r
+  /**\r
+   * The message from any exception thrown throughout the initialization process.\r
+   */\r
+  private static String errorMessage;\r
 \r
-        if (loadedWithoutErrors) { // if we haven't hit any errors yet\r
-            loadedWithoutErrors = loadClasses();\r
+  /**\r
+   * An initialization block that determines the operating system and loads the necessary\r
+   * runtime data.\r
+   */\r
+  static\r
+  {\r
+    loadedWithoutErrors = true;\r
+\r
+    String osName = System.getProperty("os.name");\r
+\r
+    if (osName.startsWith("Mac OS"))\r
+    {\r
+      String mrjVersion = System.getProperty("mrj.version");\r
+      String majorMRJVersion = mrjVersion.substring(0, 3);\r
+\r
+      try\r
+      {\r
+        double version = Double.valueOf(majorMRJVersion).doubleValue();\r
+\r
+        if (version == 2)\r
+        {\r
+          jvm = MRJ_2_0;\r
+        }\r
+        else if ( (version >= 2.1) && (version < 3))\r
+        {\r
+          // Assume that all 2.x versions of MRJ work the same.  MRJ 2.1 actually\r
+          // works via Runtime.exec() and 2.2 supports that but has an openURL() method\r
+          // as well that we currently ignore.\r
+          jvm = MRJ_2_1;\r
+        }\r
+        else if (version == 3.0)\r
+        {\r
+          jvm = MRJ_3_0;\r
         }\r
+        else if (version >= 3.1)\r
+        {\r
+          // Assume that all 3.1 and later versions of MRJ work the same.\r
+          jvm = MRJ_3_1;\r
+        }\r
+        else\r
+        {\r
+          loadedWithoutErrors = false;\r
+          errorMessage = "Unsupported MRJ version: " + version;\r
+        }\r
+      }\r
+      catch (NumberFormatException nfe)\r
+      {\r
+        loadedWithoutErrors = false;\r
+        errorMessage = "Invalid MRJ version: " + mrjVersion;\r
+      }\r
+    }\r
+    else if (osName.startsWith("Windows"))\r
+    {\r
+      if (osName.indexOf("9") != -1)\r
+      {\r
+        jvm = WINDOWS_9x;\r
+      }\r
+      else\r
+      {\r
+        jvm = WINDOWS_NT;\r
+      }\r
+    }\r
+    else\r
+    {\r
+      jvm = OTHER;\r
     }\r
 \r
-    /**
- * This class should be never be instantiated; this just ensures so.
- */\r
-    private BrowserLauncher() {\r
+    if (loadedWithoutErrors)\r
+    { // if we haven't hit any errors yet\r
+      loadedWithoutErrors = loadClasses();\r
     }\r
+  }\r
+\r
+  /**\r
+   * This class should be never be instantiated; this just ensures so.\r
+   */\r
+  private BrowserLauncher()\r
+  {\r
+  }\r
+\r
+  /**\r
+   * Called by a static initializer to load any classes, fields, and methods required at runtime\r
+   * to locate the user's web browser.\r
+   * @return <code>true</code> if all intialization succeeded\r
+   *                        <code>false</code> if any portion of the initialization failed\r
+   */\r
+  private static boolean loadClasses()\r
+  {\r
+    switch (jvm)\r
+    {\r
+      case MRJ_2_0:\r
+\r
+        try\r
+        {\r
+          Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");\r
+          Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");\r
+          Class appleEventClass = Class.forName(\r
+              "com.apple.MacOS.AppleEvent");\r
+          Class aeClass = Class.forName("com.apple.MacOS.ae");\r
+          aeDescClass = Class.forName("com.apple.MacOS.AEDesc");\r
+\r
+          aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[]\r
+              {\r
+              int.class\r
+          });\r
+          appleEventConstructor = appleEventClass.getDeclaredConstructor(new\r
+              Class[]\r
+              {\r
+              int.class, int.class, aeTargetClass, int.class,\r
+              int.class\r
+          });\r
+          aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[]\r
+              {\r
+              String.class\r
+          });\r
+\r
+          makeOSType = osUtilsClass.getDeclaredMethod("makeOSType",\r
+              new Class[]\r
+              {String.class});\r
+          putParameter = appleEventClass.getDeclaredMethod("putParameter",\r
+              new Class[]\r
+              {int.class, aeDescClass});\r
+          sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply",\r
+              new Class[]\r
+              {});\r
+\r
+          Field keyDirectObjectField = aeClass.getDeclaredField(\r
+              "keyDirectObject");\r
+          keyDirectObject = (Integer) keyDirectObjectField.get(null);\r
+\r
+          Field autoGenerateReturnIDField = appleEventClass.getDeclaredField(\r
+              "kAutoGenerateReturnID");\r
+          kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField.get(null);\r
+\r
+          Field anyTransactionIDField = appleEventClass.getDeclaredField(\r
+              "kAnyTransactionID");\r
+          kAnyTransactionID = (Integer) anyTransactionIDField.get(null);\r
+        }\r
+        catch (ClassNotFoundException cnfe)\r
+        {\r
+          errorMessage = cnfe.getMessage();\r
 \r
-    /**
- * Called by a static initializer to load any classes, fields, and methods required at runtime
- * to locate the user's web browser.
- * @return <code>true</code> if all intialization succeeded
- *                        <code>false</code> if any portion of the initialization failed
- */\r
-    private static boolean loadClasses() {\r
-        switch (jvm) {\r
-        case MRJ_2_0:\r
-\r
-            try {\r
-                Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");\r
-                Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");\r
-                Class appleEventClass = Class.forName(\r
-                        "com.apple.MacOS.AppleEvent");\r
-                Class aeClass = Class.forName("com.apple.MacOS.ae");\r
-                aeDescClass = Class.forName("com.apple.MacOS.AEDesc");\r
-\r
-                aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] {\r
-                            int.class\r
-                        });\r
-                appleEventConstructor = appleEventClass.getDeclaredConstructor(new Class[] {\r
-                            int.class, int.class, aeTargetClass, int.class,\r
-                            int.class\r
-                        });\r
-                aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] {\r
-                            String.class\r
-                        });\r
-\r
-                makeOSType = osUtilsClass.getDeclaredMethod("makeOSType",\r
-                        new Class[] { String.class });\r
-                putParameter = appleEventClass.getDeclaredMethod("putParameter",\r
-                        new Class[] { int.class, aeDescClass });\r
-                sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply",\r
-                        new Class[] {  });\r
-\r
-                Field keyDirectObjectField = aeClass.getDeclaredField(\r
-                        "keyDirectObject");\r
-                keyDirectObject = (Integer) keyDirectObjectField.get(null);\r
-\r
-                Field autoGenerateReturnIDField = appleEventClass.getDeclaredField(\r
-                        "kAutoGenerateReturnID");\r
-                kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField.get(null);\r
-\r
-                Field anyTransactionIDField = appleEventClass.getDeclaredField(\r
-                        "kAnyTransactionID");\r
-                kAnyTransactionID = (Integer) anyTransactionIDField.get(null);\r
-            } catch (ClassNotFoundException cnfe) {\r
-                errorMessage = cnfe.getMessage();\r
-\r
-                return false;\r
-            } catch (NoSuchMethodException nsme) {\r
-                errorMessage = nsme.getMessage();\r
-\r
-                return false;\r
-            } catch (NoSuchFieldException nsfe) {\r
-                errorMessage = nsfe.getMessage();\r
-\r
-                return false;\r
-            } catch (IllegalAccessException iae) {\r
-                errorMessage = iae.getMessage();\r
-\r
-                return false;\r
-            }\r
+          return false;\r
+        }\r
+        catch (NoSuchMethodException nsme)\r
+        {\r
+          errorMessage = nsme.getMessage();\r
 \r
-            break;\r
+          return false;\r
+        }\r
+        catch (NoSuchFieldException nsfe)\r
+        {\r
+          errorMessage = nsfe.getMessage();\r
 \r
-        case MRJ_2_1:\r
+          return false;\r
+        }\r
+        catch (IllegalAccessException iae)\r
+        {\r
+          errorMessage = iae.getMessage();\r
 \r
-            try {\r
-                mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");\r
-                mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");\r
-\r
-                Field systemFolderField = mrjFileUtilsClass.getDeclaredField(\r
-                        "kSystemFolderType");\r
-                kSystemFolderType = systemFolderField.get(null);\r
-                findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder",\r
-                        new Class[] { mrjOSTypeClass });\r
-                getFileCreator = mrjFileUtilsClass.getDeclaredMethod("getFileCreator",\r
-                        new Class[] { File.class });\r
-                getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType",\r
-                        new Class[] { File.class });\r
-            } catch (ClassNotFoundException cnfe) {\r
-                errorMessage = cnfe.getMessage();\r
-\r
-                return false;\r
-            } catch (NoSuchFieldException nsfe) {\r
-                errorMessage = nsfe.getMessage();\r
-\r
-                return false;\r
-            } catch (NoSuchMethodException nsme) {\r
-                errorMessage = nsme.getMessage();\r
-\r
-                return false;\r
-            } catch (SecurityException se) {\r
-                errorMessage = se.getMessage();\r
-\r
-                return false;\r
-            } catch (IllegalAccessException iae) {\r
-                errorMessage = iae.getMessage();\r
-\r
-                return false;\r
-            }\r
+          return false;\r
+        }\r
 \r
-            break;\r
+        break\r
+            ;\r
+\r
+      case MRJ_2_1:\r
+\r
+        try\r
+        {\r
+          mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");\r
+          mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");\r
+\r
+          Field systemFolderField = mrjFileUtilsClass.getDeclaredField(\r
+              "kSystemFolderType");\r
+          kSystemFolderType = systemFolderField.get(null);\r
+          findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder",\r
+              new Class[]\r
+              {mrjOSTypeClass});\r
+          getFileCreator = mrjFileUtilsClass.getDeclaredMethod("getFileCreator",\r
+              new Class[]\r
+              {File.class});\r
+          getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType",\r
+              new Class[]\r
+              {File.class});\r
+        }\r
+        catch (ClassNotFoundException cnfe)\r
+        {\r
+          errorMessage = cnfe.getMessage();\r
 \r
-        case MRJ_3_0:\r
+          return false;\r
+        }\r
+        catch (NoSuchFieldException nsfe)\r
+        {\r
+          errorMessage = nsfe.getMessage();\r
 \r
-            try {\r
-                Class linker = Class.forName("com.apple.mrj.jdirect.Linker");\r
-                Constructor constructor = linker.getConstructor(new Class[] {\r
-                            Class.class\r
-                        });\r
-                linkage = constructor.newInstance(new Object[] {\r
-                            BrowserLauncher.class\r
-                        });\r
-            } catch (ClassNotFoundException cnfe) {\r
-                errorMessage = cnfe.getMessage();\r
+          return false;\r
+        }\r
+        catch (NoSuchMethodException nsme)\r
+        {\r
+          errorMessage = nsme.getMessage();\r
 \r
-                return false;\r
-            } catch (NoSuchMethodException nsme) {\r
-                errorMessage = nsme.getMessage();\r
+          return false;\r
+        }\r
+        catch (SecurityException se)\r
+        {\r
+          errorMessage = se.getMessage();\r
 \r
-                return false;\r
-            } catch (InvocationTargetException ite) {\r
-                errorMessage = ite.getMessage();\r
+          return false;\r
+        }\r
+        catch (IllegalAccessException iae)\r
+        {\r
+          errorMessage = iae.getMessage();\r
 \r
-                return false;\r
-            } catch (InstantiationException ie) {\r
-                errorMessage = ie.getMessage();\r
+          return false;\r
+        }\r
 \r
-                return false;\r
-            } catch (IllegalAccessException iae) {\r
-                errorMessage = iae.getMessage();\r
+        break\r
+            ;\r
+\r
+      case MRJ_3_0:\r
+\r
+        try\r
+        {\r
+          Class linker = Class.forName("com.apple.mrj.jdirect.Linker");\r
+          Constructor constructor = linker.getConstructor(new Class[]\r
+              {\r
+              Class.class\r
+          });\r
+          linkage = constructor.newInstance(new Object[]\r
+                                            {\r
+                                            BrowserLauncher.class\r
+          });\r
+        }\r
+        catch (ClassNotFoundException cnfe)\r
+        {\r
+          errorMessage = cnfe.getMessage();\r
 \r
-                return false;\r
-            }\r
+          return false;\r
+        }\r
+        catch (NoSuchMethodException nsme)\r
+        {\r
+          errorMessage = nsme.getMessage();\r
 \r
-            break;\r
+          return false;\r
+        }\r
+        catch (InvocationTargetException ite)\r
+        {\r
+          errorMessage = ite.getMessage();\r
 \r
-        case MRJ_3_1:\r
+          return false;\r
+        }\r
+        catch (InstantiationException ie)\r
+        {\r
+          errorMessage = ie.getMessage();\r
 \r
-            try {\r
-                mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");\r
-                openURL = mrjFileUtilsClass.getDeclaredMethod("openURL",\r
-                        new Class[] { String.class });\r
-            } catch (ClassNotFoundException cnfe) {\r
-                errorMessage = cnfe.getMessage();\r
+          return false;\r
+        }\r
+        catch (IllegalAccessException iae)\r
+        {\r
+          errorMessage = iae.getMessage();\r
 \r
-                return false;\r
-            } catch (NoSuchMethodException nsme) {\r
-                errorMessage = nsme.getMessage();\r
+          return false;\r
+        }\r
 \r
-                return false;\r
-            }\r
+        break\r
+            ;\r
 \r
-            break;\r
+      case MRJ_3_1:\r
 \r
-        default:\r
-            break;\r
+        try\r
+        {\r
+          mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");\r
+          openURL = mrjFileUtilsClass.getDeclaredMethod("openURL",\r
+              new Class[]\r
+              {String.class});\r
         }\r
+        catch (ClassNotFoundException cnfe)\r
+        {\r
+          errorMessage = cnfe.getMessage();\r
 \r
-        return true;\r
-    }\r
+          return false;\r
+        }\r
+        catch (NoSuchMethodException nsme)\r
+        {\r
+          errorMessage = nsme.getMessage();\r
 \r
-    /**
- * Attempts to locate the default web browser on the local system.  Caches results so it
- * only locates the browser once for each use of this class per JVM instance.
- * @return The browser for the system.  Note that this may not be what you would consider
- *                        to be a standard web browser; instead, it's the application that gets called to
- *                        open the default web browser.  In some cases, this will be a non-String object
- *                        that provides the means of calling the default browser.
- */\r
-    private static Object locateBrowser() {\r
-        if (browser != null) {\r
-            return browser;\r
+          return false;\r
         }\r
 \r
-        switch (jvm) {\r
-        case MRJ_2_0:\r
-\r
-            try {\r
-                Integer finderCreatorCode = (Integer) makeOSType.invoke(null,\r
-                        new Object[] { FINDER_CREATOR });\r
-                Object aeTarget = aeTargetConstructor.newInstance(new Object[] {\r
-                            finderCreatorCode\r
-                        });\r
-                Integer gurlType = (Integer) makeOSType.invoke(null,\r
-                        new Object[] { GURL_EVENT });\r
-                Object appleEvent = appleEventConstructor.newInstance(new Object[] {\r
-                            gurlType, gurlType, aeTarget, kAutoGenerateReturnID,\r
-                            kAnyTransactionID\r
-                        });\r
-\r
-                // Don't set browser = appleEvent because then the next time we call\r
-                // locateBrowser(), we'll get the same AppleEvent, to which we'll already have\r
-                // added the relevant parameter. Instead, regenerate the AppleEvent every time.\r
-                // There's probably a way to do this better; if any has any ideas, please let\r
-                // me know.\r
-                return appleEvent;\r
-            } catch (IllegalAccessException iae) {\r
-                browser = null;\r
-                errorMessage = iae.getMessage();\r
-\r
-                return browser;\r
-            } catch (InstantiationException ie) {\r
-                browser = null;\r
-                errorMessage = ie.getMessage();\r
-\r
-                return browser;\r
-            } catch (InvocationTargetException ite) {\r
-                browser = null;\r
-                errorMessage = ite.getMessage();\r
-\r
-                return browser;\r
-            }\r
+        break\r
+            ;\r
 \r
-        case MRJ_2_1:\r
+      default:\r
+        break;\r
+    }\r
 \r
-            File systemFolder;\r
+    return true;\r
+  }\r
+\r
+  /**\r
+   * Attempts to locate the default web browser on the local system.  Caches results so it\r
+   * only locates the browser once for each use of this class per JVM instance.\r
+   * @return The browser for the system.  Note that this may not be what you would consider\r
+   *                        to be a standard web browser; instead, it's the application that gets called to\r
+   *                        open the default web browser.  In some cases, this will be a non-String object\r
+   *                        that provides the means of calling the default browser.\r
+   */\r
+  private static Object locateBrowser()\r
+  {\r
+    if (browser != null)\r
+    {\r
+      return browser;\r
+    }\r
 \r
-            try {\r
-                systemFolder = (File) findFolder.invoke(null,\r
-                        new Object[] { kSystemFolderType });\r
-            } catch (IllegalArgumentException iare) {\r
-                browser = null;\r
-                errorMessage = iare.getMessage();\r
+    switch (jvm)\r
+    {\r
+      case MRJ_2_0:\r
+\r
+        try\r
+        {\r
+          Integer finderCreatorCode = (Integer) makeOSType.invoke(null,\r
+              new Object[]\r
+              {FINDER_CREATOR});\r
+          Object aeTarget = aeTargetConstructor.newInstance(new Object[]\r
+              {\r
+              finderCreatorCode\r
+          });\r
+          Integer gurlType = (Integer) makeOSType.invoke(null,\r
+              new Object[]\r
+              {GURL_EVENT});\r
+          Object appleEvent = appleEventConstructor.newInstance(new Object[]\r
+              {\r
+              gurlType, gurlType, aeTarget, kAutoGenerateReturnID,\r
+              kAnyTransactionID\r
+          });\r
+\r
+          // Don't set browser = appleEvent because then the next time we call\r
+          // locateBrowser(), we'll get the same AppleEvent, to which we'll already have\r
+          // added the relevant parameter. Instead, regenerate the AppleEvent every time.\r
+          // There's probably a way to do this better; if any has any ideas, please let\r
+          // me know.\r
+          return appleEvent;\r
+        }\r
+        catch (IllegalAccessException iae)\r
+        {\r
+          browser = null;\r
+          errorMessage = iae.getMessage();\r
 \r
-                return browser;\r
-            } catch (IllegalAccessException iae) {\r
-                browser = null;\r
-                errorMessage = iae.getMessage();\r
+          return browser;\r
+        }\r
+        catch (InstantiationException ie)\r
+        {\r
+          browser = null;\r
+          errorMessage = ie.getMessage();\r
 \r
-                return browser;\r
-            } catch (InvocationTargetException ite) {\r
-                browser = null;\r
-                errorMessage = ite.getTargetException().getClass() + ": " +\r
-                    ite.getTargetException().getMessage();\r
+          return browser;\r
+        }\r
+        catch (InvocationTargetException ite)\r
+        {\r
+          browser = null;\r
+          errorMessage = ite.getMessage();\r
 \r
-                return browser;\r
-            }\r
+          return browser;\r
+        }\r
 \r
-            String[] systemFolderFiles = systemFolder.list();\r
-\r
-            // Avoid a FilenameFilter because that can't be stopped mid-list\r
-            for (int i = 0; i < systemFolderFiles.length; i++) {\r
-                try {\r
-                    File file = new File(systemFolder, systemFolderFiles[i]);\r
-\r
-                    if (!file.isFile()) {\r
-                        continue;\r
-                    }\r
-\r
-                    // We're looking for a file with a creator code of 'MACS' and\r
-                    // a type of 'FNDR'.  Only requiring the type results in non-Finder\r
-                    // applications being picked up on certain Mac OS 9 systems,\r
-                    // especially German ones, and sending a GURL event to those\r
-                    // applications results in a logout under Multiple Users.\r
-                    Object fileType = getFileType.invoke(null,\r
-                            new Object[] { file });\r
-\r
-                    if (FINDER_TYPE.equals(fileType.toString())) {\r
-                        Object fileCreator = getFileCreator.invoke(null,\r
-                                new Object[] { file });\r
-\r
-                        if (FINDER_CREATOR.equals(fileCreator.toString())) {\r
-                            browser = file.toString(); // Actually the Finder, but that's OK\r
-\r
-                            return browser;\r
-                        }\r
-                    }\r
-                } catch (IllegalArgumentException iare) {\r
-                    browser = browser;\r
-                    errorMessage = iare.getMessage();\r
-\r
-                    return null;\r
-                } catch (IllegalAccessException iae) {\r
-                    browser = null;\r
-                    errorMessage = iae.getMessage();\r
-\r
-                    return browser;\r
-                } catch (InvocationTargetException ite) {\r
-                    browser = null;\r
-                    errorMessage = ite.getTargetException().getClass() + ": " +\r
-                        ite.getTargetException().getMessage();\r
-\r
-                    return browser;\r
-                }\r
-            }\r
+        case MRJ_2_1:\r
 \r
+          File systemFolder;\r
+\r
+          try\r
+          {\r
+            systemFolder = (File) findFolder.invoke(null,\r
+                new Object[]\r
+                {kSystemFolderType});\r
+          }\r
+          catch (IllegalArgumentException iare)\r
+          {\r
             browser = null;\r
+            errorMessage = iare.getMessage();\r
 \r
-            break;\r
+            return browser;\r
+          }\r
+          catch (IllegalAccessException iae)\r
+          {\r
+            browser = null;\r
+            errorMessage = iae.getMessage();\r
 \r
-        case MRJ_3_0:\r
-        case MRJ_3_1:\r
-            browser = ""; // Return something non-null\r
+            return browser;\r
+          }\r
+          catch (InvocationTargetException ite)\r
+          {\r
+            browser = null;\r
+            errorMessage = ite.getTargetException().getClass() + ": " +\r
+                ite.getTargetException().getMessage();\r
 \r
-            break;\r
+            return browser;\r
+          }\r
+\r
+          String[] systemFolderFiles = systemFolder.list();\r
+\r
+          // Avoid a FilenameFilter because that can't be stopped mid-list\r
+          for (int i = 0; i < systemFolderFiles.length; i++)\r
+          {\r
+            try\r
+            {\r
+              File file = new File(systemFolder, systemFolderFiles[i]);\r
+\r
+              if (!file.isFile())\r
+              {\r
+                continue;\r
+              }\r
+\r
+              // We're looking for a file with a creator code of 'MACS' and\r
+              // a type of 'FNDR'.  Only requiring the type results in non-Finder\r
+              // applications being picked up on certain Mac OS 9 systems,\r
+              // especially German ones, and sending a GURL event to those\r
+              // applications results in a logout under Multiple Users.\r
+              Object fileType = getFileType.invoke(null,\r
+                  new Object[]\r
+                  {file});\r
+\r
+              if (FINDER_TYPE.equals(fileType.toString()))\r
+              {\r
+                Object fileCreator = getFileCreator.invoke(null,\r
+                    new Object[]\r
+                    {file});\r
+\r
+                if (FINDER_CREATOR.equals(fileCreator.toString()))\r
+                {\r
+                  browser = file.toString(); // Actually the Finder, but that's OK\r
+\r
+                  return browser;\r
+                }\r
+              }\r
+            }\r
+            catch (IllegalArgumentException iare)\r
+            {\r
+              browser = browser;\r
+              errorMessage = iare.getMessage();\r
 \r
-        case WINDOWS_NT:\r
-            browser = "cmd.exe";\r
+              return null;\r
+            }\r
+            catch (IllegalAccessException iae)\r
+            {\r
+              browser = null;\r
+              errorMessage = iae.getMessage();\r
 \r
-            break;\r
+              return browser;\r
+            }\r
+            catch (InvocationTargetException ite)\r
+            {\r
+              browser = null;\r
+              errorMessage = ite.getTargetException().getClass() + ": " +\r
+                  ite.getTargetException().getMessage();\r
 \r
-        case WINDOWS_9x:\r
-            browser = "command.com";\r
+              return browser;\r
+            }\r
+          }\r
 \r
-            break;\r
+          browser = null;\r
 \r
-        case OTHER:default:\r
-            browser = jalview.bin.Cache.applicationProperties.getProperty(\r
-                    "jalview.browser");\r
+          break;\r
 \r
-            if (browser == null) {\r
-                // hope firefox exists :-/\r
-                browser = "firefox";\r
-            }\r
+      case MRJ_3_0:\r
+      case MRJ_3_1:\r
+        browser = ""; // Return something non-null\r
 \r
-            break;\r
-        }\r
+        break;\r
 \r
-        return browser;\r
-    }\r
+      case WINDOWS_NT:\r
+        browser = "cmd.exe";\r
 \r
-    /**
- * Attempts to open the default web browser to the given URL.
- * @param url The URL to open
- * @throws IOException If the web browser could not be located or does not run
- */\r
-    public static void openURL(String url) throws IOException {\r
-        if (!loadedWithoutErrors) {\r
-            throw new IOException("Exception in finding browser: " +\r
-                errorMessage);\r
-        }\r
-\r
-        Object browser = locateBrowser();\r
-\r
-        if (browser == null) {\r
-            throw new IOException("Unable to locate browser: " + errorMessage);\r
-        }\r
-\r
-        switch (jvm) {\r
-        case MRJ_2_0:\r
-\r
-            Object aeDesc = null;\r
-\r
-            try {\r
-                aeDesc = aeDescConstructor.newInstance(new Object[] { url });\r
-                putParameter.invoke(browser,\r
-                    new Object[] { keyDirectObject, aeDesc });\r
-                sendNoReply.invoke(browser, new Object[] {  });\r
-            } catch (InvocationTargetException ite) {\r
-                throw new IOException(\r
-                    "InvocationTargetException while creating AEDesc: " +\r
-                    ite.getMessage());\r
-            } catch (IllegalAccessException iae) {\r
-                throw new IOException(\r
-                    "IllegalAccessException while building AppleEvent: " +\r
-                    iae.getMessage());\r
-            } catch (InstantiationException ie) {\r
-                throw new IOException(\r
-                    "InstantiationException while creating AEDesc: " +\r
-                    ie.getMessage());\r
-            } finally {\r
-                aeDesc = null; // Encourage it to get disposed if it was created\r
-                browser = null; // Ditto\r
-            }\r
+        break;\r
 \r
-            break;\r
+      case WINDOWS_9x:\r
+        browser = "command.com";\r
 \r
-        case MRJ_2_1:\r
-            Runtime.getRuntime().exec(new String[] { (String) browser, url });\r
+        break;\r
 \r
-            break;\r
+      case OTHER:\r
+      default:\r
+        browser = jalview.bin.Cache.applicationProperties.getProperty(\r
+            "jalview.browser");\r
 \r
-        case MRJ_3_0:\r
+        if (browser == null)\r
+        {\r
+          // hope firefox exists :-/\r
+          browser = "firefox";\r
+        }\r
 \r
-            int[] instance = new int[1];\r
-            int result = ICStart(instance, 0);\r
+        break;\r
+    }\r
 \r
-            if (result == 0) {\r
-                int[] selectionStart = new int[] { 0 };\r
-                byte[] urlBytes = url.getBytes();\r
-                int[] selectionEnd = new int[] { urlBytes.length };\r
-                result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes,\r
-                        urlBytes.length, selectionStart, selectionEnd);\r
+    return browser;\r
+  }\r
+\r
+  /**\r
+   * Attempts to open the default web browser to the given URL.\r
+   * @param url The URL to open\r
+   * @throws IOException If the web browser could not be located or does not run\r
+   */\r
+  public static void openURL(String url)\r
+      throws IOException\r
+  {\r
+    if (!loadedWithoutErrors)\r
+    {\r
+      throw new IOException("Exception in finding browser: " +\r
+                            errorMessage);\r
+    }\r
 \r
-                if (result == 0) {\r
-                    // Ignore the return value; the URL was launched successfully\r
-                    // regardless of what happens here.\r
-                    ICStop(instance);\r
-                } else {\r
-                    throw new IOException("Unable to launch URL: " + result);\r
-                }\r
-            } else {\r
-                throw new IOException(\r
-                    "Unable to create an Internet Config instance: " + result);\r
-            }\r
+    Object browser = locateBrowser();\r
 \r
-            break;\r
+    if (browser == null)\r
+    {\r
+      throw new IOException("Unable to locate browser: " + errorMessage);\r
+    }\r
 \r
-        case MRJ_3_1:\r
+    switch (jvm)\r
+    {\r
+      case MRJ_2_0:\r
+\r
+        Object aeDesc = null;\r
+\r
+        try\r
+        {\r
+          aeDesc = aeDescConstructor.newInstance(new Object[]\r
+                                                 {url});\r
+          putParameter.invoke(browser,\r
+                              new Object[]\r
+                              {keyDirectObject, aeDesc});\r
+          sendNoReply.invoke(browser, new Object[]\r
+                             {});\r
+        }\r
+        catch (InvocationTargetException ite)\r
+        {\r
+          throw new IOException(\r
+              "InvocationTargetException while creating AEDesc: " +\r
+              ite.getMessage());\r
+        }\r
+        catch (IllegalAccessException iae)\r
+        {\r
+          throw new IOException(\r
+              "IllegalAccessException while building AppleEvent: " +\r
+              iae.getMessage());\r
+        }\r
+        catch (InstantiationException ie)\r
+        {\r
+          throw new IOException(\r
+              "InstantiationException while creating AEDesc: " +\r
+              ie.getMessage());\r
+        }\r
+        finally\r
+        {\r
+          aeDesc = null; // Encourage it to get disposed if it was created\r
+          browser = null; // Ditto\r
+        }\r
 \r
-            try {\r
-                openURL.invoke(null, new Object[] { url });\r
-            } catch (InvocationTargetException ite) {\r
-                throw new IOException(\r
-                    "InvocationTargetException while calling openURL: " +\r
-                    ite.getMessage());\r
-            } catch (IllegalAccessException iae) {\r
-                throw new IOException(\r
-                    "IllegalAccessException while calling openURL: " +\r
-                    iae.getMessage());\r
-            }\r
+        break;\r
+\r
+      case MRJ_2_1:\r
+        Runtime.getRuntime().exec(new String[]\r
+                                  { (String) browser, url});\r
+\r
+        break;\r
+\r
+      case MRJ_3_0:\r
+\r
+        int[] instance = new int[1];\r
+        int result = ICStart(instance, 0);\r
+\r
+        if (result == 0)\r
+        {\r
+          int[] selectionStart = new int[]\r
+              {\r
+              0};\r
+          byte[] urlBytes = url.getBytes();\r
+          int[] selectionEnd = new int[]\r
+              {\r
+              urlBytes.length};\r
+          result = ICLaunchURL(instance[0], new byte[]\r
+                               {0}, urlBytes,\r
+                               urlBytes.length, selectionStart, selectionEnd);\r
+\r
+          if (result == 0)\r
+          {\r
+            // Ignore the return value; the URL was launched successfully\r
+            // regardless of what happens here.\r
+            ICStop(instance);\r
+          }\r
+          else\r
+          {\r
+            throw new IOException("Unable to launch URL: " + result);\r
+          }\r
+        }\r
+        else\r
+        {\r
+          throw new IOException(\r
+              "Unable to create an Internet Config instance: " + result);\r
+        }\r
 \r
-            break;\r
-\r
-        case WINDOWS_NT:\r
-        case WINDOWS_9x:\r
-\r
-            // Add quotes around the URL to allow ampersands and other special\r
-            // characters to work.\r
-            Process process = Runtime.getRuntime().exec(new String[] {\r
-                        (String) browser, FIRST_WINDOWS_PARAMETER,\r
-                        SECOND_WINDOWS_PARAMETER, THIRD_WINDOWS_PARAMETER,\r
-                        '"' + url + '"'\r
-                    });\r
-\r
-            // This avoids a memory leak on some versions of Java on Windows.\r
-            // That's hinted at in <http://developer.java.sun.com/developer/qow/archive/68/>.\r
-            try {\r
-                process.waitFor();\r
-                process.exitValue();\r
-            } catch (InterruptedException ie) {\r
-                throw new IOException(\r
-                    "InterruptedException while launching browser: " +\r
-                    ie.getMessage());\r
-            }\r
+        break;\r
 \r
-            break;\r
+      case MRJ_3_1:\r
 \r
-        case OTHER:\r
+        try\r
+        {\r
+          openURL.invoke(null, new Object[]\r
+                         {url});\r
+        }\r
+        catch (InvocationTargetException ite)\r
+        {\r
+          throw new IOException(\r
+              "InvocationTargetException while calling openURL: " +\r
+              ite.getMessage());\r
+        }\r
+        catch (IllegalAccessException iae)\r
+        {\r
+          throw new IOException(\r
+              "IllegalAccessException while calling openURL: " +\r
+              iae.getMessage());\r
+        }\r
 \r
-            // Assume that we're on Unix and that Netscape (actually Firefox) is installed\r
-            // First, attempt to open the URL in a currently running session of Netscape\r
-            // JBPNote log debug\r
+        break\r
+            ;\r
+\r
+      case WINDOWS_NT:\r
+      case WINDOWS_9x:\r
+\r
+        // Add quotes around the URL to allow ampersands and other special\r
+        // characters to work.\r
+        Process process = Runtime.getRuntime().exec(new String[]\r
+            {\r
+            (String) browser, FIRST_WINDOWS_PARAMETER,\r
+            SECOND_WINDOWS_PARAMETER, THIRD_WINDOWS_PARAMETER,\r
+            '"' + url + '"'\r
+        });\r
+\r
+        // This avoids a memory leak on some versions of Java on Windows.\r
+        // That's hinted at in <http://developer.java.sun.com/developer/qow/archive/68/>.\r
+        try\r
+        {\r
+          process.waitFor();\r
+          process.exitValue();\r
+        }\r
+        catch (InterruptedException ie)\r
+        {\r
+          throw new IOException(\r
+              "InterruptedException while launching browser: " +\r
+              ie.getMessage());\r
+        }\r
 \r
-            /* System.out.println("Executing : "+browser+" "+
-                                                                                                    NETSCAPE_REMOTE_PARAMETER+" "+
-                                                                                                    NETSCAPE_OPEN_PARAMETER_START +
-                                                                                                    url +
-                                                                                                    NETSCAPE_OPEN_NEW_WINDOW +
-                                                                                                    NETSCAPE_OPEN_PARAMETER_END);
- */\r
-            process = Runtime.getRuntime().exec(new String[] {\r
-                        (String) browser, NETSCAPE_REMOTE_PARAMETER,\r
-                        \r
-                    NETSCAPE_OPEN_PARAMETER_START + url +\r
-                        NETSCAPE_OPEN_NEW_WINDOW + NETSCAPE_OPEN_PARAMETER_END\r
-                    });\r
-\r
-            try {\r
-                int exitCode = process.waitFor();\r
-\r
-                if (exitCode != 0) { // if Netscape was not open\r
-                    Runtime.getRuntime().exec(new String[] { (String) browser, url });\r
-                }\r
-            } catch (InterruptedException ie) {\r
-                throw new IOException(\r
-                    "InterruptedException while launching browser: " +\r
-                    ie.getMessage());\r
-            }\r
+        break\r
+            ;\r
+\r
+      case OTHER:\r
+\r
+        // Assume that we're on Unix and that Netscape (actually Firefox) is installed\r
+        // First, attempt to open the URL in a currently running session of Netscape\r
+        // JBPNote log debug\r
+\r
+        /* System.out.println("Executing : "+browser+" "+\r
+         NETSCAPE_REMOTE_PARAMETER+" "+\r
+         NETSCAPE_OPEN_PARAMETER_START +\r
+         url +\r
+         NETSCAPE_OPEN_NEW_WINDOW +\r
+         NETSCAPE_OPEN_PARAMETER_END);\r
+         */\r
+        process = Runtime.getRuntime().exec(new String[]\r
+                                            {\r
+                                            (String) browser,\r
+                                            NETSCAPE_REMOTE_PARAMETER,\r
+\r
+                                            NETSCAPE_OPEN_PARAMETER_START + url +\r
+                                            NETSCAPE_OPEN_NEW_WINDOW +\r
+                                            NETSCAPE_OPEN_PARAMETER_END\r
+        });\r
+\r
+        try\r
+        {\r
+          int exitCode = process.waitFor();\r
+\r
+          if (exitCode != 0)\r
+          { // if Netscape was not open\r
+            Runtime.getRuntime().exec(new String[]\r
+                                      { (String) browser, url});\r
+          }\r
+        }\r
+        catch (InterruptedException ie)\r
+        {\r
+          throw new IOException(\r
+              "InterruptedException while launching browser: " +\r
+              ie.getMessage());\r
+        }\r
 \r
-            break;\r
+        break\r
+            ;\r
 \r
-        default:\r
+      default:\r
 \r
-            // This should never occur, but if it does, we'll try the simplest thing possible\r
-            Runtime.getRuntime().exec(new String[] { (String) browser, url });\r
+        // This should never occur, but if it does, we'll try the simplest thing possible\r
+        Runtime.getRuntime().exec(new String[]\r
+                                  { (String) browser, url});\r
 \r
-            break;\r
-        }\r
+        break;\r
     }\r
+  }\r
 \r
-    /**
- * Methods required for Mac OS X.  The presence of native methods does not cause
- * any problems on other platforms.
- */\r
-    private native static int ICStart(int[] instance, int signature);\r
+  /**\r
+   * Methods required for Mac OS X.  The presence of native methods does not cause\r
+   * any problems on other platforms.\r
+   */\r
+  private native static int ICStart(int[] instance, int signature);\r
 \r
-    private native static int ICStop(int[] instance);\r
+  private native static int ICStop(int[] instance);\r
 \r
-    private native static int ICLaunchURL(int instance, byte[] hint,\r
-        byte[] data, int len, int[] selectionStart, int[] selectionEnd);\r
+  private native static int ICLaunchURL(int instance, byte[] hint,\r
+                                        byte[] data, int len,\r
+                                        int[] selectionStart,\r
+                                        int[] selectionEnd);\r
 }\r