PageRenderTime 57ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/hpsource/BrowserLauncher.java

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