PageRenderTime 67ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/es/uvigo/darwin/xprottest/util/BrowserLauncher.java

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