1 19 20 package org.netbeans.modules.extbrowser; 21 22 import java.beans.*; 23 import org.openide.ErrorManager; 24 25 import org.openide.execution.NbProcessDescriptor; 26 import org.openide.util.NbBundle; 27 import org.openide.awt.HtmlBrowser; 28 import org.openide.util.Utilities; 29 30 32 33 public class ExtWebBrowser implements HtmlBrowser.Factory, java.io.Serializable , PropertyChangeListener { 34 35 private static final long serialVersionUID = -3021027901671504127L; 36 37 public static final String PROP_NAME = "name"; 39 40 public static final String PROP_BROWSER_EXECUTABLE = "browserExecutable"; 42 43 public static final String PROP_DDESERVER = "dDEServer"; 45 48 49 public static final String PROP_DDE_ACTIVATE_TIMEOUT = "activateTimeout"; 51 52 public static final String PROP_DDE_OPENURL_TIMEOUT = "openurlTimeout"; 54 55 public static final String NETSCAPE = "NETSCAPE"; 57 public static final String IEXPLORE = "IEXPLORE"; 59 public static final String MOZILLA = "MOZILLA"; 61 public static final String FIREFOX = "FIREFOX"; 63 public static final String NETSCAPE6 = "NETSCAPE6"; 65 68 69 protected static final int DEFAULT_ACTIVATE_TIMEOUT = 2000; 70 71 72 protected static final int DEFAULT_OPENURL_TIMEOUT = 3000; 73 74 75 protected String ddeServer; 76 77 78 protected int activateTimeout = DEFAULT_ACTIVATE_TIMEOUT; 79 80 83 84 protected int openurlTimeout = DEFAULT_OPENURL_TIMEOUT; 85 86 87 private static ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.extbrowser"); 89 protected String name; 90 91 public static ErrorManager getEM () { 92 return err; 93 } 94 95 96 protected NbProcessDescriptor browserExecutable; 97 98 protected transient PropertyChangeSupport pcs; 99 100 101 public ExtWebBrowser () { 102 init(); 103 } 104 105 106 private void init () { 107 if (err.isLoggable(ErrorManager.INFORMATIONAL)) { 108 err.log(ErrorManager.INFORMATIONAL, getClass().getName() + " " + System.currentTimeMillis() + "> init"); 109 } 110 pcs = new PropertyChangeSupport(this); 111 if (Utilities.isWindows()) { 112 pcs.addPropertyChangeListener(this); 113 } 114 } 115 116 121 public String getDDEServer () { 122 return ddeServer; 123 } 124 125 129 public void setDDEServer (String ddeServer) { 130 if ((ddeServer != null) && !ddeServer.equals(this.ddeServer)) { 131 String old = this.ddeServer; 132 this.ddeServer = ddeServer; 133 pcs.firePropertyChange (PROP_DDESERVER, old, ddeServer); 134 getEM().log("DDEServer changed to: " + ddeServer); } 136 } 137 138 158 162 public int getOpenurlTimeout() { 163 return openurlTimeout; 164 } 165 166 170 public void setOpenurlTimeout(int openurlTimeout) { 171 if (openurlTimeout != this.openurlTimeout) { 172 int oldVal = this.openurlTimeout; 173 this.openurlTimeout = openurlTimeout; 174 pcs.firePropertyChange(PROP_DDE_OPENURL_TIMEOUT, oldVal, openurlTimeout); 175 } 176 } 177 178 182 public int getActivateTimeout() { 183 return activateTimeout; 184 } 185 186 190 public void setActivateTimeout(int activateTimeout) { 191 if (activateTimeout != this.activateTimeout) { 192 int oldVal = this.activateTimeout; 193 this.activateTimeout = activateTimeout; 194 pcs.firePropertyChange(PROP_DDE_ACTIVATE_TIMEOUT, oldVal, activateTimeout); 195 } 196 } 197 198 public String getName() { 200 return name; 201 } 202 203 205 public void setName(String name) { 206 if ((name != null) && (!name.equals(this.name))) { 207 String oldVal = this.name; 208 this.name = name; 209 pcs.firePropertyChange(PROP_NAME, oldVal, name); 210 } 211 } 212 213 216 public NbProcessDescriptor getBrowserExecutable () { 217 if (browserExecutable == null || "".equals(browserExecutable.getProcessName())) { return defaultBrowserExecutable(); 219 } 220 return browserExecutable; 221 } 222 223 226 public void setBrowserExecutable (NbProcessDescriptor browserExecutable) { 227 if ((browserExecutable != null) && (!browserExecutable.equals(this.browserExecutable))) { 228 NbProcessDescriptor oldVal = this.browserExecutable; 229 this.browserExecutable = browserExecutable; 230 pcs.firePropertyChange(PROP_BROWSER_EXECUTABLE, oldVal, browserExecutable); 231 } 232 if (browserExecutable == null) { 233 NbProcessDescriptor oldVal = this.browserExecutable; 234 this.browserExecutable = defaultBrowserExecutable(); 235 pcs.firePropertyChange(PROP_BROWSER_EXECUTABLE, oldVal, browserExecutable); 236 } 237 } 238 239 240 public void propertyChange(PropertyChangeEvent evt) { 241 if (evt.getPropertyName().equals(ExtWebBrowser.PROP_BROWSER_EXECUTABLE)) { 242 Object np = evt.getNewValue(); 243 if ((np != null) && (np instanceof NbProcessDescriptor)) { 244 String processName = ((NbProcessDescriptor)np).getProcessName(); 245 if (err.isLoggable(ErrorManager.INFORMATIONAL)) { 246 err.log(ErrorManager.INFORMATIONAL, "" + System.currentTimeMillis() + "> propertychange: " + processName); 247 } 248 if ((processName != null) && (processName.trim().length() > 0)) { 249 if (processName.toUpperCase().indexOf("IEXPLORE.EXE") > -1) { setDDEServer(IEXPLORE); 251 } else if (processName.toUpperCase().indexOf("MOZILLA.EXE") > -1) { setDDEServer(MOZILLA); 253 } else if (processName.toUpperCase().indexOf("FIREFOX.EXE") > -1) { setDDEServer(FIREFOX); 255 } else if (processName.toUpperCase().indexOf("NETSCP6.EXE") > -1) { setDDEServer(NETSCAPE6); 257 } else if (processName.toUpperCase().indexOf("NETSCP.EXE") > -1) { setDDEServer(NETSCAPE6); 259 } else if (processName.toUpperCase().indexOf("NETSCAPE.EXE") > -1) { setDDEServer(NETSCAPE); 261 } else { 262 setDDEServer(null); 263 } 264 } 265 } 266 } 267 } 268 269 274 protected NbProcessDescriptor defaultBrowserExecutable () { 275 String b = "netscape"; if (err.isLoggable(ErrorManager.INFORMATIONAL)) { 277 err.log(ErrorManager.INFORMATIONAL, "" + System.currentTimeMillis() + "> ExtBrowser: defaultBrowserExecutable: "); 278 } 279 if (Utilities.isWindows()) { 280 b = "iexplore"; String params = ""; try { 283 b = NbDdeBrowserImpl.getDefaultOpenCommand (); 286 String [] args = Utilities.parseParameters(b); 287 288 if (args == null || args.length == 0) { 289 throw new NbBrowserException (); 290 } 291 b = args[0]; 292 if (args[0].toUpperCase().indexOf("IEXPLORE.EXE") > -1) { setDDEServer(IEXPLORE); 294 params = "-nohome "; } else if (args[0].toUpperCase().indexOf("MOZILLA.EXE") > -1) { setDDEServer(MOZILLA); 297 } else if (args[0].toUpperCase().indexOf("FIREFOX.EXE") > -1) { setDDEServer(FIREFOX); 299 } else if (args[0].toUpperCase().indexOf("NETSCP6.EXE") > -1) { setDDEServer(NETSCAPE6); 301 } else if (args[0].toUpperCase().indexOf("NETSCP.EXE") > -1) { setDDEServer(NETSCAPE6); 303 } else if (args[0].toUpperCase().indexOf("NETSCAPE.EXE") > -1) { setDDEServer(NETSCAPE); 305 } 306 params += "{" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "}"; 307 return new NbProcessDescriptor(b, params); 308 309 } catch (NbBrowserException e) { 310 try { 311 b = NbDdeBrowserImpl.getBrowserPath("IEXPLORE"); if ((b != null) && (b.trim().length() > 0)) { 313 setDDEServer(IEXPLORE); 314 params += "{" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "}"; 315 return new NbProcessDescriptor(b, params); 316 } 317 318 b = NbDdeBrowserImpl.getBrowserPath("MOZILLA"); if ((b != null) && (b.trim().length() > 0)) { 320 setDDEServer(MOZILLA); 321 params += "{" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "}"; 322 return new NbProcessDescriptor(b, params); 323 } 324 325 b = NbDdeBrowserImpl.getBrowserPath("FIREFOX"); if ((b != null) && (b.trim().length() > 0)) { 327 setDDEServer(FIREFOX); 328 params += "{" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "}"; 329 return new NbProcessDescriptor(b, params); 330 } 331 332 b = NbDdeBrowserImpl.getBrowserPath("Netscp"); if ((b != null) && (b.trim().length() > 0)) { 334 setDDEServer(NETSCAPE6); 335 params += "{" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "}"; 336 return new NbProcessDescriptor(b, params); 337 } 338 339 b = NbDdeBrowserImpl.getBrowserPath("Netscp6"); if ((b != null) && (b.trim().length() > 0)) { 341 setDDEServer(NETSCAPE6); 342 params += "{" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "}"; 343 return new NbProcessDescriptor(b, params); 344 } 345 346 b = NbDdeBrowserImpl.getBrowserPath("Netscape"); if ((b != null) && (b.trim().length() > 0)) { 348 setDDEServer(NETSCAPE); 349 params += "{" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "}"; 350 return new NbProcessDescriptor(b, params); 351 } 352 353 } catch (NbBrowserException e2) { 354 setDDEServer(IEXPLORE); 355 b = "C:\\Program Files\\Internet Explorer\\iexplore.exe"; } 357 } catch (UnsatisfiedLinkError e) { 358 b = "iexplore"; } 361 params += "{" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "}"; 362 return new NbProcessDescriptor (b, params); 363 364 } else if (Utilities.isUnix() && !Utilities.isMac()) { 366 367 if (Utilities.getOperatingSystem() == Utilities.OS_LINUX) { 369 b = "mozilla"; java.io.File f = new java.io.File ("/usr/local/mozilla/mozilla"); if (f.exists()) { 372 b = f.getAbsolutePath(); 373 } else { 374 f = new java.io.File ("/usr/bin/firefox"); if (f.exists()) { 376 b = f.getAbsolutePath(); 377 } 378 } 379 } else if (Utilities.getOperatingSystem() == Utilities.OS_SOLARIS) { 381 b = "netscape"; java.io.File f = new java.io.File ("/usr/dt/bin/sun_netscape"); if (f.exists()) { 384 b = f.getAbsolutePath(); 385 } 386 } 387 388 return new NbProcessDescriptor( b, 389 "-remote \"openURL({" + ExtWebBrowser.UnixBrowserFormat.TAG_URL + "})\"", NbBundle.getMessage(ExtWebBrowser.class, "MSG_BrowserExecutorHint") 391 ); 392 393 } else if (Utilities.getOperatingSystem () == Utilities.OS_OS2) { 395 return new NbProcessDescriptor( 396 "Netscape.exe", " {" + UnixBrowserFormat.TAG_URL + "}", NbBundle.getBundle(ExtWebBrowser.class).getString("MSG_BrowserExecutorHint") 400 ); 401 402 } else if (Utilities.isMac()) { 404 return new NbProcessDescriptor( 405 "/usr/bin/open", " {" + UnixBrowserFormat.TAG_URL + "}", NbBundle.getBundle(ExtWebBrowser.class).getString("MSG_BrowserExecutorHint") 409 ); 410 411 } else { 413 return new NbProcessDescriptor( 414 "", " {" + UnixBrowserFormat.TAG_URL + "}", NbBundle.getBundle(ExtWebBrowser.class).getString("MSG_BrowserExecutorHint") 419 ); 420 } 421 } 422 423 426 public HtmlBrowser.Impl createHtmlBrowserImpl() { 427 return new DelegatingWebBrowserImpl(this); 428 } 429 430 432 public void addPropertyChangeListener (PropertyChangeListener l) { 433 if (pcs == null) { 434 pcs = new PropertyChangeSupport(this); 435 } 436 pcs.addPropertyChangeListener (l); 437 } 438 439 441 public void removePropertyChangeListener (PropertyChangeListener l) { 442 if (pcs != null) { 443 pcs.removePropertyChangeListener (l); 444 } 445 } 446 447 private void readObject (java.io.ObjectInputStream ois) 448 throws java.io.IOException , ClassNotFoundException { 449 ois.defaultReadObject (); 450 if (browserExecutable != null && browserExecutable.getArguments() != null) { 451 String args = browserExecutable.getArguments(); 453 int idx = args.indexOf("{params}"); if (idx >= 0) { 455 browserExecutable = new NbProcessDescriptor ( 456 browserExecutable.getProcessName(), 457 args.substring(0, idx)+"-remote \"openURL({URL})"+args.substring(idx+8), NbBundle.getMessage (ExtWebBrowser.class, "MSG_BrowserExecutorHint") 459 ); 460 } 461 } 462 init(); 463 } 464 465 468 public static class UnixBrowserFormat extends org.openide.util.MapFormat { 469 470 471 private static final long serialVersionUID = -699340388834127437L; 472 473 474 public static final String TAG_URL = "URL"; 476 479 public UnixBrowserFormat (String url) { 480 super(new java.util.HashMap ()); 481 java.util.Map map = getMap (); 482 map.put (TAG_URL, url); 483 } 484 } 485 486 } 487 | Popular Tags |