]> gerrit.simantics Code Review - simantics/district.git/blobdiff - 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
diff --git a/org.simantics.district.maps/src/org/simantics/maps/pojo/AppletProxyUtil.java b/org.simantics.district.maps/src/org/simantics/maps/pojo/AppletProxyUtil.java
new file mode 100644 (file)
index 0000000..1234bd4
--- /dev/null
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.maps.pojo;
+
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+
+import org.simantics.maps.IProxyUtil;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class AppletProxyUtil implements IProxyUtil {
+
+    /**
+     * @return IProxyService of the platform or <code>null</code> if the
+     *         service is not available.
+     */
+    public Proxy getProxyService(final String url) {
+        List<Proxy> l;
+        try {
+            l = ProxySelector.getDefault().select(new URI(url));
+        } catch (URISyntaxException e) {
+            e.printStackTrace();
+            return null;
+        }
+
+        for(Proxy proxy : l) {
+            if(proxy.type() == Proxy.Type.HTTP && proxy.address() != null) {
+                return proxy;
+            }
+        }
+        return null;
+    }
+
+}