KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > standalone > SearchCommand


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
23  * Command to search an update site and list its features.
24  * <p>
25  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
26  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
27  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
28  * (repeatedly) as the API evolves.
29  * </p>
30  * @since 3.0
31  */

32 public class SearchCommand extends ScriptedCommand {
33
34     private URL remoteSiteURL;
35     private UpdateSearchRequest searchRequest;
36     private IUpdateSearchResultCollector collector;
37
38     public SearchCommand(String JavaDoc fromSite) {
39         try {
40             //PAL foundation
41
this.remoteSiteURL = new URL(UpdateURLDecoder.decode(fromSite, "UTF-8")); //$NON-NLS-1$
42
UpdateSearchScope searchScope = new UpdateSearchScope();
43             searchScope.addSearchSite(
44                 "remoteSite", //$NON-NLS-1$
45
remoteSiteURL,
46                 new String JavaDoc[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     /**
58      */

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                 // Just show this but do not throw exception
69
// because there may be results anyway.
70
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                 "\"" //$NON-NLS-1$
88
+ feature.getLabel()
89                     + "\" " //$NON-NLS-1$
90
+ feature.getVersionedIdentifier().getIdentifier()
91                     + " " //$NON-NLS-1$
92
+ feature.getVersionedIdentifier().getVersion());
93         }
94     }
95 }
96
Popular Tags