1 4 package com.tc.admin.common; 5 6 import java.lang.reflect.Method ; 7 import javax.swing.JOptionPane ; 8 9 public class BrowserLauncher { 10 private static final String errMsg = "Error attempting to launch web browser"; 11 12 private static final String [] UNIX_BROWSERS = { 13 "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" 14 }; 15 16 public static void openURL(String url) { 17 String osName = System.getProperty("os.name"); 18 19 try { 20 if(osName.startsWith("Mac OS")) { 21 Class fileMgr = Class.forName("com.apple.eio.FileManager"); 22 Method openURL = fileMgr.getDeclaredMethod("openURL", new Class [] {String .class}); 23 24 openURL.invoke(null, new Object [] {url}); 25 } 26 else if(osName.startsWith("Windows")) { 27 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); 28 } 29 else { 30 String browser = null; 31 32 for(int count = 0; count < UNIX_BROWSERS.length && browser == null; count++) { 33 if(Runtime.getRuntime().exec(new String [] {"which", UNIX_BROWSERS[count]}).waitFor() == 0) { 34 browser = UNIX_BROWSERS[count]; 35 } 36 } 37 38 if(browser == null) { 39 throw new Exception ("Could not find web browser"); 40 } 41 else { 42 Runtime.getRuntime().exec(new String [] {browser, url}); 43 } 44 } 45 } catch(Exception e) { 46 JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage()); 47 } 48 } 49 } 50 | Popular Tags |