1 11 package org.eclipse.update.standalone; 12 import java.io.*; 13 import java.net.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.update.core.*; 17 import org.eclipse.update.internal.configurator.UpdateURLDecoder; 18 import org.eclipse.update.internal.core.*; 19 import org.eclipse.update.internal.search.*; 20 import org.eclipse.update.search.*; 21 22 32 public class SearchCommand extends ScriptedCommand { 33 34 private URL remoteSiteURL; 35 private UpdateSearchRequest searchRequest; 36 private IUpdateSearchResultCollector collector; 37 38 public SearchCommand(String fromSite) { 39 try { 40 this.remoteSiteURL = new URL(UpdateURLDecoder.decode(fromSite, "UTF-8")); UpdateSearchScope searchScope = new UpdateSearchScope(); 43 searchScope.addSearchSite( 44 "remoteSite", remoteSiteURL, 46 new String [0]); 47 searchRequest = 48 new UpdateSearchRequest(new SiteSearchCategory(), searchScope); 49 collector = new UpdateSearchResultCollector(); 50 } catch (MalformedURLException e) { 51 StandaloneUpdateApplication.exceptionLogged(); 52 UpdateCore.log(e); 53 } catch (UnsupportedEncodingException e) { 54 } 55 } 56 57 59 public boolean run(IProgressMonitor monitor) { 60 try { 61 monitor.beginTask(Messages.Standalone_searching + remoteSiteURL.toExternalForm(), 4); 62 searchRequest.performSearch(collector, monitor); 63 return true; 64 } catch (CoreException ce) { 65 IStatus status = ce.getStatus(); 66 if (status != null 67 && status.getCode() == ISite.SITE_ACCESS_EXCEPTION) { 68 System.out.println(Messages.Standalone_connection); 71 } else { 72 StandaloneUpdateApplication.exceptionLogged(); 73 UpdateCore.log(ce); 74 } 75 return false; 76 } catch (OperationCanceledException ce) { 77 return true; 78 } finally { 79 monitor.done(); 80 } 81 } 82 83 84 class UpdateSearchResultCollector implements IUpdateSearchResultCollector { 85 public void accept(IFeature feature) { 86 System.out.println( 87 "\"" + feature.getLabel() 89 + "\" " + feature.getVersionedIdentifier().getIdentifier() 91 + " " + feature.getVersionedIdentifier().getVersion()); 93 } 94 } 95 } 96 | Popular Tags |