X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FProxy.java;h=750b3eef6a37c874b69b485e8f30b9c41ca47946;hp=fa59c738439e40467aa62dfb28252799375b0375;hb=HEAD;hpb=5644a84eee241f6c831f06e0bbf29650f0b82cc2 diff --git a/src/be/nikiroo/utils/Proxy.java b/src/be/nikiroo/utils/Proxy.java old mode 100755 new mode 100644 index fa59c73..750b3ee --- a/src/be/nikiroo/utils/Proxy.java +++ b/src/be/nikiroo/utils/Proxy.java @@ -9,6 +9,64 @@ import java.net.PasswordAuthentication; * @author niki */ public class Proxy { + /** + * Use the proxy described by this string: + * + * Some examples: + * + * + * @param proxy + * the proxy + */ + static public void use(String proxy) { + if (proxy != null && !proxy.isEmpty()) { + String user = null; + String password = null; + int port = 8080; + + if (proxy.contains("@")) { + int pos = proxy.indexOf("@"); + user = proxy.substring(0, pos); + proxy = proxy.substring(pos + 1); + if (user.contains(":")) { + pos = user.indexOf(":"); + password = user.substring(pos + 1); + user = user.substring(0, pos); + } + } + + if (proxy.equals(":")) { + proxy = null; + } else if (proxy.contains(":")) { + int pos = proxy.indexOf(":"); + try { + port = Integer.parseInt(proxy.substring(0, pos)); + proxy = proxy.substring(pos + 1); + } catch (Exception e) { + } + } + + if (proxy == null) { + Proxy.useSystemProxy(user, password); + } else { + Proxy.useProxy(proxy, port, user, password); + } + } + } + /** * Use the system proxy. */ @@ -61,8 +119,8 @@ public class Proxy { */ static public void useProxy(String host, int port, String user, String password) { - System.setProperty("http.proxyHost", "proxy.stluc.ucl.ac.be"); - System.setProperty("http.proxyPort", "8080"); + System.setProperty("http.proxyHost", host); + System.setProperty("http.proxyPort", Integer.toString(port)); auth(user, password); }