Skip to main content
summaryrefslogtreecommitdiffstats
blob: fff3ce68218ca3de3dd813f66d9802fae4ccbe85 (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
64
65
66
67
/*******************************************************************************
 * Copyright (c) 2006, 2015 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_CONTENT_EXTENSION = HelpPlugin.PLUGIN_ID + ".contentExtension"; //$NON-NLS-1$
	private static final String ELEMENT_CONTENT_EXTENSION = "contentExtension"; //$NON-NLS-1$
	private static final String ATTRIBUTE_FILE = "file"; //$NON-NLS-1$
	private static final String ATTRIBUTE_CONTENT = "content"; //$NON-NLS-1$

	/* (non-Javadoc)
	 * @see org.eclipse.help.AbstractContentExtensionProvider#getContentExtensions(java.lang.String)
	 */
	@Override
	public IContentExtension[] getContentExtensions(String locale) {
		List extensions = new ArrayList();
		IExtensionRegistry registry = Platform.getExtensionRegistry();
		ContentExtensionFileParser parser = new ContentExtensionFileParser();
		IConfigurationElement[] elements = registry.getConfigurationElementsFor(EXTENSION_POINT_CONTENT_EXTENSION);
		for (int i=0;i<elements.length;++i) {
			if (ELEMENT_CONTENT_EXTENSION.equals(elements[i].getName())) {
				String file = elements[i].getAttribute(ATTRIBUTE_FILE);
				String bundleId = elements[i].getContributor().getName();
				Bundle bundle = Platform.getBundle(bundleId);
				try {
					ContentExtension[] ext = parser.parse(bundle, file);
					for (int j=0;j<ext.length;++j) {
						String content = ext[j].getAttribute(ATTRIBUTE_CONTENT);
						if (content != null) {
							ext[j].setAttribute(ATTRIBUTE_CONTENT, '/' + bundleId + '/' + content);
						}
						extensions.add(ext[j]);
					}
				}
				catch (Throwable t) {
					String msg = "Error reading user assistance content extension file /\"" + bundleId + '/' + file + "\" (skipping file)"; //$NON-NLS-1$ //$NON-NLS-2$
					HelpPlugin.logError(msg, t);
				}
			}
		}
		return (IContentExtension[])extensions.toArray(new IContentExtension[extensions.size()]);
	}
}

Back to the top