1 11 package org.eclipse.update.internal.configurator; 12 13 import java.net.*; 14 import java.util.ArrayList ; 15 import java.util.MissingResourceException ; 16 import java.util.ResourceBundle ; 17 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.update.configurator.*; 20 import org.eclipse.update.internal.configurator.branding.*; 21 import org.osgi.framework.*; 22 import org.w3c.dom.*; 23 24 25 29 public class FeatureEntry 30 implements 31 IPlatformConfiguration.IFeatureEntry, 32 IConfigurationConstants, 33 IBundleGroup, 34 IBundleGroupConstants, 35 IProductConstants { 36 private String id; 37 private String version; 38 private String pluginVersion; 39 private String application; 40 private URL[] root; 41 private boolean primary; 42 private String pluginIdentifier; 43 private String url; 44 private String description; 45 private String licenseURL; 46 private ArrayList plugins; 47 private AboutInfo branding; 48 private SiteEntry site; 49 private ResourceBundle resourceBundle; 50 private boolean fullyParsed; 51 52 public FeatureEntry(String id, String version, String pluginIdentifier, String pluginVersion, boolean primary, String application, URL[] root) { 53 if (id == null) 54 throw new IllegalArgumentException (); 55 this.id = id; 56 this.version = version; 57 this.pluginVersion = pluginVersion; 58 this.pluginIdentifier = pluginIdentifier; 59 this.primary = primary; 60 this.application = application; 61 this.root = (root == null ? new URL[0] : root); 62 } 63 64 public FeatureEntry( String id, String version, String pluginVersion, boolean primary, String application, URL[] root) { 65 this(id, version, id, pluginVersion, primary, application, root); 66 } 67 68 public void setSite(SiteEntry site) { 69 this.site = site; 70 } 71 72 public SiteEntry getSite() { 73 return this.site; 74 } 75 76 public void addPlugin(PluginEntry plugin) { 77 if (plugins == null) 78 plugins = new ArrayList (); 79 plugins.add(plugin); 80 } 81 82 public PluginEntry[] getPluginEntries() { 83 if (plugins == null) 84 fullParse(); 85 return (PluginEntry[])plugins.toArray(new PluginEntry[plugins.size()]); 86 } 87 88 92 public void setURL(String url) { 93 this.url = url; 94 } 95 96 99 public String getURL() { 100 return url; 103 } 104 105 108 public String getFeatureIdentifier() { 109 return id; 110 } 111 112 115 public String getFeatureVersion() { 116 return version; 117 } 118 119 122 public String getFeaturePluginVersion() { 123 return pluginVersion != null && pluginVersion.length() > 0 ? pluginVersion : null; 124 } 125 126 129 public String getFeaturePluginIdentifier() { 130 return pluginIdentifier != null && pluginIdentifier.length() > 0 ? pluginIdentifier : id; 132 } 133 134 137 public String getFeatureApplication() { 138 return application; 139 } 140 141 144 public URL[] getFeatureRootURLs() { 145 return root; 146 } 147 148 151 public boolean canBePrimary() { 152 return primary; 153 } 154 155 public Element toXML(Document doc) { 156 URL installURL = Utils.getInstallURL(); 157 158 Element featureElement = doc.createElement(CFG_FEATURE_ENTRY); 159 if (id != null) 161 featureElement.setAttribute(CFG_FEATURE_ENTRY_ID, id); 162 if (primary) 163 featureElement.setAttribute(CFG_FEATURE_ENTRY_PRIMARY, "true"); if (version != null) 165 featureElement.setAttribute(CFG_FEATURE_ENTRY_VERSION, version); 166 if (pluginVersion != null && !pluginVersion.equals(version) && pluginVersion.length() > 0) 167 featureElement.setAttribute(CFG_FEATURE_ENTRY_PLUGIN_VERSION, pluginVersion); 168 if (pluginIdentifier != null && !pluginIdentifier.equals(id) && pluginIdentifier.length() > 0) 169 featureElement.setAttribute(CFG_FEATURE_ENTRY_PLUGIN_IDENTIFIER, pluginIdentifier); 170 if (application != null) 171 featureElement.setAttribute(CFG_FEATURE_ENTRY_APPLICATION, application); 172 if (url != null) 173 featureElement.setAttribute(CFG_URL, Utils.makeRelative(installURL, url)); 175 176 URL[] roots = getFeatureRootURLs(); 177 for (int i=0; i<roots.length; i++) { 178 String root = Utils.makeRelative(installURL, roots[i]).toExternalForm(); 180 if (root.trim().length() > 0){ 181 Element rootElement = doc.createElement(CFG_FEATURE_ENTRY_ROOT); 182 rootElement.appendChild(doc.createTextNode(root)); 183 featureElement.appendChild(rootElement); 184 } 185 } 186 187 return featureElement; 188 } 189 190 public void setDescription(String description) { 191 this.description = description; 192 } 193 194 197 public Bundle [] getBundles() { 198 if (plugins == null) 199 fullParse(); 200 201 ArrayList bundles = new ArrayList (plugins.size()); 202 for (int i=0; i<plugins.size(); i++) { 203 PluginEntry plugin = (PluginEntry)plugins.get(i); 204 Bundle bundle = Utils.getBundle(plugin.getPluginIdentifier()); 206 if (bundle != null) 207 bundles.add(bundle); 208 } 209 return (Bundle [])bundles.toArray(new Bundle [bundles.size()]); 210 } 211 214 public String getDescription() { 215 if (description == null) 216 fullParse(); 217 return description; 218 } 219 222 public String getIdentifier() { 223 return id; 224 } 225 228 public String getName() { 229 if (branding == null) 230 branding = AboutInfo.readFeatureInfo(id, version, getFeaturePluginIdentifier()); 231 return branding.getProductName(); 232 } 233 236 public String getProperty(String key) { 237 if (key == null) 238 return null; 239 240 if (branding == null) 241 branding = AboutInfo.readFeatureInfo(id, version, getFeaturePluginIdentifier()); 242 243 if (key.equals(FEATURE_IMAGE)) 245 return branding.getFeatureImageURL() == null ? null : branding.getFeatureImageURL().toExternalForm(); 246 else if (key.equals(TIPS_AND_TRICKS_HREF)) 247 return branding.getTipsAndTricksHref(); 248 else if (key.equals(IBundleGroupConstants.WELCOME_PAGE)) return branding.getWelcomePageURL() == null ? null : branding.getWelcomePageURL().toExternalForm(); 250 else if (key.equals(WELCOME_PERSPECTIVE)) 251 return branding.getWelcomePerspectiveId(); 252 else if (key.equals(APP_NAME)) 254 return branding.getAppName(); 255 else if (key.equals(ABOUT_TEXT)) 256 return branding.getAboutText(); 257 else if (key.equals(ABOUT_IMAGE)) 258 return branding.getAboutImageURL() == null ? null : branding.getAboutImageURL().toExternalForm(); 259 else if (key.equals(WINDOW_IMAGE)) 260 return branding.getWindowImageURL()== null ? null : branding.getWindowImageURL().toExternalForm(); 261 else if (key.equals(WINDOW_IMAGES)) { 262 URL[] urls = branding.getWindowImagesURLs(); 263 if (urls == null) 264 return null; 265 StringBuffer windowImagesURLs = new StringBuffer (); 266 for (int i=0; i<urls.length; i++){ 267 windowImagesURLs.append(urls[i].toExternalForm()); 268 if (i != urls.length-1) 269 windowImagesURLs.append(','); 270 } 271 return windowImagesURLs.toString(); 272 } else if (key.equals(LICENSE_HREF)) 273 return getLicenseURL(); 274 275 return null; 276 } 277 280 public String getProviderName() { 281 if (branding == null) 282 branding = AboutInfo.readFeatureInfo(id, version, getFeaturePluginIdentifier()); 283 return branding.getProviderName(); 284 } 285 288 public String getVersion() { 289 return version; 290 } 291 294 public String getApplication() { 295 return application; 296 } 297 300 public String getId() { 301 return id; 302 } 303 304 public ResourceBundle getResourceBundle(){ 305 if (resourceBundle != null) 306 return resourceBundle; 307 308 if (site == null) 310 return null; 311 312 ResourceBundle bundle = null; 313 try { 314 URL propertiesURL = new URL(site.getResolvedURL(), getURL()); 315 ClassLoader l = new URLClassLoader(new URL[] { propertiesURL }, null); 316 bundle = ResourceBundle.getBundle(IConfigurationConstants.CFG_FEATURE_ENTRY, Utils.getDefaultLocale(), l); 317 } catch (MissingResourceException e) { 318 Utils.log(e.getLocalizedMessage()); 319 } catch (MalformedURLException e) { 320 Utils.log(e.getLocalizedMessage()); 321 } 322 return bundle; 323 } 324 325 public void setLicenseURL(String licenseURL) { 326 this.licenseURL = licenseURL; 327 } 328 329 public String getLicenseURL() { 330 if (licenseURL == null) 331 fullParse(); 332 if (licenseURL == null) 333 return null; 334 335 String resolvedURL = Utils.getResourceString(getResourceBundle(), licenseURL); 336 if (resolvedURL.startsWith("http://")) return resolvedURL; 338 try { 339 return new URL(getSite().getResolvedURL(), getURL() + resolvedURL).toExternalForm(); 340 } catch (MalformedURLException e) { 341 return resolvedURL; 342 } 343 } 344 345 private void fullParse() { 346 if (fullyParsed) 347 return; 348 fullyParsed = true; 349 if (plugins == null) 350 plugins = new ArrayList (); 351 FullFeatureParser parser = new FullFeatureParser(this); 352 parser.parse(); 353 } 354 355 public Bundle getDefiningBundle() { 356 return Utils.getBundle(getFeaturePluginIdentifier()); 357 } 358 359 public boolean hasBranding() { 360 String bundleId = getFeaturePluginIdentifier(); 361 return bundleId != null && Utils.getBundle(bundleId) != null; 362 } 363 } 364 | Popular Tags |