KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.beans.PropertyChangeListener JavaDoc;
27 import org.openide.ErrorManager;
28
29 /*
30  * @author Martin Grebac
31  */

32 public class NetscapeBrowser extends ExtWebBrowser implements PropertyChangeListener JavaDoc {
33
34     private static final long serialVersionUID = -2097024098026706995L;
35
36     /** storage for starting browser timeout property */
37     //protected int browserStartTimeout = 6000;
38

39     /** Creates new ExtWebBrowser */
40     public NetscapeBrowser() {
41         init();
42     }
43     
44     public void init() {
45         //Windows - we don't care about executable changes, because there's no need to setup ddeserver on non-windows platform
46
if (Utilities.isWindows()) {
47             ddeServer = ExtWebBrowser.NETSCAPE6;
48             pcs.addPropertyChangeListener(this);
49             //browserStartTimeout = 6000;
50
}
51     }
52
53     /** Determines whether the browser should be visible or not
54      * @return true when OS is Windows.
55      * false in all other cases.
56      */

57     public static Boolean JavaDoc isHidden () {
58         String JavaDoc detectedPath = null;
59         if (Utilities.isWindows()) {
60             try {
61                 detectedPath = NbDdeBrowserImpl.getBrowserPath("NETSCP"); // NOI18N
62
} catch (NbBrowserException e) {
63                 ExtWebBrowser.getEM().log("Cannot detect Netscape 7 : " + e); // NOI18N
64
}
65             if ((detectedPath != null) && (detectedPath.trim().length() > 0)) {
66                 return Boolean.FALSE;
67             }
68
69             try {
70                 detectedPath = NbDdeBrowserImpl.getBrowserPath("NETSCP6"); // NOI18N
71
} catch (NbBrowserException e) {
72                 ExtWebBrowser.getEM().log("Cannot detect Netscape 6 : " + e); // NOI18N
73
}
74             if ((detectedPath != null) && (detectedPath.trim().length() > 0)) {
75                 return Boolean.FALSE;
76             }
77             
78             try {
79                 detectedPath = NbDdeBrowserImpl.getBrowserPath("NETSCAPE"); // NOI18N
80
} catch (NbBrowserException e) {
81                 ExtWebBrowser.getEM().log("Cannot detect Netscape 4 : " + e); // NOI18N
82
}
83             if ((detectedPath != null) && (detectedPath.trim().length() > 0)) {
84                 return Boolean.FALSE;
85             }
86             
87             return Boolean.TRUE;
88         }
89         
90         return (Utilities.isUnix() && !Utilities.isMac()) ? Boolean.FALSE : Boolean.TRUE;
91     }
92
93     /** Getter for browser name
94      * @return name of browser
95      */

96     public String JavaDoc getName () {
97         if (name == null) {
98             this.name = NbBundle.getMessage(NetscapeBrowser.class, "CTL_NetscapeBrowserName");
99         }
100         return name;
101     }
102
103     /**
104      * Returns a new instance of BrowserImpl implementation.
105      * @throws UnsupportedOperationException when method is called and OS is not Windows.
106      * @return browserImpl implementation of browser.
107      */

108     public HtmlBrowser.Impl createHtmlBrowserImpl() {
109         ExtBrowserImpl impl = null;
110
111         if (org.openide.util.Utilities.isWindows ()) {
112             impl = new NbDdeBrowserImpl (this);
113         } else if (Utilities.isUnix() && !Utilities.isMac()) {
114             impl = new UnixBrowserImpl(this);
115         } else {
116             throw new UnsupportedOperationException JavaDoc (NbBundle.getMessage (NetscapeBrowser.class, "MSG_CannotUseBrowser"));
117         }
118         
119         return impl;
120     }
121
122     /** Default command for browser execution.
123      * Can be overriden to return browser that suits to platform and settings.
124      *
125      * @return process descriptor that allows to start browser.
126      */

127     protected NbProcessDescriptor defaultBrowserExecutable() {
128         String JavaDoc b = "";
129         String JavaDoc params = ""; // NOI18N
130
NbProcessDescriptor retValue;
131         
132         //Windows
133
if (Utilities.isWindows()) {
134             params += "{" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "}";
135             try {
136                 try {
137                     b = NbDdeBrowserImpl.getBrowserPath("Netscp"); // NOI18N
138
if ((b != null) && (b.trim().length() > 0)) {
139                         setDDEServer(ExtWebBrowser.NETSCAPE6);
140                         return new NbProcessDescriptor(b, params);
141                     }
142                 } catch (NbBrowserException e) {
143                     if (ExtWebBrowser.getEM().isLoggable(ErrorManager.INFORMATIONAL)) {
144                         ExtWebBrowser.getEM().log("Cannot get Path for Netscape 7: " + e); // NOI18N
145
}
146                 }
147
148                 try {
149                     b = NbDdeBrowserImpl.getBrowserPath("Netscp6"); // NOI18N
150
if ((b != null) && (b.trim().length() > 0)) {
151                         setDDEServer(ExtWebBrowser.NETSCAPE6);
152                         return new NbProcessDescriptor(b, params);
153                     }
154                 } catch (NbBrowserException e) {
155                     if (ExtWebBrowser.getEM().isLoggable(ErrorManager.INFORMATIONAL)) {
156                         ExtWebBrowser.getEM().log("Cannot get Path for Netscape 6: " + e); // NOI18N
157
}
158                 }
159
160                 try {
161                     b = NbDdeBrowserImpl.getBrowserPath("Netscape"); // NOI18N
162
if ((b != null) && (b.trim().length() > 0)) {
163                         setDDEServer(ExtWebBrowser.NETSCAPE);
164                         return new NbProcessDescriptor(b, params);
165                     }
166                 } catch (NbBrowserException e) {
167                     if (ExtWebBrowser.getEM().isLoggable(ErrorManager.INFORMATIONAL)) {
168                         ExtWebBrowser.getEM().log("Cannot get Path for Netscape 4: " + e); // NOI18N
169
}
170                 }
171                 
172             } catch (UnsatisfiedLinkError JavaDoc e) {
173                 if (ExtWebBrowser.getEM().isLoggable(ErrorManager.INFORMATIONAL)) {
174                     ExtWebBrowser.getEM().log("Some problem here:" + e); // NOI18N
175
}
176             }
177
178             b = "C:\\PROGRA~1\\Netscape\\NETSCA~1\\netscp.exe"; // NOI18N
179
setDDEServer(ExtWebBrowser.NETSCAPE6);
180             
181             retValue = new NbProcessDescriptor (b, params);
182         
183         //Unix
184
} else {
185
186             b = "netscape"; // NOI18N
187
if (Utilities.getOperatingSystem() == Utilities.OS_SOLARIS) {
188                 java.io.File JavaDoc f = new java.io.File JavaDoc ("/usr/dt/bin/sun_netscape"); // NOI18N
189
if (f.exists()) {
190                     b = f.getAbsolutePath();
191                 }
192             }
193             retValue = new NbProcessDescriptor (
194                 b, "-remote \"openURL({" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "})\"", // NOI18N
195
NbBundle.getMessage (NetscapeBrowser.class, "MSG_BrowserExecutorHint")
196             );
197         }
198         
199         return retValue;
200     }
201
202 }
203
Popular Tags