]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.maps/src/org/simantics/maps/pojo/AppletProxyUtil.java
Share some projects for Simantics District
[simantics/district.git] / org.simantics.district.maps / src / org / simantics / maps / pojo / AppletProxyUtil.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management
3  * in Industry THTH ry.
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  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.maps.pojo;
13
14 import java.net.Proxy;
15 import java.net.ProxySelector;
16 import java.net.URI;
17 import java.net.URISyntaxException;
18 import java.util.List;
19
20 import org.simantics.maps.IProxyUtil;
21
22 /**
23  * @author Tuukka Lehtonen
24  */
25 public class AppletProxyUtil implements IProxyUtil {
26
27     /**
28      * @return IProxyService of the platform or <code>null</code> if the
29      *         service is not available.
30      */
31     public Proxy getProxyService(final String url) {
32         List<Proxy> l;
33         try {
34             l = ProxySelector.getDefault().select(new URI(url));
35         } catch (URISyntaxException e) {
36             e.printStackTrace();
37             return null;
38         }
39
40         for(Proxy proxy : l) {
41             if(proxy.type() == Proxy.Type.HTTP && proxy.address() != null) {
42                 return proxy;
43             }
44         }
45         return null;
46     }
47
48 }