1 11 package org.eclipse.help.internal.extension; 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.Platform; 19 import org.eclipse.help.AbstractContentExtensionProvider; 20 import org.eclipse.help.IContentExtension; 21 import org.eclipse.help.internal.HelpPlugin; 22 import org.osgi.framework.Bundle; 23 24 28 public class ContentExtensionFileProvider extends AbstractContentExtensionProvider { 29 30 private static final String EXTENSION_POINT_CONTENT_EXTENSION = HelpPlugin.PLUGIN_ID + ".contentExtension"; private static final String ELEMENT_CONTENT_EXTENSION = "contentExtension"; private static final String ATTRIBUTE_FILE = "file"; private static final String ATTRIBUTE_CONTENT = "content"; 35 38 public IContentExtension[] getContentExtensions(String locale) { 39 List extensions = new ArrayList (); 40 IExtensionRegistry registry = Platform.getExtensionRegistry(); 41 ContentExtensionFileParser parser = new ContentExtensionFileParser(); 42 IConfigurationElement[] elements = registry.getConfigurationElementsFor(EXTENSION_POINT_CONTENT_EXTENSION); 43 for (int i=0;i<elements.length;++i) { 44 if (ELEMENT_CONTENT_EXTENSION.equals(elements[i].getName())) { 45 String file = elements[i].getAttribute(ATTRIBUTE_FILE); 46 String bundleId = elements[i].getContributor().getName(); 47 Bundle bundle = Platform.getBundle(bundleId); 48 try { 49 ContentExtension[] ext = parser.parse(bundle, file); 50 for (int j=0;j<ext.length;++j) { 51 String content = ext[j].getAttribute(ATTRIBUTE_CONTENT); 52 if (content != null) { 53 ext[j].setAttribute(ATTRIBUTE_CONTENT, '/' + bundleId + '/' + content); 54 } 55 extensions.add(ext[j]); 56 } 57 } 58 catch (Throwable t) { 59 String msg = "Error reading user assistance content extension file /\"" + bundleId + '/' + file + "\" (skipping file)"; HelpPlugin.logError(msg, t); 61 } 62 } 63 } 64 return (IContentExtension[])extensions.toArray(new IContentExtension[extensions.size()]); 65 } 66 } 67 | Popular Tags |