X-Git-Url: https://git.hedgecode.org/?p=chesshog-scanner.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fhedgecode%2Fchess%2Fscanner%2Fproxy%2FProxyParams.java;h=6802109e77bf2e56393c9921a5dc079923e0cfb8;hp=6dba49be3872216ddada961519ab0088a300325b;hb=70d45ca74e19c98d0bef2a081f77fc1e3543691e;hpb=6e3a8590a26312b6cea579777db885107cae88df diff --git a/src/main/java/org/hedgecode/chess/scanner/proxy/ProxyParams.java b/src/main/java/org/hedgecode/chess/scanner/proxy/ProxyParams.java index 6dba49b..6802109 100644 --- a/src/main/java/org/hedgecode/chess/scanner/proxy/ProxyParams.java +++ b/src/main/java/org/hedgecode/chess/scanner/proxy/ProxyParams.java @@ -19,6 +19,8 @@ package org.hedgecode.chess.scanner.proxy; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.hedgecode.chess.scanner.ScannerConstants.*; + /** * Aggregate the proxy parameters for {@link Proxy}. * @@ -26,29 +28,26 @@ import java.util.regex.Pattern; */ public class ProxyParams { - private static final Pattern PROXY_SERVER_PATTERN = Pattern.compile( - "^([^:]+):([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}):([0-9]{1,5})$" - ); - - private static final Pattern PROXY_AUTH_PATTERN = Pattern.compile( - "^([^:]+):(.+)$" - ); + private static final Pattern PROXY_SERVER_PATTERN = Pattern.compile(PROXY_SERVER_REGEX); + private static final Pattern PROXY_AUTH_PATTERN = Pattern.compile(PROXY_AUTH_REGEX); - private Proxy type; + private ProxyType type; + private boolean isSystem; private String host; - private String port; + private int port; - private String user = null; - private String password = null; + private String user; + private String password; - public ProxyParams(String proxyServer, String proxyAuth) { + public ProxyParams(String proxyServer, String proxyAuth, boolean isSystemProxy) { + isSystem = isSystemProxy; Matcher matcher = PROXY_SERVER_PATTERN.matcher(proxyServer); if (matcher.find()) { - type = Proxy.byName(matcher.group(1)); + type = ProxyType.byName(matcher.group(1)); host = matcher.group(2); - port = matcher.group(3); + port = Integer.parseInt(matcher.group(3)); } if (proxyAuth != null && !proxyAuth.isEmpty()) { @@ -60,29 +59,19 @@ public class ProxyParams { } } - public ProxyParams(Proxy type, String host, String port) { - this.type = type; - this.host = host; - this.port = port; - } - - public ProxyParams(Proxy type, String host, String port, String user, String password) { - this.type = type; - this.host = host; - this.port = port; - this.user = user; - this.password = password; + public ProxyType getType() { + return type; } - public Proxy getType() { - return type; + public boolean isSystem() { + return isSystem; } public String getHost() { return host; } - public String getPort() { + public int getPort() { return port; } @@ -97,11 +86,11 @@ public class ProxyParams { @Override public String toString() { return String.format( - "[%s] %s:%s%s", + "[%s] %s:%d %s", type, host, port, - user != null ? " (with auth)" : "" + user != null ? String.format("(user: %s)", user) : "" ); }