2 * Copyright (c) 2019-2020. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.scanner.proxy;
19 import java.util.regex.Matcher;
20 import java.util.regex.Pattern;
23 * Aggregate the proxy parameters for {@link Proxy}.
25 * @author Dmitry Samoshin aka gotty
27 public class ProxyParams {
29 private static final Pattern PROXY_SERVER_PATTERN = Pattern.compile(
30 "^([^:]+):([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}):([0-9]{1,5})$"
33 private static final Pattern PROXY_AUTH_PATTERN = Pattern.compile(
42 private String user = null;
43 private String password = null;
45 public ProxyParams(String proxyServer, String proxyAuth) {
47 Matcher matcher = PROXY_SERVER_PATTERN.matcher(proxyServer);
49 type = Proxy.byName(matcher.group(1));
50 host = matcher.group(2);
51 port = matcher.group(3);
54 if (proxyAuth != null && !proxyAuth.isEmpty()) {
55 matcher = PROXY_AUTH_PATTERN.matcher(proxyAuth);
57 user = matcher.group(1);
58 password = matcher.group(2);
63 public ProxyParams(Proxy type, String host, String port) {
69 public ProxyParams(Proxy type, String host, String port, String user, String password) {
74 this.password = password;
77 public Proxy getType() {
81 public String getHost() {
85 public String getPort() {
89 public String getUser() {
93 public String getPassword() {
98 public String toString() {
104 user != null ? " (with auth)" : ""