1 11 package org.eclipse.help.internal.index; 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.AbstractIndexProvider; 20 import org.eclipse.help.IIndexContribution; 21 import org.eclipse.help.internal.HelpPlugin; 22 23 26 public class IndexFileProvider extends AbstractIndexProvider { 27 28 public static final String EXTENSION_POINT_ID_INDEX = HelpPlugin.PLUGIN_ID + ".index"; public static final String ELEMENT_NAME_INDEX = "index"; public static final String ATTRIBUTE_NAME_FILE = "file"; 32 35 public IIndexContribution[] getIndexContributions(String locale) { 36 List contributions = new ArrayList (); 37 IndexFile[] indexFiles = getIndexFiles(locale); 38 IndexFileParser parser = new IndexFileParser(); 39 for (int i=0;i<indexFiles.length;++i) { 40 try { 41 IIndexContribution toc = parser.parse(indexFiles[i]); 42 contributions.add(toc); 43 } 44 catch (Throwable t) { 45 String msg = "Error reading help keyword index file /\"" + indexFiles[i].getPluginId() + '/' + indexFiles[i].getFile() + "\" (skipping file)"; HelpPlugin.logError(msg, t); 47 } 48 } 49 return (IIndexContribution[])contributions.toArray(new IIndexContribution[contributions.size()]); 50 } 51 52 55 private IndexFile[] getIndexFiles(String locale) { 56 List indexFiles = new ArrayList (); 57 IExtensionRegistry registry = Platform.getExtensionRegistry(); 58 IConfigurationElement[] elements = registry.getConfigurationElementsFor(EXTENSION_POINT_ID_INDEX); 59 for (int i=0;i<elements.length;++i) { 60 IConfigurationElement elem = elements[i]; 61 String pluginId = elem.getContributor().getName(); 62 if (elem.getName().equals(ELEMENT_NAME_INDEX)) { 63 String file = elem.getAttribute(ATTRIBUTE_NAME_FILE); 64 IndexFile indexFile = new IndexFile(pluginId, file, locale); 65 indexFiles.add(indexFile); 66 } 67 } 68 return (IndexFile[])indexFiles.toArray(new IndexFile[indexFiles.size()]); 69 } 70 } 71 | Popular Tags |