PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/TaxonDNA/com/ggvaidya/TaxonDNA/Others/BrowserLauncher.java

http://taxondna.googlecode.com/
Java | 586 lines | 372 code | 52 blank | 162 comment | 39 complexity | 073bbb68391283e158fc9ba62881e897 MD5 | raw file
Possible License(s): GPL-2.0
  1. package com.ggvaidya.TaxonDNA.Others;
  2. /* All code after this line entirely the creation and (c) Eric Albert, 1999-2001. Used as per conditions. */
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.lang.reflect.Constructor;
  7. import java.lang.reflect.Field;
  8. import java.lang.reflect.InvocationTargetException;
  9. import java.lang.reflect.Method;
  10. /**
  11. * BrowserLauncher is a class that provides one static method, openURL, which opens the default
  12. * web browser for the current user of the system to the given URL. It may support other
  13. * protocols depending on the system -- mailto, ftp, etc. -- but that has not been rigorously
  14. * tested and is not guaranteed to work.
  15. * <p>
  16. * Yes, this is platform-specific code, and yes, it may rely on classes on certain platforms
  17. * that are not part of the standard JDK. What we're trying to do, though, is to take something
  18. * that's frequently desirable but inherently platform-specific -- opening a default browser --
  19. * and allow programmers (you, for example) to do so without worrying about dropping into native
  20. * code or doing anything else similarly evil.
  21. * <p>
  22. * Anyway, this code is completely in Java and will run on all JDK 1.1-compliant systems without
  23. * modification or a need for additional libraries. All classes that are required on certain
  24. * platforms to allow this to run are dynamically loaded at runtime via reflection and, if not
  25. * found, will not cause this to do anything other than returning an error when opening the
  26. * browser.
  27. * <p>
  28. * There are certain system requirements for this class, as it's running through Runtime.exec(),
  29. * which is Java's way of making a native system call. Currently, this requires that a Macintosh
  30. * have a Finder which supports the GURL event, which is true for Mac OS 8.0 and 8.1 systems that
  31. * have the Internet Scripting AppleScript dictionary installed in the Scripting Additions folder
  32. * in the Extensions folder (which is installed by default as far as I know under Mac OS 8.0 and
  33. * 8.1), and for all Mac OS 8.5 and later systems. On Windows, it only runs under Win32 systems
  34. * (Windows 95, 98, and NT 4.0, as well as later versions of all). On other systems, this drops
  35. * back from the inherently platform-sensitive concept of a default browser and simply attempts
  36. * to launch Netscape via a shell command.
  37. * <p>
  38. * This code is Copyright 1999-2001 by Eric Albert (ejalbert@cs.stanford.edu) and may be
  39. * redistributed or modified in any form without restrictions as long as the portion of this
  40. * comment from this paragraph through the end of the comment is not removed. The author
  41. * requests that he be notified of any application, applet, or other binary that makes use of
  42. * this code, but that's more out of curiosity than anything and is not required. This software
  43. * includes no warranty. The author is not repsonsible for any loss of data or functionality
  44. * or any adverse or unexpected effects of using this software.
  45. * <p>
  46. * Credits:
  47. * <br>Steven Spencer, JavaWorld magazine (<a href="http://www.javaworld.com/javaworld/javatips/jw-javatip66.html">Java Tip 66</a>)
  48. * <br>Thanks also to Ron B. Yeh, Eric Shapiro, Ben Engber, Paul Teitlebaum, Andrea Cantatore,
  49. * Larry Barowski, Trevor Bedzek, Frank Miedrich, and Ron Rabakukk
  50. *
  51. * @author Eric Albert (<a href="mailto:ejalbert@cs.stanford.edu">ejalbert@cs.stanford.edu</a>)
  52. * @version 1.4b1 (Released June 20, 2001)
  53. */
  54. public class BrowserLauncher {
  55. /**
  56. * The Java virtual machine that we are running on. Actually, in most cases we only care
  57. * about the operating system, but some operating systems require us to switch on the VM. */
  58. private static int jvm;
  59. /** The browser for the system */
  60. private static Object browser;
  61. /**
  62. * Caches whether any classes, methods, and fields that are not part of the JDK and need to
  63. * be dynamically loaded at runtime loaded successfully.
  64. * <p>
  65. * Note that if this is <code>false</code>, <code>openURL()</code> will always return an
  66. * IOException.
  67. */
  68. private static boolean loadedWithoutErrors;
  69. /** The com.apple.mrj.MRJFileUtils class */
  70. private static Class mrjFileUtilsClass;
  71. /** The com.apple.mrj.MRJOSType class */
  72. private static Class mrjOSTypeClass;
  73. /** The com.apple.MacOS.AEDesc class */
  74. private static Class aeDescClass;
  75. /** The <init>(int) method of com.apple.MacOS.AETarget */
  76. private static Constructor aeTargetConstructor;
  77. /** The <init>(int, int, int) method of com.apple.MacOS.AppleEvent */
  78. private static Constructor appleEventConstructor;
  79. /** The <init>(String) method of com.apple.MacOS.AEDesc */
  80. private static Constructor aeDescConstructor;
  81. /** The findFolder method of com.apple.mrj.MRJFileUtils */
  82. private static Method findFolder;
  83. /** The getFileCreator method of com.apple.mrj.MRJFileUtils */
  84. private static Method getFileCreator;
  85. /** The getFileType method of com.apple.mrj.MRJFileUtils */
  86. private static Method getFileType;
  87. /** The openURL method of com.apple.mrj.MRJFileUtils */
  88. private static Method openURL;
  89. /** The makeOSType method of com.apple.MacOS.OSUtils */
  90. private static Method makeOSType;
  91. /** The putParameter method of com.apple.MacOS.AppleEvent */
  92. private static Method putParameter;
  93. /** The sendNoReply method of com.apple.MacOS.AppleEvent */
  94. private static Method sendNoReply;
  95. /** Actually an MRJOSType pointing to the System Folder on a Macintosh */
  96. private static Object kSystemFolderType;
  97. /** The keyDirectObject AppleEvent parameter type */
  98. private static Integer keyDirectObject;
  99. /** The kAutoGenerateReturnID AppleEvent code */
  100. private static Integer kAutoGenerateReturnID;
  101. /** The kAnyTransactionID AppleEvent code */
  102. private static Integer kAnyTransactionID;
  103. /** The linkage object required for JDirect 3 on Mac OS X. */
  104. private static Object linkage;
  105. /** The framework to reference on Mac OS X */
  106. private static final String JDirect_MacOSX = "/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/HIToolbox";
  107. /** JVM constant for MRJ 2.0 */
  108. private static final int MRJ_2_0 = 0;
  109. /** JVM constant for MRJ 2.1 or later */
  110. private static final int MRJ_2_1 = 1;
  111. /** JVM constant for Java on Mac OS X 10.0 (MRJ 3.0) */
  112. private static final int MRJ_3_0 = 3;
  113. /** JVM constant for MRJ 3.1 */
  114. private static final int MRJ_3_1 = 4;
  115. /** JVM constant for any Windows NT JVM */
  116. private static final int WINDOWS_NT = 5;
  117. /** JVM constant for any Windows 9x JVM */
  118. private static final int WINDOWS_9x = 6;
  119. /** JVM constant for any other platform */
  120. private static final int OTHER = -1;
  121. /**
  122. * The file type of the Finder on a Macintosh. Hardcoding "Finder" would keep non-U.S. English
  123. * systems from working properly.
  124. */
  125. private static final String FINDER_TYPE = "FNDR";
  126. /**
  127. * The creator code of the Finder on a Macintosh, which is needed to send AppleEvents to the
  128. * application.
  129. */
  130. private static final String FINDER_CREATOR = "MACS";
  131. /** The name for the AppleEvent type corresponding to a GetURL event. */
  132. private static final String GURL_EVENT = "GURL";
  133. /**
  134. * The first parameter that needs to be passed into Runtime.exec() to open the default web
  135. * browser on Windows.
  136. */
  137. private static final String FIRST_WINDOWS_PARAMETER = "/c";
  138. /** The second parameter for Runtime.exec() on Windows. */
  139. private static final String SECOND_WINDOWS_PARAMETER = "start";
  140. /**
  141. * The third parameter for Runtime.exec() on Windows. This is a "title"
  142. * parameter that the command line expects. Setting this parameter allows
  143. * URLs containing spaces to work.
  144. */
  145. private static final String THIRD_WINDOWS_PARAMETER = "\"\"";
  146. /**
  147. * The shell parameters for Netscape that opens a given URL in an already-open copy of Netscape
  148. * on many command-line systems.
  149. */
  150. private static final String NETSCAPE_REMOTE_PARAMETER = "-remote";
  151. private static final String NETSCAPE_OPEN_PARAMETER_START = "'openURL(";
  152. private static final String NETSCAPE_OPEN_PARAMETER_END = ")'";
  153. /**
  154. * The message from any exception thrown throughout the initialization process.
  155. */
  156. private static String errorMessage;
  157. /**
  158. * An initialization block that determines the operating system and loads the necessary
  159. * runtime data.
  160. */
  161. static {
  162. loadedWithoutErrors = true;
  163. String osName = System.getProperty("os.name");
  164. if (osName.startsWith("Mac OS")) {
  165. String mrjVersion = System.getProperty("mrj.version");
  166. String majorMRJVersion = mrjVersion.substring(0, 3);
  167. try {
  168. double version = Double.valueOf(majorMRJVersion).doubleValue();
  169. if (version == 2) {
  170. jvm = MRJ_2_0;
  171. } else if (version >= 2.1 && version < 3) {
  172. // Assume that all 2.x versions of MRJ work the same. MRJ 2.1 actually
  173. // works via Runtime.exec() and 2.2 supports that but has an openURL() method
  174. // as well that we currently ignore.
  175. jvm = MRJ_2_1;
  176. } else if (version == 3.0) {
  177. jvm = MRJ_3_0;
  178. } else if (version >= 3.1) {
  179. // Assume that all 3.1 and later versions of MRJ work the same.
  180. jvm = MRJ_3_1;
  181. } else {
  182. loadedWithoutErrors = false;
  183. errorMessage = "Unsupported MRJ version: " + version;
  184. }
  185. } catch (NumberFormatException nfe) {
  186. loadedWithoutErrors = false;
  187. errorMessage = "Invalid MRJ version: " + mrjVersion;
  188. }
  189. } else if (osName.startsWith("Windows")) {
  190. if (osName.indexOf("9") != -1) {
  191. jvm = WINDOWS_9x;
  192. } else {
  193. jvm = WINDOWS_NT;
  194. }
  195. } else {
  196. jvm = OTHER;
  197. }
  198. if (loadedWithoutErrors) { // if we haven't hit any errors yet
  199. loadedWithoutErrors = loadClasses();
  200. }
  201. }
  202. /**
  203. * This class should be never be instantiated; this just ensures so.
  204. */
  205. private BrowserLauncher() { }
  206. /**
  207. * Called by a static initializer to load any classes, fields, and methods required at runtime
  208. * to locate the user's web browser.
  209. * @return <code>true</code> if all intialization succeeded
  210. * <code>false</code> if any portion of the initialization failed
  211. */
  212. private static boolean loadClasses() {
  213. switch (jvm) {
  214. case MRJ_2_0:
  215. try {
  216. Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
  217. Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
  218. Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
  219. Class aeClass = Class.forName("com.apple.MacOS.ae");
  220. aeDescClass = Class.forName("com.apple.MacOS.AEDesc");
  221. aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class [] { int.class });
  222. appleEventConstructor = appleEventClass.getDeclaredConstructor(new Class[] { int.class, int.class, aeTargetClass, int.class, int.class });
  223. aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] { String.class });
  224. makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class [] { String.class });
  225. putParameter = appleEventClass.getDeclaredMethod("putParameter", new Class[] { int.class, aeDescClass });
  226. sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[] { });
  227. Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject");
  228. keyDirectObject = (Integer) keyDirectObjectField.get(null);
  229. Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID");
  230. kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField.get(null);
  231. Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID");
  232. kAnyTransactionID = (Integer) anyTransactionIDField.get(null);
  233. } catch (ClassNotFoundException cnfe) {
  234. errorMessage = cnfe.getMessage();
  235. return false;
  236. } catch (NoSuchMethodException nsme) {
  237. errorMessage = nsme.getMessage();
  238. return false;
  239. } catch (NoSuchFieldException nsfe) {
  240. errorMessage = nsfe.getMessage();
  241. return false;
  242. } catch (IllegalAccessException iae) {
  243. errorMessage = iae.getMessage();
  244. return false;
  245. }
  246. break;
  247. case MRJ_2_1:
  248. try {
  249. mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
  250. mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");
  251. Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType");
  252. kSystemFolderType = systemFolderField.get(null);
  253. findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] { mrjOSTypeClass });
  254. getFileCreator = mrjFileUtilsClass.getDeclaredMethod("getFileCreator", new Class[] { File.class });
  255. getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] { File.class });
  256. } catch (ClassNotFoundException cnfe) {
  257. errorMessage = cnfe.getMessage();
  258. return false;
  259. } catch (NoSuchFieldException nsfe) {
  260. errorMessage = nsfe.getMessage();
  261. return false;
  262. } catch (NoSuchMethodException nsme) {
  263. errorMessage = nsme.getMessage();
  264. return false;
  265. } catch (SecurityException se) {
  266. errorMessage = se.getMessage();
  267. return false;
  268. } catch (IllegalAccessException iae) {
  269. errorMessage = iae.getMessage();
  270. return false;
  271. }
  272. break;
  273. case MRJ_3_0:
  274. try {
  275. Class linker = Class.forName("com.apple.mrj.jdirect.Linker");
  276. Constructor constructor = linker.getConstructor(new Class[]{ Class.class });
  277. linkage = constructor.newInstance(new Object[] { BrowserLauncher.class });
  278. } catch (ClassNotFoundException cnfe) {
  279. errorMessage = cnfe.getMessage();
  280. return false;
  281. } catch (NoSuchMethodException nsme) {
  282. errorMessage = nsme.getMessage();
  283. return false;
  284. } catch (InvocationTargetException ite) {
  285. errorMessage = ite.getMessage();
  286. return false;
  287. } catch (InstantiationException ie) {
  288. errorMessage = ie.getMessage();
  289. return false;
  290. } catch (IllegalAccessException iae) {
  291. errorMessage = iae.getMessage();
  292. return false;
  293. }
  294. break;
  295. case MRJ_3_1:
  296. try {
  297. mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
  298. openURL = mrjFileUtilsClass.getDeclaredMethod("openURL", new Class[] { String.class });
  299. } catch (ClassNotFoundException cnfe) {
  300. errorMessage = cnfe.getMessage();
  301. return false;
  302. } catch (NoSuchMethodException nsme) {
  303. errorMessage = nsme.getMessage();
  304. return false;
  305. }
  306. break;
  307. default:
  308. break;
  309. }
  310. return true;
  311. }
  312. /**
  313. * Attempts to locate the default web browser on the local system. Caches results so it
  314. * only locates the browser once for each use of this class per JVM instance.
  315. * @return The browser for the system. Note that this may not be what you would consider
  316. * to be a standard web browser; instead, it's the application that gets called to
  317. * open the default web browser. In some cases, this will be a non-String object
  318. * that provides the means of calling the default browser.
  319. */
  320. private static Object locateBrowser() {
  321. if (browser != null) {
  322. return browser;
  323. }
  324. switch (jvm) {
  325. case MRJ_2_0:
  326. try {
  327. Integer finderCreatorCode = (Integer) makeOSType.invoke(null, new Object[] { FINDER_CREATOR });
  328. Object aeTarget = aeTargetConstructor.newInstance(new Object[] { finderCreatorCode });
  329. Integer gurlType = (Integer) makeOSType.invoke(null, new Object[] { GURL_EVENT });
  330. Object appleEvent = appleEventConstructor.newInstance(new Object[] { gurlType, gurlType, aeTarget, kAutoGenerateReturnID, kAnyTransactionID });
  331. // Don't set browser = appleEvent because then the next time we call
  332. // locateBrowser(), we'll get the same AppleEvent, to which we'll already have
  333. // added the relevant parameter. Instead, regenerate the AppleEvent every time.
  334. // There's probably a way to do this better; if any has any ideas, please let
  335. // me know.
  336. return appleEvent;
  337. } catch (IllegalAccessException iae) {
  338. browser = null;
  339. errorMessage = iae.getMessage();
  340. return browser;
  341. } catch (InstantiationException ie) {
  342. browser = null;
  343. errorMessage = ie.getMessage();
  344. return browser;
  345. } catch (InvocationTargetException ite) {
  346. browser = null;
  347. errorMessage = ite.getMessage();
  348. return browser;
  349. }
  350. case MRJ_2_1:
  351. File systemFolder;
  352. try {
  353. systemFolder = (File) findFolder.invoke(null, new Object[] { kSystemFolderType });
  354. } catch (IllegalArgumentException iare) {
  355. browser = null;
  356. errorMessage = iare.getMessage();
  357. return browser;
  358. } catch (IllegalAccessException iae) {
  359. browser = null;
  360. errorMessage = iae.getMessage();
  361. return browser;
  362. } catch (InvocationTargetException ite) {
  363. browser = null;
  364. errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
  365. return browser;
  366. }
  367. String[] systemFolderFiles = systemFolder.list();
  368. // Avoid a FilenameFilter because that can't be stopped mid-list
  369. for(int i = 0; i < systemFolderFiles.length; i++) {
  370. try {
  371. File file = new File(systemFolder, systemFolderFiles[i]);
  372. if (!file.isFile()) {
  373. continue;
  374. }
  375. // We're looking for a file with a creator code of 'MACS' and
  376. // a type of 'FNDR'. Only requiring the type results in non-Finder
  377. // applications being picked up on certain Mac OS 9 systems,
  378. // especially German ones, and sending a GURL event to those
  379. // applications results in a logout under Multiple Users.
  380. Object fileType = getFileType.invoke(null, new Object[] { file });
  381. if (FINDER_TYPE.equals(fileType.toString())) {
  382. Object fileCreator = getFileCreator.invoke(null, new Object[] { file });
  383. if (FINDER_CREATOR.equals(fileCreator.toString())) {
  384. browser = file.toString(); // Actually the Finder, but that's OK
  385. return browser;
  386. }
  387. }
  388. } catch (IllegalArgumentException iare) {
  389. browser = browser;
  390. errorMessage = iare.getMessage();
  391. return null;
  392. } catch (IllegalAccessException iae) {
  393. browser = null;
  394. errorMessage = iae.getMessage();
  395. return browser;
  396. } catch (InvocationTargetException ite) {
  397. browser = null;
  398. errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
  399. return browser;
  400. }
  401. }
  402. browser = null;
  403. break;
  404. case MRJ_3_0:
  405. case MRJ_3_1:
  406. browser = ""; // Return something non-null
  407. break;
  408. case WINDOWS_NT:
  409. browser = "cmd.exe";
  410. break;
  411. case WINDOWS_9x:
  412. browser = "command.com";
  413. break;
  414. case OTHER:
  415. default:
  416. browser = "netscape";
  417. break;
  418. }
  419. return browser;
  420. }
  421. /**
  422. * Attempts to open the default web browser to the given URL.
  423. * @param url The URL to open
  424. * @throws IOException If the web browser could not be located or does not run
  425. */
  426. public static void openURL(String url) throws IOException {
  427. if (!loadedWithoutErrors) {
  428. throw new IOException("Exception in finding browser: " + errorMessage);
  429. }
  430. Object browser = locateBrowser();
  431. if (browser == null) {
  432. throw new IOException("Unable to locate browser: " + errorMessage);
  433. }
  434. switch (jvm) {
  435. case MRJ_2_0:
  436. Object aeDesc = null;
  437. try {
  438. aeDesc = aeDescConstructor.newInstance(new Object[] { url });
  439. putParameter.invoke(browser, new Object[] { keyDirectObject, aeDesc });
  440. sendNoReply.invoke(browser, new Object[] { });
  441. } catch (InvocationTargetException ite) {
  442. throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage());
  443. } catch (IllegalAccessException iae) {
  444. throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage());
  445. } catch (InstantiationException ie) {
  446. throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage());
  447. } finally {
  448. aeDesc = null; // Encourage it to get disposed if it was created
  449. browser = null; // Ditto
  450. }
  451. break;
  452. case MRJ_2_1:
  453. Runtime.getRuntime().exec(new String[] { (String) browser, url } );
  454. break;
  455. case MRJ_3_0:
  456. int[] instance = new int[1];
  457. int result = ICStart(instance, 0);
  458. if (result == 0) {
  459. int[] selectionStart = new int[] { 0 };
  460. byte[] urlBytes = url.getBytes();
  461. int[] selectionEnd = new int[] { urlBytes.length };
  462. result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes,
  463. urlBytes.length, selectionStart,
  464. selectionEnd);
  465. if (result == 0) {
  466. // Ignore the return value; the URL was launched successfully
  467. // regardless of what happens here.
  468. ICStop(instance);
  469. } else {
  470. throw new IOException("Unable to launch URL: " + result);
  471. }
  472. } else {
  473. throw new IOException("Unable to create an Internet Config instance: " + result);
  474. }
  475. break;
  476. case MRJ_3_1:
  477. try {
  478. openURL.invoke(null, new Object[] { url });
  479. } catch (InvocationTargetException ite) {
  480. throw new IOException("InvocationTargetException while calling openURL: " + ite.getMessage());
  481. } catch (IllegalAccessException iae) {
  482. throw new IOException("IllegalAccessException while calling openURL: " + iae.getMessage());
  483. }
  484. break;
  485. case WINDOWS_NT:
  486. case WINDOWS_9x:
  487. // Add quotes around the URL to allow ampersands and other special
  488. // characters to work.
  489. Process process = Runtime.getRuntime().exec(new String[] { (String) browser,
  490. FIRST_WINDOWS_PARAMETER,
  491. SECOND_WINDOWS_PARAMETER,
  492. THIRD_WINDOWS_PARAMETER,
  493. '"' + url + '"' });
  494. // This avoids a memory leak on some versions of Java on Windows.
  495. // That's hinted at in <http://developer.java.sun.com/developer/qow/archive/68/>.
  496. try {
  497. process.waitFor();
  498. process.exitValue();
  499. } catch (InterruptedException ie) {
  500. throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
  501. }
  502. break;
  503. case OTHER:
  504. // Assume that we're on Unix and that Netscape is installed
  505. // First, attempt to open the URL in a currently running session of Netscape
  506. process = Runtime.getRuntime().exec(new String[] { (String) browser,
  507. NETSCAPE_REMOTE_PARAMETER,
  508. NETSCAPE_OPEN_PARAMETER_START +
  509. url +
  510. NETSCAPE_OPEN_PARAMETER_END });
  511. try {
  512. int exitCode = process.waitFor();
  513. if (exitCode != 0) { // if Netscape was not open
  514. Runtime.getRuntime().exec(new String[] { (String) browser, url });
  515. }
  516. } catch (InterruptedException ie) {
  517. throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
  518. }
  519. break;
  520. default:
  521. // This should never occur, but if it does, we'll try the simplest thing possible
  522. Runtime.getRuntime().exec(new String[] { (String) browser, url });
  523. break;
  524. }
  525. }
  526. /**
  527. * Methods required for Mac OS X. The presence of native methods does not cause
  528. * any problems on other platforms.
  529. */
  530. private native static int ICStart(int[] instance, int signature);
  531. private native static int ICStop(int[] instance);
  532. private native static int ICLaunchURL(int instance, byte[] hint, byte[] data, int len,
  533. int[] selectionStart, int[] selectionEnd);
  534. }