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.ui.browser.BrowserFactory; 18 import org.eclipse.ui.browser.IWebBrowser; 19 22 public class BrowserExt implements IBrowserExt { 23 private static final String ATTR_FACTORY_CLASS = "factoryclass"; 25 private IConfigurationElement element; 26 27 private BrowserFactory delegate; 28 29 32 public BrowserExt(IConfigurationElement element) { 33 super(); 34 this.element = element; 35 } 36 37 42 public String getId() { 43 return element.getAttribute("id"); } 45 46 public String getName() { 47 String label = element.getAttribute("name"); if (label == null) 49 return "n/a"; return label; 51 } 52 53 public String getParameters() { 54 return element.getAttribute("parameters"); } 56 57 public String getExecutable() { 58 return element.getAttribute("executable"); } 60 61 public String getOS() { 62 String os = element.getAttribute("os"); if (os == null) 64 os = ""; return os; 66 } 67 68 public String [] getDefaultLocations() { 69 List list = new ArrayList (); 70 IConfigurationElement[] children = element.getChildren("location"); if (children != null) { 72 int size = children.length; 73 for (int i = 0; i < size; i++) { 74 list.add(children[i].getValue()); 75 } 76 } 77 78 String [] s = new String [list.size()]; 79 list.toArray(s); 80 return s; 81 } 82 83 protected BrowserFactory getDelegate() { 84 if (delegate == null) { 85 if (element.getAttribute(ATTR_FACTORY_CLASS) == null 86 || element.getAttribute(ATTR_FACTORY_CLASS).length() == 0) 87 return null; 88 89 try { 90 delegate = (BrowserFactory) element 91 .createExecutableExtension(ATTR_FACTORY_CLASS); 92 } catch (Exception e) { 93 Trace 94 .trace( 95 Trace.SEVERE, 96 "Could not create delegate" + toString() + ": " + e.getMessage()); } 98 } 99 return delegate; 100 } 101 102 109 public boolean isAvailable() { 110 if (delegate == null && (element.getAttribute(ATTR_FACTORY_CLASS) == null 111 || element.getAttribute(ATTR_FACTORY_CLASS).length() == 0)) 112 return true; 113 114 try { 115 return getDelegate().isAvailable(); 116 } catch (Exception e) { 117 Trace 118 .trace( 119 Trace.SEVERE, 120 "Error calling delegate " + toString() + ": " + e.getMessage()); return false; 122 } 123 } 124 125 130 public IWebBrowser createBrowser(String id, String location, 131 String parameters) { 132 try { 133 return getDelegate().createBrowser(id, location, parameters); 134 } catch (Exception e) { 135 Trace 136 .trace( 137 Trace.SEVERE, 138 "Error calling delegate " + toString() + ": " + e.getMessage()); return null; 140 } 141 } 142 143 148 public String toString() { 149 String s = "BrowserExt: " + getId() + ", " + getName() + ", " + getOS() + ", " + getExecutable() + ", " + getParameters() + ", "; String [] locations = getDefaultLocations(); 152 if (locations != null) { 153 int size = locations.length; 154 for (int i = 0; i < size; i++) { 155 s += locations[i] + ";"; } 157 } 158 return s; 159 } 160 } 161 | Popular Tags |