1 11 package org.eclipse.help.internal.browser; 12 13 import java.io.*; 14 import java.util.Hashtable ; 15 import java.util.Locale ; 16 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.help.browser.*; 19 import org.eclipse.help.internal.base.*; 20 public class MozillaFactory implements IBrowserFactory, IExecutableExtension { 21 private String executable; 22 private String executableName; 23 private String osList; 24 private MozillaBrowserAdapter browserInstance = null; 25 28 public MozillaFactory() { 29 super(); 30 } 31 34 public boolean isAvailable() { 35 if (!isSupportedOS(System.getProperty("os.name"))) { return false; 37 } 38 try { 39 Process pr = Runtime.getRuntime().exec("which " + executable); StreamConsumer outputs = new StreamConsumer(pr.getInputStream()); 41 (outputs).start(); 42 StreamConsumer errors = new StreamConsumer(pr.getErrorStream()); 43 (errors).start(); 44 pr.waitFor(); 45 int ret = pr.exitValue(); 46 if (ret == 0) { 47 return !errorsInOutput(outputs, errors); 48 } 49 return false; 50 } catch (InterruptedException e) { 51 return false; 52 } catch (IOException e) { 53 return true; 55 } 56 } 57 66 private boolean errorsInOutput(StreamConsumer outputs, StreamConsumer errors) { 67 try { 68 outputs.join(1000); 69 if (outputs.getLastLine() != null 70 && outputs.getLastLine() 71 .indexOf("no " + executable + " in") >= 0) { 73 return true; 74 } 75 errors.join(1000); 76 if (errors.getLastLine() != null 77 && errors.getLastLine().indexOf("no " + executable + " in") >= 0) { 79 return true; 80 } 81 } catch (InterruptedException ie) { 82 } 84 return false; 85 } 86 89 public IBrowser createBrowser() { 90 if (browserInstance == null) { 92 browserInstance = new MozillaBrowserAdapter(executable, 93 executableName); 94 } 95 return browserInstance; 96 } 97 101 public void setInitializationData(IConfigurationElement config, 102 String propertyName, Object data) throws CoreException { 103 try { 104 Hashtable params = (Hashtable ) data; 105 executable = (String ) params.get("executable"); executableName = (String ) params.get("executableName"); osList = (String ) params.get("os"); } catch (Exception e) { 109 throw new CoreException(new Status(IStatus.ERROR, 110 HelpBasePlugin.PLUGIN_ID, IStatus.OK, HelpBaseResources.MozillaFactory_dataMissing, 111 e)); 112 } 113 } 114 private boolean isSupportedOS(String os) { 115 if (osList == null || osList.length() <= 0) { 116 return false; 118 } 119 String [] OSes = osList.split(",\\s*"); for (int i = 0; i < OSes.length; i++) { 121 if (os.toLowerCase(Locale.ENGLISH).startsWith(OSes[i].toLowerCase(Locale.ENGLISH))) { 122 return true; 123 } 124 } 125 return false; 126 } 127 } 128 | Popular Tags |