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