KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > core > SiteManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  * Laurent Fourrier (laurent@fourrier.nom.fr) - HTTP Proxy code and NetAccess Plugin
11  *******************************************************************************/

12 package org.eclipse.update.core;
13
14 import java.net.URL JavaDoc;
15
16 import org.eclipse.core.net.proxy.IProxyData;
17 import org.eclipse.core.net.proxy.IProxyService;
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.update.configuration.ILocalSite;
20 import org.eclipse.update.internal.core.InternalSiteManager;
21 import org.eclipse.update.internal.core.UpdateCore;
22
23 /**
24  * Site Manager.
25  * A helper class used for creating site instance.
26  * Site manager is a singleton class. It cannot be instantiated;
27  * all functionality is provided by static methods.
28  *
29  * <p>
30  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
31  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
32  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
33  * (repeatedly) as the API evolves.
34  * </p>
35  * @see org.eclipse.update.core.ISite
36  * @see org.eclipse.update.configuration.ILocalSite
37  * @see org.eclipse.update.configuration.IConfiguredSite
38  * @since 2.0
39  */

40 public class SiteManager {
41
42     private static String JavaDoc os;
43     private static String JavaDoc ws;
44     private static String JavaDoc arch;
45     private static String JavaDoc nl;
46
47     private SiteManager() {
48     }
49
50     /**
51      * Returns a site object for the site specified by the argument URL.
52      * Typically, the URL references a site manifest file on an update
53      * site. An update site acts as a source of features for installation
54      * actions.
55      *
56      * @param siteURL site URL
57      * @return site object for the url
58      * @exception CoreException
59      * @deprecated use getSite(URL,IPogressMonitor) instead
60      * @since 2.0
61      */

62     public static ISite getSite(URL JavaDoc siteURL) throws CoreException {
63         return InternalSiteManager.getSite(siteURL, true,null);
64     }
65
66     /**
67      * Returns a site object for the site specified by the argument URL.
68      * Typically, the URL references a site manifest file on an update
69      * site. An update site acts as a source of features for installation
70      * actions.
71      *
72      * @param siteURL site URL
73      * @param monitor the progress monitor
74      * @return site object for the url or <samp>null</samp> in case a
75      * user canceled the connection in the progress monitor.
76      * @exception CoreException
77      * @since 2.1
78      */

79     public static ISite getSite(URL JavaDoc siteURL, IProgressMonitor monitor) throws CoreException {
80         return InternalSiteManager.getSite(siteURL, true, monitor);
81     }
82
83     /**
84      * Returns a site object for the site specified by the argument URL.
85      * Typically, the URL references a site manifest file on an update
86      * site. An update site acts as a source of features for installation
87      * actions.
88      *
89      * @param siteURL site URL
90      * @param usesCache <code>false</code> if the cache should be refreshed, and the site entirely reparsed, <code>false</code> otherwise.
91      * @return site object for the url
92      * @exception CoreException
93      * @deprecated use getSite(URL,boolean,IPogressMonitor) instead
94      * @since 2.0
95      */

96     public static ISite getSite(URL JavaDoc siteURL, boolean usesCache) throws CoreException {
97         return InternalSiteManager.getSite(siteURL, usesCache,null);
98     }
99
100     /**
101      * Returns a site object for the site specified by the argument URL.
102      * Typically, the URL references a site manifest file on an update
103      * site. An update site acts as a source of features for installation
104      * actions.
105      *
106      * @param siteURL site URL
107      * @param usesCache <code>false</code> if the cache should be refreshed, and the site entirely reparsed, <code>false</code> otherwise.
108      * @param monitor the progress monitor
109      * @return site object for the url or <samp>null</samp> in case a
110      * user canceled the connection in the progress monitor.
111      * @exception CoreException
112      * @since 2.1
113      */

114     public static ISite getSite(URL JavaDoc siteURL, boolean usesCache, IProgressMonitor monitor) throws CoreException {
115         return InternalSiteManager.getSite(siteURL, usesCache, monitor);
116     }
117
118
119     /**
120      * Returns the "local site". A local site is a logical collection
121      * of configuration information plus one or more file system
122      * installation directories, represented as intividual sites.
123      * These are potential targets for installation actions.
124      *
125      * @return the local site
126      * @exception CoreException
127      * @since 2.0
128      */

129     public static ILocalSite getLocalSite() throws CoreException {
130         return InternalSiteManager.getLocalSite();
131     }
132
133     /**
134      * Trigger handling of newly discovered features. This method
135      * can be called by the executing application whenever it
136      * is invoked with the -newUpdates command line argument.
137      *
138      * @throws CoreException if an error occurs.
139      * @since 2.0
140      * @deprecated Do not use this method
141      */

142     public static void handleNewChanges() throws CoreException {
143     }
144     /**
145      * Returns system architecture specification. A comma-separated list of arch
146      * designators defined by the platform.
147      *
148      * This information is used as a hint by the installation and update
149      * support.
150      *
151      * @return system architecture specification
152      * @since 2.1
153      */

154     public static String JavaDoc getOSArch() {
155         if (arch == null)
156             arch = Platform.getOSArch();
157         return arch;
158     }
159
160     /**
161      * Returns operating system specification. A comma-separated list of os
162      * designators defined by the platform.
163      *
164      * This information is used as a hint by the installation and update
165      * support.
166      *
167      * @return the operating system specification.
168      * @since 2.1
169      */

170     public static String JavaDoc getOS() {
171         if (os == null)
172             os = Platform.getOS();
173         return os;
174     }
175
176     /**
177      * Returns system architecture specification. A comma-separated list of arch
178      * designators defined by the platform.
179      *
180      * This information is used as a hint by the installation and update
181      * support.
182      * @return system architecture specification.
183      * @since 2.1
184      */

185     public static String JavaDoc getWS() {
186         if (ws == null)
187             ws = Platform.getWS();
188         return ws;
189     }
190
191     /**
192      * Sets the arch.
193      * @param arch The arch to set
194      */

195     public static void setOSArch(String JavaDoc arch) {
196         SiteManager.arch = arch;
197     }
198
199     /**
200      * Sets the os.
201      * @param os The os to set
202      */

203     public static void setOS(String JavaDoc os) {
204         SiteManager.os = os;
205     }
206
207     /**
208      * Sets the ws.
209      * @param ws The ws to set
210      */

211     public static void setWS(String JavaDoc ws) {
212         SiteManager.ws = ws;
213     }
214
215     /**
216      * Sets the nl.
217      * @param nl The nl to set
218      */

219     public static void setNL(String JavaDoc nl) {
220         SiteManager.nl = nl;
221     }
222     
223     /**
224      * Returns an estimate of bytes per second transfer rate for this URL
225      * @param site the URL of the site
226      * @return long a bytes per second estimate rate
227      * @since 2.1
228      */

229     public static long getEstimatedTransferRate(URL JavaDoc site) {
230         if (site == null)
231             return 0;
232         return InternalSiteManager.getEstimatedTransferRate(site.getHost());
233     }
234
235     /**
236      * Returns current locale
237      *
238      * @return the string name of the current locale or <code>null</code>
239      * @since 2.1
240      */

241     public static String JavaDoc getNL() {
242         if (nl == null)
243             nl = Platform.getNL();
244         return nl;
245     }
246
247     /**
248      * Returns the HTTP Proxy Server or <code>null</code> if none.
249      * @return the HTTP proxy Server
250      * @deprecated clients should access the {@link IProxyService} directly
251      */

252     public static String JavaDoc getHttpProxyServer() {
253         IProxyService service = UpdateCore.getPlugin().getProxyService();
254         if (service != null && service.isProxiesEnabled()) {
255             IProxyData data = service.getProxyData(IProxyData.HTTP_PROXY_TYPE);
256             if (data != null)
257                 return data.getHost();
258             
259         }
260         return null;
261     }
262     /**
263      * Returns the HTTP Proxy Port or <code>null</code> if none
264      * @return the HTTP proxy Port
265      * @deprecated clients should access the {@link IProxyService} directly
266      */

267     public static String JavaDoc getHttpProxyPort() {
268         IProxyService service = UpdateCore.getPlugin().getProxyService();
269         if (service != null && service.isProxiesEnabled()) {
270             IProxyData data = service.getProxyData(IProxyData.HTTP_PROXY_TYPE);
271             if (data != null) {
272                 if (data.getPort() == -1)
273                     return "80";
274                 return String.valueOf(data.getPort());
275             }
276             
277         }
278         return null;
279     }
280     
281     /**
282      * Returns <code>true</code> if the connection should use the
283      * http proxy server, <code>false</code> otherwise
284      * @return is the http proxy server enable
285      * @deprecated clients should access the {@link IProxyService} directly
286      */

287     public static boolean isHttpProxyEnable() {
288         IProxyService service = UpdateCore.getPlugin().getProxyService();
289         if (service != null && service.isProxiesEnabled()) {
290             IProxyData data = service.getProxyData(IProxyData.HTTP_PROXY_TYPE);
291             return (data != null && data.getHost() != null);
292         }
293         return false;
294     }
295     /**
296      * Sets the HTTP Proxy information
297      * Sets the HTTP proxy server for the HTTP proxy server
298      * Sets the HTTP proxy port for the HTTP proxy server
299      * If the proxy name is <code>null</code> or the proxy port is
300      * <code>null</code> the connection will not use HTTP proxy server.
301      *
302      * @param enable <code>true</code> if the connection should use an http
303      * proxy server, <code>false </code> otherwise.
304      * @param httpProxyServer the HTTP proxy server name or IP address
305      * @param httpProxyPort the HTTP proxy port
306      *
307      * @deprecated clients should use the {@link IProxyService} directly
308      */

309     public static void setHttpProxyInfo(boolean enable, String JavaDoc httpProxyServer, String JavaDoc httpProxyPort) {
310         IProxyService service = UpdateCore.getPlugin().getProxyService();
311         if (service == null)
312             return;
313         // Make sure that the proxy service is enabled if needed but don't disable the
314
// service if the http proxy is being disabled
315
if (enable && !service.isProxiesEnabled())
316             service.setProxiesEnabled(enable);
317
318         if (service.isProxiesEnabled()) {
319             IProxyData data = service.getProxyData(IProxyData.HTTP_PROXY_TYPE);
320             if (data != null) {
321                 data.setHost(httpProxyServer);
322                 if (httpProxyPort == null || httpProxyPort.equals("80")) {
323                     data.setPort(-1);
324                 } else {
325                     try {
326                         int port = Integer.parseInt(httpProxyPort);
327                         data.setPort(port);
328                     } catch (NumberFormatException JavaDoc e) {
329                         UpdateCore.log(e);
330                     }
331                 }
332                 try {
333                     service.setProxyData(new IProxyData[] { data });
334                 } catch (CoreException e) {
335                     UpdateCore.log(e);
336                 }
337             }
338         }
339     }
340 }
341
Popular Tags