1 11 package org.eclipse.help.internal.base.remote; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 import java.net.HttpURLConnection ; 16 import java.net.URL ; 17 18 import org.eclipse.help.AbstractContextProvider; 19 import org.eclipse.help.IContext; 20 import org.eclipse.help.internal.base.HelpBasePlugin; 21 import org.eclipse.help.internal.context.Context; 22 import org.eclipse.help.internal.dynamic.DocumentReader; 23 24 29 public class RemoteContextProvider extends AbstractContextProvider { 30 31 private static final String PATH_CONTEXT = "/context"; private static final String PARAM_ID = "id"; private static final String PARAM_LANG = "lang"; 35 private DocumentReader reader; 36 37 public IContext getContext(String id, String locale) { 38 if (RemoteHelp.isEnabled()) { 39 InputStream in = null; 40 try { 41 URL url = RemoteHelp.getURL(PATH_CONTEXT + '?' + PARAM_ID + '=' + id + '&' + PARAM_LANG + '=' + locale); 42 HttpURLConnection connection = (HttpURLConnection )url.openConnection(); 43 if (connection.getResponseCode() == 200) { 44 in = connection.getInputStream(); 45 if (reader == null) { 46 reader = new DocumentReader(); 47 } 48 return (Context)reader.read(in); 49 } 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 context-sensitive help data 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 null; 71 } 72 73 76 public String [] getPlugins() { 77 return null; 79 } 80 } 81 | Popular Tags |