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;
22 import static org.hedgecode.chess.scanner.ScannerConstants.*;
25 * Aggregate the proxy parameters for {@link Proxy}.
27 * @author Dmitry Samoshin aka gotty
29 public class ProxyParams {
31 private static final Pattern PROXY_SERVER_PATTERN = Pattern.compile(PROXY_SERVER_REGEX);
32 private static final Pattern PROXY_AUTH_PATTERN = Pattern.compile(PROXY_AUTH_REGEX);
34 private ProxyType type;
35 private boolean isSystem;
41 private String password;
43 public ProxyParams(String proxyServer, String proxyAuth, boolean isSystemProxy) {
44 isSystem = isSystemProxy;
46 Matcher matcher = PROXY_SERVER_PATTERN.matcher(proxyServer);
48 type = ProxyType.byName(matcher.group(1));
49 host = matcher.group(2);
50 port = Integer.parseInt(matcher.group(3));
53 if (proxyAuth != null && !proxyAuth.isEmpty()) {
54 matcher = PROXY_AUTH_PATTERN.matcher(proxyAuth);
56 user = matcher.group(1);
57 password = matcher.group(2);
62 public ProxyType getType() {
66 public boolean isSystem() {
70 public String getHost() {
74 public int getPort() {
78 public String getUser() {
82 public String getPassword() {
87 public String toString() {
93 user != null ? String.format("(user: %s)", user) : ""