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 import java.util.List ; 17 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.SubProgressMonitor; 20 import org.eclipse.help.internal.base.HelpBasePlugin; 21 import org.eclipse.help.internal.search.ISearchHitCollector; 22 import org.eclipse.help.internal.search.ISearchQuery; 23 import org.eclipse.help.internal.search.QueryTooComplexException; 24 import org.eclipse.help.internal.util.URLCoder; 25 26 29 public class RemoteSearchManager { 30 31 private static final String PATH_SEARCH = "/search"; private static final String PARAM_PHRASE = "phrase"; private static final String PARAM_LANG = "lang"; private RemoteSearchParser parser; 35 36 39 public void search(ISearchQuery searchQuery, ISearchHitCollector collector, IProgressMonitor pm) 40 throws QueryTooComplexException { 41 pm.beginTask("", 100); try { 43 if (RemoteHelp.isEnabled()) { 45 InputStream in = null; 46 try { 47 URL url = RemoteHelp.getURL(PATH_SEARCH + '?' + PARAM_PHRASE + '=' + URLCoder.encode(searchQuery.getSearchWord()) + '&' + PARAM_LANG + '=' + searchQuery.getLocale()); 48 in = url.openStream(); 49 if (parser == null) { 50 parser = new RemoteSearchParser(); 51 } 52 List hits = parser.parse(in, new SubProgressMonitor(pm, 100)); 54 collector.addHits(hits, null); 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 search results 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 } 76 finally { 77 pm.done(); 78 } 79 } 80 } 81 | Popular Tags |