import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import static org.hedgecode.chess.scanner.ScannerConstants.*;
+
/**
* Aggregate the proxy parameters for {@link Proxy}.
*
*/
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()) {
}
}
- 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;
}
@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) : ""
);
}