01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.util;
07:
08: import java.io.IOException;
09:
10: import org.h2.constant.SysProperties;
11:
12: /**
13: * This tool starts the browser with a specific URL.
14: */
15: public class StartBrowser {
16:
17: public static void openURL(String url) {
18: String osName = SysProperties.getStringSetting("os.name",
19: "linux").toLowerCase();
20: Runtime rt = Runtime.getRuntime();
21: try {
22: if (osName.indexOf("windows") >= 0) {
23: rt.exec(new String[] { "rundll32",
24: "url.dll,FileProtocolHandler", url });
25: } else if (osName.indexOf("mac") >= 0) {
26: Runtime.getRuntime().exec(new String[] { "open", url });
27: } else {
28: String[] browsers = { "firefox", "mozilla-firefox",
29: "mozilla", "konqueror", "netscape", "opera" };
30: boolean ok = false;
31: for (int i = 0; i < browsers.length; i++) {
32: try {
33: rt.exec(new String[] { browsers[i], url });
34: ok = true;
35: break;
36: } catch (Exception e) {
37: // ignore and try the next
38: }
39: }
40: if (!ok) {
41: // No success in detection.
42: System.out
43: .println("Please open a browser and go to "
44: + url);
45: }
46: }
47: } catch (IOException e) {
48: System.out
49: .println("Failed to start a browser to open the URL "
50: + url);
51: e.printStackTrace();
52: }
53: }
54:
55: }
|