01: package com.umlet.control;
02:
03: import java.lang.reflect.Method;
04: import javax.swing.JOptionPane;
05:
06: public class BrowserLauncher {
07:
08: private static final String errMsg = "Error attempting to launch web browser";
09:
10: public static void openURL(String url) {
11: String osName = System.getProperty("os.name");
12: try {
13: if (osName.startsWith("Mac OS")) {
14: Class fileMgr = Class
15: .forName("com.apple.eio.FileManager");
16: Method openURL = fileMgr.getDeclaredMethod("openURL",
17: new Class[] { String.class });
18: openURL.invoke(null, new Object[] { url });
19: } else if (osName.startsWith("Windows"))
20: Runtime.getRuntime().exec(
21: "rundll32 url.dll,FileProtocolHandler " + url);
22: else { //assume Unix or Linux
23: String[] browsers = { "firefox", "opera", "konqueror",
24: "epiphany", "mozilla", "netscape" };
25: String browser = null;
26: for (int count = 0; count < browsers.length
27: && browser == null; count++)
28: if (Runtime.getRuntime().exec(
29: new String[] { "which", browsers[count] })
30: .waitFor() == 0)
31: browser = browsers[count];
32: if (browser == null)
33: throw new Exception("Could not find web browser");
34: else
35: Runtime.getRuntime().exec(
36: new String[] { browser, url });
37: }
38: } catch (Exception e) {
39: System.err.println("Error in openURL:" + e.getMessage());
40: }
41: }
42: }
|