01: package com.calipso.reportgenerator.common;
02:
03: import java.lang.reflect.Method;
04:
05: /**
06: *
07: * User: jbassino
08: * Date: 26-oct-2005
09: * Time: 15:24:27
10: *
11: */
12: public class BrowserLauncher {
13:
14: private static final String errMsg = "Error attempting to launch web browser";
15:
16: public static void openURL(String url) throws Exception {
17: String osName = System.getProperty("os.name");
18: if (osName.startsWith("Mac OS")) {
19: Class macUtils = Class
20: .forName("com.apple.mrj.MRJFileUtils");
21: Method openURL = macUtils.getDeclaredMethod("openURL",
22: new Class[] { String.class });
23: openURL.invoke(null, new Object[] { url });
24: } else if (osName.startsWith("Windows"))
25: Runtime.getRuntime().exec(
26: "rundll32 url.dll,FileProtocolHandler " + url);
27: else { //assume Unix or Linux
28: String[] browsers = { "firefox", "opera", "konqueror",
29: "mozilla", "netscape" };
30: String browser = null;
31: for (int count = 0; count < browsers.length
32: && browser == null; count++)
33: if (Runtime.getRuntime().exec(
34: new String[] { "which", browsers[count] })
35: .waitFor() == 0)
36: browser = browsers[count];
37: if (browser == null)
38: throw new Exception("Could not find web browser.");
39: else
40: Runtime.getRuntime()
41: .exec(new String[] { browser, url });
42: }
43: }
44: }
|