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.regex;
19 import java.io.UnsupportedEncodingException;
20 import java.net.URLEncoder;
22 import static org.hedgecode.chess.scanner.ChessHogScannerConstants.*;
27 * @author Dmitry Samoshin aka gotty
29 public class RegexBuilder {
31 public static String build(Type type, String target, RegexParams params) {
42 public String format(String target, RegexParams params) {
43 if (params.getPageId() != null) {
44 target = target.replace(
49 return target.replace(
50 RegexParams.TOURNAMENT_ID,
51 params.getTournamentId()
58 public String format(String target, RegexParams params) {
59 if (params.getTournamentId() != null) {
60 target = target.replace(
61 RegexParams.TOURNAMENT_ID,
62 params.getTournamentId()
65 return target.replace(
74 public String format(String target, RegexParams params) {
75 return target.replace(
78 ? urlEncode(params.getQuery())
84 public abstract String format(String target, RegexParams params);
86 private static String urlEncode(String query) throws RuntimeException {
89 encodeQuery = URLEncoder.encode(
92 } catch (UnsupportedEncodingException cause) {
93 throw new RuntimeException(
94 String.format("Unsupported encoding: %s", CHARSET.name()),