1 package prefuse.util.ui; 2 3 import java.io.IOException ; 4 import java.net.URL ; 5 6 30 public abstract class BrowserLauncher { 31 32 private static final String WIN_ID = "Windows"; 33 private static final String WIN_PATH = "rundll32"; 34 private static final String WIN_FLAG = "url.dll,FileProtocolHandler"; 35 private static final String UNIX_PATH = "netscape"; 36 private static final String UNIX_FLAG = "-remote openURL"; 37 38 42 public static void showDocument(URL url) { 43 showDocument(url.toString()); 44 } 45 46 52 public static void showDocument(String url) { 53 boolean windows = isWindowsPlatform(); 54 String cmd = null; 55 try { 56 if (windows) { 57 cmd = WIN_PATH + " " + WIN_FLAG + " " + url; 59 Runtime.getRuntime().exec(cmd); 60 } else { 61 cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")"; 67 Process p = Runtime.getRuntime().exec(cmd); 68 try { 69 int exitCode = p.waitFor(); 72 if (exitCode != 0) { 73 cmd = UNIX_PATH + " " + url; 76 p = Runtime.getRuntime().exec(cmd); 77 } 78 } catch (InterruptedException x) { 79 System.err.println( 80 "Error bringing up browser, cmd='" + cmd + "'"); 81 System.err.println("Caught: " + x); 82 } 83 } 84 } catch (IOException x) { 85 System.err.println("Could not invoke browser, command=" + cmd); 87 System.err.println("Caught: " + x); 88 } 89 } 90 91 96 public static boolean isWindowsPlatform() { 97 String os = System.getProperty("os.name"); 98 return (os != null && os.startsWith(WIN_ID)); 99 } 100 101 106 public static void main(String [] argv) { 107 showDocument(argv[0]); 108 } 109 110 } | Popular Tags |