1 12 package org.eclipse.update.core; 13 14 import java.net.URL ; 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 40 public class SiteManager { 41 42 private static String os; 43 private static String ws; 44 private static String arch; 45 private static String nl; 46 47 private SiteManager() { 48 } 49 50 62 public static ISite getSite(URL siteURL) throws CoreException { 63 return InternalSiteManager.getSite(siteURL, true,null); 64 } 65 66 79 public static ISite getSite(URL siteURL, IProgressMonitor monitor) throws CoreException { 80 return InternalSiteManager.getSite(siteURL, true, monitor); 81 } 82 83 96 public static ISite getSite(URL siteURL, boolean usesCache) throws CoreException { 97 return InternalSiteManager.getSite(siteURL, usesCache,null); 98 } 99 100 114 public static ISite getSite(URL siteURL, boolean usesCache, IProgressMonitor monitor) throws CoreException { 115 return InternalSiteManager.getSite(siteURL, usesCache, monitor); 116 } 117 118 119 129 public static ILocalSite getLocalSite() throws CoreException { 130 return InternalSiteManager.getLocalSite(); 131 } 132 133 142 public static void handleNewChanges() throws CoreException { 143 } 144 154 public static String getOSArch() { 155 if (arch == null) 156 arch = Platform.getOSArch(); 157 return arch; 158 } 159 160 170 public static String getOS() { 171 if (os == null) 172 os = Platform.getOS(); 173 return os; 174 } 175 176 185 public static String getWS() { 186 if (ws == null) 187 ws = Platform.getWS(); 188 return ws; 189 } 190 191 195 public static void setOSArch(String arch) { 196 SiteManager.arch = arch; 197 } 198 199 203 public static void setOS(String os) { 204 SiteManager.os = os; 205 } 206 207 211 public static void setWS(String ws) { 212 SiteManager.ws = ws; 213 } 214 215 219 public static void setNL(String nl) { 220 SiteManager.nl = nl; 221 } 222 223 229 public static long getEstimatedTransferRate(URL site) { 230 if (site == null) 231 return 0; 232 return InternalSiteManager.getEstimatedTransferRate(site.getHost()); 233 } 234 235 241 public static String getNL() { 242 if (nl == null) 243 nl = Platform.getNL(); 244 return nl; 245 } 246 247 252 public static String 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 267 public static String 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 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 309 public static void setHttpProxyInfo(boolean enable, String httpProxyServer, String httpProxyPort) { 310 IProxyService service = UpdateCore.getPlugin().getProxyService(); 311 if (service == null) 312 return; 313 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 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 |