001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)Browser.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package jbidemo;
030:
031: import java.net.URL;
032:
033: /**
034: *
035: * @author Sun Microsystems, Inc.
036: */
037: public class Browser {
038: private String mBrowserPath;
039:
040: /**
041: * Creates a new instance of Browser
042: */
043: public Browser() {
044: }
045:
046: public void setBrowserPath(String browserPath) {
047: if (browserPath != null && browserPath.trim().length() > 0) {
048: this .mBrowserPath = browserPath.trim();
049: } else {
050: this .mBrowserPath = "mozilla";
051: }
052: }
053:
054: public String getBrowserPath() {
055: return this .mBrowserPath;
056: }
057:
058: public void launchBrowserUnix(URL target) {
059: try {
060: Runtime.getRuntime().exec(
061: getBrowserPath() + " " + target.toString());
062: } catch (Exception ex) {
063: ex.printStackTrace();
064: }
065: }
066:
067: public void launchBrowserWin32(URL target) {
068: try {
069: Runtime.getRuntime().exec(
070: "rundll32 url.dll,FileProtocolHandler "
071: + target.toString());
072: } catch (Exception ex) {
073: ex.printStackTrace();
074: }
075: }
076:
077: public void launchBrowser(URL target) {
078: System.out.println("OS " + System.getProperty("os.name"));
079: String osName = System.getProperty("os.name");
080:
081: if (osName.startsWith("Windows")) {
082: launchBrowserWin32(target);
083: } else {
084: launchBrowserUnix(target);
085: }
086: }
087:
088: public final static void main(String[] args) {
089: String urlStr = "";
090: String browserPath = "mozilla";
091:
092: if (args.length <= 0) {
093: System.out.println("No Url is specified");
094: } else {
095: urlStr = args[0];
096: if (urlStr == null) {
097: urlStr = "";
098: }
099:
100: if (args.length > 1) {
101: browserPath = args[1];
102: }
103: }
104: try {
105: Browser browser = new Browser();
106: browser.setBrowserPath(browserPath);
107: URL url = new URL(urlStr);
108: browser.launchBrowser(url);
109: } catch (Exception ex) {
110: // ex.printStackTrace();
111: System.out
112: .println("Can not Open Browser" + ex.getMessage());
113: }
114: }
115: }
|