KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > index > IndexFileProvider


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.index;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
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 /*
24  * Provides index data from index XML files to the help system.
25  */

26 public class IndexFileProvider extends AbstractIndexProvider {
27
28     public static final String JavaDoc EXTENSION_POINT_ID_INDEX = HelpPlugin.PLUGIN_ID + ".index"; //$NON-NLS-1$
29
public static final String JavaDoc ELEMENT_NAME_INDEX = "index"; //$NON-NLS-1$
30
public static final String JavaDoc ATTRIBUTE_NAME_FILE = "file"; //$NON-NLS-1$
31

32     /* (non-Javadoc)
33      * @see org.eclipse.help.AbstractIndexProvider#getIndexContributions(java.lang.String)
34      */

35     public IIndexContribution[] getIndexContributions(String JavaDoc locale) {
36         List JavaDoc contributions = new ArrayList JavaDoc();
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 JavaDoc t) {
45                 String JavaDoc msg = "Error reading help keyword index file /\"" + indexFiles[i].getPluginId() + '/' + indexFiles[i].getFile() + "\" (skipping file)"; //$NON-NLS-1$ //$NON-NLS-2$
46
HelpPlugin.logError(msg, t);
47             }
48         }
49         return (IIndexContribution[])contributions.toArray(new IIndexContribution[contributions.size()]);
50     }
51
52     /*
53      * Returns all available IndexFiles for the given locale.
54      */

55     private IndexFile[] getIndexFiles(String JavaDoc locale) {
56         List JavaDoc indexFiles = new ArrayList JavaDoc();
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 JavaDoc pluginId = elem.getContributor().getName();
62             if (elem.getName().equals(ELEMENT_NAME_INDEX)) {
63                 String JavaDoc 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