1 11 package org.eclipse.ui.internal.browser; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IExtensionRegistry; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.Platform; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.ui.plugin.AbstractUIPlugin; 22 import org.osgi.framework.BundleContext; 23 26 public class WebBrowserUIPlugin extends AbstractUIPlugin { 27 public static final String PLUGIN_ID = "org.eclipse.ui.browser"; 30 private static WebBrowserUIPlugin singleton; 32 33 private static List browsers; 35 36 39 public WebBrowserUIPlugin() { 40 super(); 41 singleton = this; 42 } 43 44 49 public static WebBrowserUIPlugin getInstance() { 50 return singleton; 51 } 52 53 58 public void stop(BundleContext context) throws Exception { 59 super.stop(context); 60 BrowserManager.safeDispose(); 61 } 62 63 71 public static IBrowserExt[] getBrowsers() { 72 if (browsers == null) 73 loadBrowsers(); 74 IBrowserExt[] c = new IBrowserExt[browsers.size()]; 75 browsers.toArray(c); 76 return c; 77 } 78 79 public static IBrowserExt findBrowsers(String executable) { 80 IBrowserExt[] browsers2 = getBrowsers(); 81 if (browsers2 == null || executable == null) 82 return null; 83 84 int ind1 = executable.lastIndexOf("/"); int ind2 = executable.lastIndexOf("\\"); if (ind2 > ind1) 87 ind1 = ind2; 88 executable = executable.substring(ind1 + 1); 89 90 String os = Platform.getOS(); 91 int size = browsers2.length; 92 for (int i = 0; i < size; i++) { 93 if (browsers2[i].getOS().toLowerCase().indexOf(os) != -1) { 94 if (browsers2[i].isAvailable()) { 95 String executable2 = browsers2[i].getExecutable(); 96 if (executable.startsWith(executable2)) 97 return browsers2[i]; 98 } 99 } 100 } 101 return null; 102 } 103 104 107 private static synchronized void loadBrowsers() { 108 if (browsers != null) 109 return; 110 Trace.trace(Trace.CONFIG, "->- Loading .browsers extension point ->-"); IExtensionRegistry registry = Platform.getExtensionRegistry(); 112 IConfigurationElement[] cf = registry.getConfigurationElementsFor(PLUGIN_ID, "browsers"); 114 int size = cf.length; 115 browsers = new ArrayList (size); 116 for (int i = 0; i < size; i++) { 117 try { 118 browsers.add(new BrowserExt(cf[i])); 119 Trace.trace(Trace.CONFIG, " Loaded browser: " + cf[i].getAttribute("id")); } catch (Throwable t) { 121 Trace.trace(Trace.SEVERE, " Could not load browser: " + cf[i].getAttribute("id"), t); } 123 } 124 Trace.trace(Trace.CONFIG, "-<- Done loading .browsers extension point -<-"); } 126 127 132 public static synchronized void logError(String message, Throwable ex) { 133 if (message == null) 134 message = ""; Status errorStatus = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, 136 message, ex); 137 WebBrowserUIPlugin.getInstance().getLog().log(errorStatus); 138 } 139 140 145 154 } | Popular Tags |