01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.admin.common;
05:
06: import java.lang.reflect.Method;
07: import javax.swing.JOptionPane;
08:
09: public class BrowserLauncher {
10: private static final String errMsg = "Error attempting to launch web browser";
11:
12: private static final String[] UNIX_BROWSERS = { "firefox", "opera",
13: "konqueror", "epiphany", "mozilla", "netscape" };
14:
15: public static void openURL(String url) {
16: String osName = System.getProperty("os.name");
17:
18: try {
19: if (osName.startsWith("Mac OS")) {
20: Class fileMgr = Class
21: .forName("com.apple.eio.FileManager");
22: Method openURL = fileMgr.getDeclaredMethod("openURL",
23: new Class[] { String.class });
24:
25: openURL.invoke(null, new Object[] { url });
26: } else if (osName.startsWith("Windows")) {
27: Runtime.getRuntime().exec(
28: "rundll32 url.dll,FileProtocolHandler " + url);
29: } else {
30: String browser = null;
31:
32: for (int count = 0; count < UNIX_BROWSERS.length
33: && browser == null; count++) {
34: if (Runtime.getRuntime().exec(
35: new String[] { "which",
36: UNIX_BROWSERS[count] }).waitFor() == 0) {
37: browser = UNIX_BROWSERS[count];
38: }
39: }
40:
41: if (browser == null) {
42: throw new Exception("Could not find web browser");
43: } else {
44: Runtime.getRuntime().exec(
45: new String[] { browser, url });
46: }
47: }
48: } catch (Exception e) {
49: JOptionPane.showMessageDialog(null, errMsg + ":\n"
50: + e.getLocalizedMessage());
51: }
52: }
53: }
|