1 11 package org.eclipse.help.internal.base.remote; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 import java.net.URL ; 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 PATH_EXTENSIONS = "/extension"; 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 locale) { 40 if (RemoteHelp.isEnabled()) { 41 InputStream in = null; 42 try { 43 URL 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 e) { 52 String msg = "I/O error while trying to contact the remote help server"; HelpBasePlugin.logError(msg, e); 54 } 55 catch (Throwable t) { 56 String msg = "Internal error while reading topic extensions from remote server"; HelpBasePlugin.logError(msg, t); 58 } 59 finally { 60 if (in != null) { 61 try { 62 in.close(); 63 } 64 catch (IOException e) { 65 } 67 } 68 } 69 } 70 return new IContentExtension[0]; 71 } 72 } 73 | Popular Tags |