KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > base > remote > RemoteExtensionProvider


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.base.remote;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.net.URL JavaDoc;
16
17 import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
18 import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
19 import org.eclipse.help.AbstractContentExtensionProvider;
20 import org.eclipse.help.IContentExtension;
21 import org.eclipse.help.internal.UAElement;
22 import org.eclipse.help.internal.base.HelpBasePlugin;
23 import org.eclipse.help.internal.dynamic.DocumentReader;
24
25 public class RemoteExtensionProvider extends AbstractContentExtensionProvider {
26
27     private static final String JavaDoc PATH_EXTENSIONS = "/extension"; //$NON-NLS-1$
28

29     private DocumentReader reader;
30
31     public RemoteExtensionProvider() {
32         RemoteHelp.addPreferenceChangeListener(new IPreferenceChangeListener() {
33             public void preferenceChange(PreferenceChangeEvent event) {
34                 contentChanged();
35             }
36         });
37     }
38     
39     public IContentExtension[] getContentExtensions(String JavaDoc locale) {
40         if (RemoteHelp.isEnabled()) {
41             InputStream JavaDoc in = null;
42             try {
43                 URL JavaDoc url = RemoteHelp.getURL(PATH_EXTENSIONS);
44                 in = url.openStream();
45                 if (reader == null) {
46                     reader = new DocumentReader();
47                 }
48                 UAElement element = reader.read(in);
49                 return (IContentExtension[])element.getChildren(IContentExtension.class);
50             }
51             catch (IOException JavaDoc e) {
52                 String JavaDoc msg = "I/O error while trying to contact the remote help server"; //$NON-NLS-1$
53
HelpBasePlugin.logError(msg, e);
54             }
55             catch (Throwable JavaDoc t) {
56                 String JavaDoc msg = "Internal error while reading topic extensions from remote server"; //$NON-NLS-1$
57
HelpBasePlugin.logError(msg, t);
58             }
59             finally {
60                 if (in != null) {
61                     try {
62                         in.close();
63                     }
64                     catch (IOException JavaDoc e) {
65                         // nothing more we can do
66
}
67                 }
68             }
69         }
70         return new IContentExtension[0];
71     }
72 }
73
Popular Tags