1 package com.calipso.reportgenerator.common; 2 3 import java.lang.reflect.Method ; 4 5 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.forName("com.apple.mrj.MRJFileUtils"); 20 Method openURL = macUtils.getDeclaredMethod("openURL", new Class [] {String .class}); 21 openURL.invoke(null, new Object [] {url}); 22 } else if (osName.startsWith("Windows")) 23 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); 24 else { String [] browsers = { "firefox", "opera", "konqueror", "mozilla", "netscape" }; 26 String browser = null; 27 for (int count = 0; count < browsers.length && browser == null; count++) 28 if (Runtime.getRuntime().exec( new String [] {"which", browsers[count]}).waitFor() == 0) 29 browser = browsers[count]; 30 if (browser == null) 31 throw new Exception ("Could not find web browser."); 32 else Runtime.getRuntime().exec(new String [] {browser, url}); 33 } 34 } 35 } 36 | Popular Tags |