Revision: 3074 http://vexi.svn.sourceforge.net/vexi/?rev=3074&view=rev Author: clrg Date: 2008-08-11 23:58:12 +0000 (Mon, 11 Aug 2008)
Log Message: ----------- Fix browser launching on Linux (needs confirming on Win2k and Vista) Modified Paths: -------------- trunk/core/org.vexi.core/src/org/vexi/plat/JVM.java trunk/core/org.vexi.core/src/org/vexi/plat/Platform.java Modified: trunk/core/org.vexi.core/src/org/vexi/plat/JVM.java =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/plat/JVM.java 2008-08-11 23:33:16 UTC (rev 3073) +++ trunk/core/org.vexi.core/src/org/vexi/plat/JVM.java 2008-08-11 23:58:12 UTC (rev 3074) @@ -11,13 +11,5 @@ /** common superclass for all platforms that run in a "real" JVM */ public abstract class JVM extends Platform { - protected void _newBrowserWindow(String url) throws JSExn { - try { - org.ibex.util.EjAlbertBrowserLauncher.openURL(url); - return; - } catch (IOException e) { - Log.warn(Platform.class, e); - } - super._newBrowserWindow(url); - } + } Modified: trunk/core/org.vexi.core/src/org/vexi/plat/Platform.java =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/plat/Platform.java 2008-08-11 23:33:16 UTC (rev 3073) +++ trunk/core/org.vexi.core/src/org/vexi/plat/Platform.java 2008-08-11 23:58:12 UTC (rev 3074) @@ -9,6 +9,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.lang.reflect.Method; import org.ibex.js.JS; import org.ibex.js.JSExn; @@ -232,9 +233,29 @@ return platform._fileDialog(suggestedFileName, write); } - /** default implementation is Eric Albert's BrowserLauncher.java */ + /** default implementation is from http://www.centerkey.com/java/browser/ */ protected void _newBrowserWindow(String url) throws JSExn{ - throw new JSExn("browser launching not available"); + String osName = System.getProperty("os.name"); + try { + if (osName.startsWith("Mac OS")) { + Class fileMgr = Class.forName("com.apple.eio.FileManager"); + Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class}); + openURL.invoke(null, new Object[] {url}); + } else if (osName.startsWith("Windows")) { + Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); + } else { + //assume Unix or Linux + String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" }; + String browser = null; + for (int count = 0; count < browsers.length && browser == null; count++) + if (Runtime.getRuntime().exec( new String[] {"which", browsers[count]}).waitFor() == 0) + browser = browsers[count]; + if (browser == null) throw new Exception("Could not find web browser"); + else Runtime.getRuntime().exec(new String[] {browser, url}); + } + } catch (Exception e) { + throw new JSExn("Error opening browser:\n" + e.getLocalizedMessage()); + } } /** opens a new browser window */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn