提交 78aab0c0 authored 作者: Thomas Mueller's avatar Thomas Mueller

New system property h2.browser to set the browser to use.

To start the browser, java.awt.Desktop.browse is now used if available.
上级 e2b82f88
...@@ -18,7 +18,8 @@ Change Log ...@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>- <ul><li>New system property h2.browser to set the browser to use.
</li><li>To start the browser, java.awt.Desktop.browse is now used if available.
</li></ul> </li></ul>
<h2>Version 1.1.102 (2008-10-24)</h2> <h2>Version 1.1.102 (2008-10-24)</h2>
......
...@@ -104,6 +104,12 @@ public class SysProperties { ...@@ -104,6 +104,12 @@ public class SysProperties {
*/ */
public static final String ALLOWED_CLASSES = getStringSetting("h2.allowedClasses", "*"); public static final String ALLOWED_CLASSES = getStringSetting("h2.allowedClasses", "*");
/**
* System property <code>h2.browser</code> (default: null).<br />
* The preferred browser to use. If not set, the default browser is used.
*/
public static final String BROWSER = getStringSetting("h2.browser", null);
/** /**
* System property <code>h2.enableAnonymousSSL</code> (default: true).<br /> * System property <code>h2.enableAnonymousSSL</code> (default: true).<br />
* When using SSL connection, the anonymous cipher suite * When using SSL connection, the anonymous cipher suite
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.util; package org.h2.util;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
...@@ -28,6 +29,36 @@ public class StartBrowser { ...@@ -28,6 +29,36 @@ public class StartBrowser {
String osName = SysProperties.getStringSetting("os.name", "linux").toLowerCase(); String osName = SysProperties.getStringSetting("os.name", "linux").toLowerCase();
Runtime rt = Runtime.getRuntime(); Runtime rt = Runtime.getRuntime();
try { try {
String browser = SysProperties.BROWSER;
if (browser != null) {
if (osName.indexOf("windows") >= 0) {
rt.exec(new String[] { "cmd.exe", "/C", browser, url });
} else {
rt.exec(new String[] { browser, url });
}
return;
}
try {
Class desktopClass = Class.forName("java.awt.Desktop");
// Desktop.isDesktopSupported()
Boolean supported = (Boolean) desktopClass.
getMethod("isDesktopSupported", new Class[0]).
invoke(null, new Object[0]);
URI uri = new URI(url);
if (supported.booleanValue()) {
// Desktop.getDesktop();
Object desktop = desktopClass.getMethod("getDesktop", new Class[0]).
invoke(null, new Object[0]);
// desktop.browse(uri);
desktopClass.getMethod("browse", new Class[] { URI.class }).
invoke(desktop, new Object[] { uri });
return;
}
} catch (Exception e) {
// ignore
}
if (osName.indexOf("windows") >= 0) { if (osName.indexOf("windows") >= 0) {
rt.exec(new String[] { "rundll32", "url.dll,FileProtocolHandler", url }); rt.exec(new String[] { "rundll32", "url.dll,FileProtocolHandler", url });
} else if (osName.indexOf("mac") >= 0) { } else if (osName.indexOf("mac") >= 0) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论