diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/resources/Messages.properties | 3 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java | 17 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/services/XBasicService.java | 84 |
5 files changed, 110 insertions, 9 deletions
@@ -1,3 +1,17 @@ +2011-03-24 Omair Majid <[email protected]> + + * netx/net/sourceforge/jnlp/resources/Messages.properties: Add + RBrowserLocationPromptTitle, RBrowserLocationPromptMessage and + RBrowserLocationPromptMessageWithReason. + * netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java + (isWindows): New method. Moved from XBasicService. + (isUnix): New method. + * netx/net/sourceforge/jnlp/services/XBasicService + (initialize): Call initializeBrowserCommand. + (initializeBrowserCommand): New method. + (posixCommandExists): New method. + (isWindows): Moved to JNLPRuntime. + 2011-03-23 Denis Lila <[email protected]> * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java @@ -22,6 +22,7 @@ New in release 1.1 (2011-XX-XX): - RH677772: NoSuchAlgorithmException using SSL/TLS in javaws * NetX - Use Firefox's proxy settings if possible + - The user's default browser (determined from xdg-open or $BROWSER) is used - RH669942: javaws fails to download version/packed files (missing support for jnlp.packEnabled and jnlp.versionEnabled) - PR658: now jnlp.packEnabled works with applets. * Plugin diff --git a/netx/net/sourceforge/jnlp/resources/Messages.properties b/netx/net/sourceforge/jnlp/resources/Messages.properties index 55717b3..1f95723 100644 --- a/netx/net/sourceforge/jnlp/resources/Messages.properties +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties @@ -154,6 +154,9 @@ RConfigurationFatal=ERROR: a fatal error has occurred while loading configuratio RPRoxyPacNotSupported=Using Proxy Auto Config (PAC) files is not supported.
RProxyFirefoxNotFound=Unable to use Firefox's proxy settings. Using "DIRECT" as proxy type.
RProxyFirefoxOptionNotImplemented=Browser proxy option "{0}" ({1}) not supported yet.
+RBrowserLocationPromptTitle=Browser Location
+RBrowserLocationPromptMessage=Specify Browser Location
+RBrowserLocationPromptMessageWithReason=Specify Browser Location (the browser command "{0}" is invalid).
# Boot options, message should be shorter than this ---------------->
BOUsage=javaws [-run-options] <jnlp file>
diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java index 98bb6f5..f48d3ad 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java @@ -620,6 +620,23 @@ public class JNLPRuntime { } } + /** + * @return true if running on Windows + */ + public static boolean isWindows() { + String os = System.getProperty("os.name"); + return (os != null && os.startsWith("Windows")); + } + + /** + * @return true if running on a Unix or Unix-like system (including Linux + * and *BSD) + */ + public static boolean isUnix() { + String sep = System.getProperty("file.separator"); + return (sep != null && sep.equals("/")); + } + public static void setInitialArgments(List<String> args) { checkInitialized(); SecurityManager securityManager = System.getSecurityManager(); diff --git a/netx/net/sourceforge/jnlp/services/XBasicService.java b/netx/net/sourceforge/jnlp/services/XBasicService.java index 761e95d..d8c1388 100644 --- a/netx/net/sourceforge/jnlp/services/XBasicService.java +++ b/netx/net/sourceforge/jnlp/services/XBasicService.java @@ -16,6 +16,8 @@ package net.sourceforge.jnlp.services; +import static net.sourceforge.jnlp.runtime.Translator.R; + import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -190,9 +192,47 @@ class XBasicService implements BasicService { if (initialized) return; initialized = true; + initializeBrowserCommand(); + if (JNLPRuntime.isDebug()) { + System.out.println("browser is " + command); + } + } - if (isWindows()) { + /** + * Initializes {@link #command} to launch a browser + */ + private void initializeBrowserCommand() { + if (JNLPRuntime.isWindows()) { command = "rundll32 url.dll,FileProtocolHandler "; + } else if (JNLPRuntime.isUnix()) { + DeploymentConfiguration config = JNLPRuntime.getConfiguration(); + command = config.getProperty(DeploymentConfiguration.KEY_BROWSER_PATH); + if (command != null) { + return; + } + + if (posixCommandExists("xdg-open")) { + command = "xdg-open"; + return; + } + + if (posixCommandExists(System.getenv("BROWSER"))) { + command = System.getenv("BROWSER"); + return; + } + + while (true) { + command = promptForCommand(command); + if (command != null && posixCommandExists(command)) { + config.setProperty(DeploymentConfiguration.KEY_BROWSER_PATH, command); + try { + config.save(); + } catch (IOException e) { + e.printStackTrace(); + } + break; + } + } } else { DeploymentConfiguration config = JNLPRuntime.getConfiguration(); command = config.getProperty(DeploymentConfiguration.KEY_BROWSER_PATH); @@ -212,18 +252,44 @@ class XBasicService implements BasicService { } } - private boolean isWindows() { - String os = System.getProperty("os.name"); - if (os != null && os.startsWith("Windows")) - return true; - else + /** + * Check that a command exists on a posix-like system + * @param command the command to check + * @return true if the command exists + */ + private boolean posixCommandExists(String command) { + if (command == null || command.trim().length() == 0) { + return false; + } + + command = command.trim(); + if (command.contains("\n") || command.contains("\r")) { return false; + } + + try { + Process p = Runtime.getRuntime().exec(new String[] { "bash", "-c", "type " + command }); + p.waitFor(); + return (p.exitValue() == 0); + } catch (IOException e) { + e.printStackTrace(); + return false; + } catch (InterruptedException e) { + e.printStackTrace(); + return false; + } } - private String promptForCommand(String cmd) { + private String promptForCommand(String previousCommand) { + String message = null; + if (previousCommand == null) { + message = R("RBrowserLocationPromptMessage"); + } else { + message = R("RBrowserLocationPromptMessageWithReason", previousCommand); + } return JOptionPane.showInputDialog(new JPanel(), - "Browser Location:", - "Specify Browser Location", + R("RBrowserLocationPromptTitle"), + message, JOptionPane.PLAIN_MESSAGE ); } |