KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > extension > ContentExtensionFileProvider


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.extension;
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.AbstractContentExtensionProvider;
20 import org.eclipse.help.IContentExtension;
21 import org.eclipse.help.internal.HelpPlugin;
22 import org.osgi.framework.Bundle;
23
24 /*
25  * Provides the extensions from content extension XML files registered via
26  * the org.eclipse.help.contentExtension extension point.
27  */

28 public class ContentExtensionFileProvider extends AbstractContentExtensionProvider {
29
30     private static final String JavaDoc EXTENSION_POINT_CONTENT_EXTENSION = HelpPlugin.PLUGIN_ID + ".contentExtension"; //$NON-NLS-1$
31
private static final String JavaDoc ELEMENT_CONTENT_EXTENSION = "contentExtension"; //$NON-NLS-1$
32
private static final String JavaDoc ATTRIBUTE_FILE = "file"; //$NON-NLS-1$
33
private static final String JavaDoc ATTRIBUTE_CONTENT = "content"; //$NON-NLS-1$
34

35     /* (non-Javadoc)
36      * @see org.eclipse.help.AbstractContentExtensionProvider#getContentExtensions(java.lang.String)
37      */

38     public IContentExtension[] getContentExtensions(String JavaDoc locale) {
39         List JavaDoc extensions = new ArrayList JavaDoc();
40         IExtensionRegistry registry = Platform.getExtensionRegistry();
41         ContentExtensionFileParser parser = new ContentExtensionFileParser();
42         IConfigurationElement[] elements = registry.getConfigurationElementsFor(EXTENSION_POINT_CONTENT_EXTENSION);
43         for (int i=0;i<elements.length;++i) {
44             if (ELEMENT_CONTENT_EXTENSION.equals(elements[i].getName())) {
45                 String JavaDoc file = elements[i].getAttribute(ATTRIBUTE_FILE);
46                 String JavaDoc bundleId = elements[i].getContributor().getName();
47                 Bundle bundle = Platform.getBundle(bundleId);
48                 try {
49                     ContentExtension[] ext = parser.parse(bundle, file);
50                     for (int j=0;j<ext.length;++j) {
51                         String JavaDoc content = ext[j].getAttribute(ATTRIBUTE_CONTENT);
52                         if (content != null) {
53                             ext[j].setAttribute(ATTRIBUTE_CONTENT, '/' + bundleId + '/' + content);
54                         }
55                         extensions.add(ext[j]);
56                     }
57                 }
58                 catch (Throwable JavaDoc t) {
59                     String JavaDoc msg = "Error reading user assistance content extension file /\"" + bundleId + '/' + file + "\" (skipping file)"; //$NON-NLS-1$ //$NON-NLS-2$
60
HelpPlugin.logError(msg, t);
61                 }
62             }
63         }
64         return (IContentExtension[])extensions.toArray(new IContentExtension[extensions.size()]);
65     }
66 }
67
Popular Tags