Remove Unused Texts from UIText.java and corresponding properties
[egit.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / EclipseProxySelector.java
blob9c9ce654e34a5cedbe38cfab5bc340c7a3e43519
1 /*******************************************************************************
2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9 package org.eclipse.egit.ui;
11 import java.io.IOException;
12 import java.net.InetAddress;
13 import java.net.InetSocketAddress;
14 import java.net.Proxy;
15 import java.net.ProxySelector;
16 import java.net.SocketAddress;
17 import java.net.URI;
18 import java.net.UnknownHostException;
19 import java.util.ArrayList;
20 import java.util.List;
22 import org.eclipse.core.net.proxy.IProxyData;
23 import org.eclipse.core.net.proxy.IProxyService;
25 class EclipseProxySelector extends ProxySelector {
26 private final IProxyService service;
28 EclipseProxySelector(final IProxyService s) {
29 service = s;
32 @Override
33 public List<Proxy> select(final URI uri) {
34 final ArrayList<Proxy> r = new ArrayList<Proxy>();
35 final String host = uri.getHost();
37 String type = IProxyData.SOCKS_PROXY_TYPE;
38 if ("http".equals(uri.getScheme())) //$NON-NLS-1$
39 type = IProxyData.HTTP_PROXY_TYPE;
40 else if ("ftp".equals(uri.getScheme())) //$NON-NLS-1$
41 type = IProxyData.HTTP_PROXY_TYPE;
42 else if ("https".equals(uri.getScheme())) //$NON-NLS-1$
43 type = IProxyData.HTTPS_PROXY_TYPE;
45 final IProxyData data = service.getProxyDataForHost(host, type);
46 if (data != null) {
47 if (IProxyData.HTTP_PROXY_TYPE.equals(data.getType()))
48 addProxy(r, Proxy.Type.HTTP, data);
49 else if (IProxyData.HTTPS_PROXY_TYPE.equals(data.getType()))
50 addProxy(r, Proxy.Type.HTTP, data);
51 else if (IProxyData.SOCKS_PROXY_TYPE.equals(data.getType()))
52 addProxy(r, Proxy.Type.SOCKS, data);
54 if (r.isEmpty())
55 r.add(Proxy.NO_PROXY);
56 return r;
59 private void addProxy(final ArrayList<Proxy> r, final Proxy.Type type,
60 final IProxyData d) {
61 try {
62 r.add(new Proxy(type, new InetSocketAddress(InetAddress.getByName(d
63 .getHost()), d.getPort())));
64 } catch (UnknownHostException uhe) {
65 // Oh well.
69 @Override
70 public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
71 // Don't tell Eclipse.