1 package hero.client.grapheditor; 2 3 import java.io.IOException ; 4 5 36 public class BrowserControl 37 { 38 static java.util.ResourceBundle resource = java.util.ResourceBundle.getBundle("resources.Traduction"); 39 47 public static void displayURL(String url) 48 { 49 boolean windows = isWindowsPlatform(); 50 String cmd = null; 51 try 52 { 53 if (windows) 54 { 55 cmd = WIN_PATH + " " + WIN_FLAG + " " + url; 57 Process p = Runtime.getRuntime().exec(cmd); 58 } 59 else 60 { 61 cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")"; 67 Process p = Runtime.getRuntime().exec(cmd); 68 try 69 { 70 int exitCode = p.waitFor(); 73 if (exitCode != 0) 74 { 75 cmd = UNIX_PATH + " " + url; 78 p = Runtime.getRuntime().exec(cmd); 79 } 80 } 81 catch(InterruptedException x) 82 { 83 System.err.println(resource.getString("browsercontrol.error") + 84 cmd + "'"); 85 System.err.println(resource.getString("browsercontrol.caught") + x); 86 } 87 } 88 } 89 catch(IOException x) 90 { 91 System.err.println(resource.getString("browsercontrol.notinvoke") + cmd); 93 System.err.println(resource.getString("browsercontrol.caught") + x); 94 } 95 } 96 102 public static boolean isWindowsPlatform() 103 { 104 String os = System.getProperty("os.name"); 105 if ( os != null && os.startsWith(WIN_ID)) 106 return true; 107 else 108 return false; 109 110 } 111 114 public static void main(String [] args) 115 { 116 displayURL("http://www.javaworld.com"); 117 } 118 private static final String WIN_ID = "Windows"; 120 private static final String WIN_PATH = "rundll32"; 122 private static final String WIN_FLAG = "url.dll,FileProtocolHandler"; 124 private static final String UNIX_PATH = "netscape"; 126 private static final String UNIX_FLAG = "-remote openURL"; 128 } 129 | Popular Tags |