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.AbstractTocProvider; 20 import org.eclipse.help.ITocContribution; 21 import org.eclipse.help.internal.base.HelpBasePlugin; 22 23 27 public class RemoteTocProvider extends AbstractTocProvider { 28 29 private static final String PATH_TOC = "/toc"; private static final String PARAM_LANG = "lang"; 32 36 public RemoteTocProvider() { 37 RemoteHelp.addPreferenceChangeListener(new IPreferenceChangeListener() { 38 public void preferenceChange(PreferenceChangeEvent event) { 39 contentChanged(); 40 } 41 }); 42 } 43 44 47 public ITocContribution[] getTocContributions(String locale) { 48 if (RemoteHelp.isEnabled()) { 49 InputStream in = null; 50 try { 51 URL url = RemoteHelp.getURL(PATH_TOC+ '?' + PARAM_LANG + '=' + locale); 52 in = url.openStream(); 53 RemoteTocParser parser = new RemoteTocParser(); 54 return parser.parse(in); 55 } 56 catch (IOException e) { 57 String msg = "I/O error while trying to contact the remote help server"; HelpBasePlugin.logError(msg, e); 59 RemoteHelp.setError(e); 60 } 61 catch (Throwable t) { 62 String msg = "Internal error while reading TOC contents from remote server"; HelpBasePlugin.logError(msg, t); 64 RemoteHelp.setError(t); 65 } 66 finally { 67 if (in != null) { 68 try { 69 in.close(); 70 } 71 catch (IOException e) { 72 } 74 } 75 } 76 } 77 return new ITocContribution[0]; 78 } 79 } 80 | Popular Tags |