1 11 package org.eclipse.help.internal.toc; 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.InvalidRegistryObjectException; 19 import org.eclipse.core.runtime.Platform; 20 import org.eclipse.help.AbstractTocProvider; 21 import org.eclipse.help.ITocContribution; 22 import org.eclipse.help.internal.HelpPlugin; 23 24 27 public class TocFileProvider extends AbstractTocProvider { 28 29 public static final String EXTENSION_POINT_ID_TOC = HelpPlugin.PLUGIN_ID + ".toc"; public static final String ELEMENT_NAME_TOC = "toc"; public static final String ATTRIBUTE_NAME_FILE = "file"; public static final String ATTRIBUTE_NAME_PRIMARY = "primary"; public static final String ATTRIBUTE_NAME_EXTRADIR = "extradir"; public static final String ATTRIBUTE_NAME_CATEGORY = "category"; 36 39 public ITocContribution[] getTocContributions(String locale) { 40 List contributions = new ArrayList (); 41 TocFile[] tocFiles = getTocFiles(locale); 42 TocFileParser parser = new TocFileParser(); 43 for (int i=0;i<tocFiles.length;++i) { 44 try { 45 ITocContribution toc = parser.parse(tocFiles[i]); 46 contributions.add(toc); 47 } 48 catch (Throwable t) { 49 String msg = "Error reading help table of contents file /\"" + tocFiles[i].getPluginId() + '/' + tocFiles[i].getFile() + "\" (skipping file)"; HelpPlugin.logError(msg, t); 51 } 52 } 53 return (ITocContribution[])contributions.toArray(new ITocContribution[contributions.size()]); 54 } 55 56 59 protected TocFile[] getTocFiles(String locale) { 60 List tocFiles = new ArrayList (); 61 IExtensionRegistry registry = Platform.getExtensionRegistry(); 62 IConfigurationElement[] elements = registry.getConfigurationElementsFor(EXTENSION_POINT_ID_TOC); 63 for (int i=0;i<elements.length;++i) { 64 IConfigurationElement elem = elements[i]; 65 String pluginId; 66 try { 67 pluginId = elem.getNamespaceIdentifier(); 68 } 69 catch (InvalidRegistryObjectException e) { 70 continue; 72 } 73 74 if (elem.getName().equals(ELEMENT_NAME_TOC)) { 75 String file = elem.getAttribute(ATTRIBUTE_NAME_FILE); 76 boolean primary = Boolean.toString(true).equals(elem.getAttribute(ATTRIBUTE_NAME_PRIMARY)); 77 String extradir = elem.getAttribute(ATTRIBUTE_NAME_EXTRADIR); 78 String category = elem.getAttribute(ATTRIBUTE_NAME_CATEGORY); 79 TocFile tocFile = new TocFile(pluginId, file, primary, locale, extradir, category); 80 tocFiles.add(tocFile); 81 } 82 } 83 return (TocFile[])tocFiles.toArray(new TocFile[tocFiles.size()]); 84 } 85 } 86 | Popular Tags |