Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 041ee8f69bc7e33c30f4495ab40b9f6aa4805daf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.help.internal.extension;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.AbstractContentExtensionProvider;
import org.eclipse.help.IContentExtension;
import org.eclipse.help.internal.HelpPlugin;
import org.osgi.framework.Bundle;

/*
 * Provides the extensions from content extension XML files registered via
 * the org.eclipse.help.contentExtension extension point.
 */
public class ContentExtensionFileProvider extends AbstractContentExtensionProvider {

	private static final String EXTENSION_POINT_ID_CONTENT_EXTENSION = HelpPlugin.PLUGIN_ID + ".contentExtension"; //$NON-NLS-1$
	private static final String ELEMENT_NAME_CONTENT_EXTENSION = "contentExtension"; //$NON-NLS-1$
	private static final String ATTRIBUTE_NAME_FILE = "file"; //$NON-NLS-1$
	
	/* (non-Javadoc)
	 * @see org.eclipse.help.AbstractContentExtensionProvider#getContentExtensions(java.lang.String)
	 */
	public IContentExtension[] getContentExtensions(String locale) {
		List extensions = new ArrayList();
		IExtensionRegistry registry = Platform.getExtensionRegistry();
		ContentExtensionFileParser parser = new ContentExtensionFileParser();
		IConfigurationElement[] elements = registry.getConfigurationElementsFor(EXTENSION_POINT_ID_CONTENT_EXTENSION);
		for (int i=0;i<elements.length;++i) {
			if (ELEMENT_NAME_CONTENT_EXTENSION.equals(elements[i].getName())) {
				String file = elements[i].getAttribute(ATTRIBUTE_NAME_FILE);
				String bundleId = elements[i].getContributor().getName();
				Bundle bundle = Platform.getBundle(bundleId);
				if (bundle != null) {
					try {
						IContentExtension[] ext = parser.parse(bundle, file);
						for (int j=0;j<ext.length;++j) {
							extensions.add(ext[j]);
						}
					}
					catch (Throwable t) {
						String msg = "Unable to load user assistance content extension " + file + " from plug-in " + bundleId; //$NON-NLS-1$ //$NON-NLS-2$
						HelpPlugin.logError(msg, t);
					}
				}
			}
		}
		return (IContentExtension[])extensions.toArray(new IContentExtension[extensions.size()]);
	}
}

Back to the top