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.AbstractIndexProvider; 20 import org.eclipse.help.IIndexContribution; 21 import org.eclipse.help.internal.base.HelpBasePlugin; 22 23 27 public class RemoteIndexProvider extends AbstractIndexProvider { 28 29 private static final String PATH_INDEX = "/index"; private static final String PARAM_LANG = "lang"; 32 36 public RemoteIndexProvider() { 37 RemoteHelp.addPreferenceChangeListener(new IPreferenceChangeListener() { 38 public void preferenceChange(PreferenceChangeEvent event) { 39 contentChanged(); 40 } 41 }); 42 } 43 44 47 public IIndexContribution[] getIndexContributions(String locale) { 48 if (RemoteHelp.isEnabled()) { 49 InputStream in = null; 50 try { 51 URL url = RemoteHelp.getURL(PATH_INDEX + '?' + PARAM_LANG + '=' + locale); 52 in = url.openStream(); 53 RemoteIndexParser parser = new RemoteIndexParser(); 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 } 60 catch (Throwable t) { 61 String msg = "Internal error while reading index contents from remote server"; HelpBasePlugin.logError(msg, t); 63 } 64 finally { 65 if (in != null) { 66 try { 67 in.close(); 68 } 69 catch (IOException e) { 70 } 72 } 73 } 74 } 75 return new IIndexContribution[0]; 76 } 77 } 78 | Popular Tags |