KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > extbrowser > FirefoxBrowser


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.extbrowser;
21
22 import org.openide.awt.HtmlBrowser;
23 import org.openide.execution.NbProcessDescriptor;
24 import org.openide.util.NbBundle;
25 import org.openide.util.Utilities;
26
27 /**
28  * @author Martin Grebac
29  */

30 public class FirefoxBrowser extends ExtWebBrowser {
31
32 // /** storage for starting browser timeout property */
33
// protected int browserStartTimeout = 6000;
34

35     private static final long serialVersionUID = -3982770681461437966L;
36
37     /** Creates new ExtWebBrowser */
38     public FirefoxBrowser() {
39         ddeServer = ExtWebBrowser.FIREFOX;
40         //browserStartTimeout = 6000;
41
}
42
43     /** Determines whether the browser should be visible or not
44      * @return true when OS is Windows.
45      * false in all other cases.
46      */

47     public static Boolean JavaDoc isHidden () {
48         String JavaDoc detectedPath = null;
49         if (Utilities.isWindows()) {
50             try {
51                 detectedPath = NbDdeBrowserImpl.getBrowserPath(ExtWebBrowser.FIREFOX); // NOI18N
52
} catch (NbBrowserException e) {
53                 ExtWebBrowser.getEM().log("Cannot detect Firefox : " + e); // NOI18N
54
}
55             if ((detectedPath != null) && (detectedPath.trim().length() > 0)) {
56                 return Boolean.FALSE;
57             }
58             return Boolean.TRUE;
59         }
60         return (Utilities.isUnix() && !Utilities.isMac()) ? Boolean.FALSE : Boolean.TRUE;
61     }
62     
63     /** Getter for browser name
64      * @return name of browser
65      */

66     public String JavaDoc getName () {
67         if (name == null) {
68             this.name = NbBundle.getMessage(FirefoxBrowser.class, "CTL_FirefoxBrowserName");
69         }
70         return name;
71     }
72     
73     /**
74      * Returns a new instance of BrowserImpl implementation.
75      * @throws UnsupportedOperationException when method is called and OS is not Windows.
76      * @return browserImpl implementation of browser.
77      */

78     public HtmlBrowser.Impl createHtmlBrowserImpl() {
79         ExtBrowserImpl impl = null;
80
81         if (Utilities.isWindows()) {
82             impl = new NbDdeBrowserImpl(this);
83         } else if (Utilities.isUnix() && !Utilities.isMac()) {
84             impl = new UnixBrowserImpl(this);
85         } else {
86             throw new UnsupportedOperationException JavaDoc (NbBundle.getMessage(FirefoxBrowser.class, "MSG_CannotUseBrowser"));
87         }
88         
89         return impl;
90     }
91     
92     /** Default command for browser execution.
93      * Can be overriden to return browser that suits to platform and settings.
94      *
95      * @return process descriptor that allows to start browser.
96      */

97     protected NbProcessDescriptor defaultBrowserExecutable () {
98
99         String JavaDoc prg;
100         String JavaDoc params = ""; // NOI18N
101
NbProcessDescriptor retValue;
102         
103         //Windows
104
if (Utilities.isWindows()) {
105             params += "{" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "}";
106             try {
107                 prg = NbDdeBrowserImpl.getBrowserPath(getDDEServer());
108                 return new NbProcessDescriptor (prg, params);
109             } catch (NbBrowserException e) {
110                     prg = "C:\\Program Files\\Mozilla Firefox\\firefox.exe"; // NOI18N
111
} catch (UnsatisfiedLinkError JavaDoc e) {
112                 prg = "firefox.exe"; // NOI18N
113
}
114
115             retValue = new NbProcessDescriptor (prg, params);
116             return retValue;
117         
118         //Unix
119
} else {
120             
121             prg = "firefox"; // NOI18N
122
if (Utilities.getOperatingSystem() == Utilities.OS_LINUX) {
123                 java.io.File JavaDoc f = new java.io.File JavaDoc ("/usr/bin/firefox"); // NOI18N
124
if (f.exists()) {
125                     prg = f.getAbsolutePath();
126                 }
127                 f = new java.io.File JavaDoc ("/usr/bin/mozilla-firefox"); // NOI18N
128
if (f.exists()) {
129                     prg = f.getAbsolutePath();
130                 }
131                 f = new java.io.File JavaDoc ("/usr/local/firefox/firefox"); // NOI18N
132
if (f.exists()) {
133                     prg = f.getAbsolutePath();
134                 }
135             } else if (Utilities.getOperatingSystem() == Utilities.OS_SOLARIS) {
136                 java.io.File JavaDoc f = new java.io.File JavaDoc ("/usr/sfw/lib/firefox/firefox"); // NOI18N
137
if (f.exists()) {
138                     prg = f.getAbsolutePath();
139                 } else {
140                     f = new java.io.File JavaDoc ("/opt/csw/bin/firefox"); // NOI18N
141
if (f.exists()) {
142                         prg = f.getAbsolutePath();
143                     }
144                 }
145             }
146             
147             retValue = new NbProcessDescriptor(
148                 prg,
149                 "-remote \"openURL({" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "})\"", // NOI18N
150
NbBundle.getMessage(FirefoxBrowser.class, "MSG_BrowserExecutorHint")
151             );
152         }
153         return retValue;
154     }
155
156 }
157
Popular Tags