<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FDevelopment_Class%2FSystem_Browser</id>
		<title>Java/Development Class/System Browser - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FDevelopment_Class%2FSystem_Browser"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Development_Class/System_Browser&amp;action=history"/>
		<updated>2026-05-12T17:33:31Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/Development_Class/System_Browser&amp;diff=8389&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Development_Class/System_Browser&amp;diff=8389&amp;oldid=prev"/>
				<updated>2010-06-01T07:01:08Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 07:01, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

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

	</feed>