6 package org.homelinux.largo.utils; |
6 package org.homelinux.largo.utils; |
7 |
7 |
8 import java.lang.reflect.Method; |
8 import java.lang.reflect.Method; |
9 |
9 |
10 import javax.swing.JOptionPane; |
10 import javax.swing.JOptionPane; |
|
11 |
11 /** |
12 /** |
12 * Cross-Platform Browserlaunch |
13 * Cross-Platform Browserlaunch |
13 */ |
14 */ |
14 public class BrowserLaunch { |
15 public class BrowserLaunch { |
15 private static final String errMsg = "Error attempting to launch web browser"; |
16 private static final String errMsg = "Error attempting to launch web browser"; |
16 |
17 |
17 /** |
18 /** |
18 * This method opens the URL in a native platform browser |
19 * This method opens the URL in a native platform browser |
19 */ |
20 */ |
20 public void openURL(String url) { |
21 public void openURL(String url) { |
21 String osName = System.getProperty("os.name"); |
22 String osName = System.getProperty("os.name"); |
22 try { |
23 try { |
23 if (osName.startsWith("Mac OS")) { |
24 if (osName.startsWith("Mac OS")) { |
24 Class<?> fileMgr = Class.forName("com.apple.eio.FileManager"); |
25 Class<?> fileMgr = Class.forName("com.apple.eio.FileManager"); |
25 Method openURL = fileMgr.getDeclaredMethod("openURL", |
26 Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { |
26 new Class[] { String.class }); |
27 String.class |
27 openURL.invoke(null, new Object[] { url }); |
28 }); |
28 } else if (osName.startsWith("Windows")) |
29 openURL.invoke(null, new Object[] { |
29 Runtime.getRuntime().exec( |
30 url |
30 "rundll32 url.dll,FileProtocolHandler " + url); |
31 }); |
31 else { |
32 } else if (osName.startsWith("Windows")) |
32 String[] browsers = { "firefox", "opera", "konqueror", |
33 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); |
33 "epiphany", "mozilla", "netscape" }; |
34 else { |
34 String browser = null; |
35 String[] browsers = { |
35 for (int count = 0; count < browsers.length && browser == null; count++) |
36 "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" |
36 if (Runtime.getRuntime().exec( |
37 }; |
37 new String[] { "which", browsers[count] }) |
38 String browser = null; |
38 .waitFor() == 0) |
39 for (int count = 0; count < browsers.length && browser == null; count++) |
39 browser = browsers[count]; |
40 if (Runtime.getRuntime().exec(new String[] { |
40 if (browser == null) |
41 "which", browsers[count] |
41 throw new Exception("Could not find web browser"); |
42 }).waitFor() == 0) |
42 else |
43 browser = browsers[count]; |
43 Runtime.getRuntime().exec(new String[] { browser, url }); |
44 if (browser == null) |
44 } |
45 throw new Exception("Could not find web browser"); |
45 } catch (Exception e) { |
46 else |
46 JOptionPane.showMessageDialog(null, errMsg + ":\n" |
47 Runtime.getRuntime().exec(new String[] { |
47 + e.getLocalizedMessage()); |
48 browser, url |
48 } |
49 }); |
49 } |
50 } |
|
51 } catch (Exception e) { |
|
52 JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage()); |
|
53 } |
|
54 } |
50 }; |
55 }; |