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.portal;
19 import java.util.regex.Matcher;
20 import java.util.regex.Pattern;
22 import org.hedgecode.chess.scanner.Initiable;
23 import org.hedgecode.chess.scanner.ScannerException;
24 import org.hedgecode.chess.scanner.Settings;
25 import org.hedgecode.chess.scanner.SettingsBuilder;
26 import org.hedgecode.chess.scanner.regex.RegexBuilder;
27 import org.hedgecode.chess.scanner.regex.RegexParams;
28 import org.hedgecode.chess.scanner.spi.ServiceRegistry;
30 import static org.hedgecode.chess.scanner.regex.RegexBuilder.Type;
33 * AbstractSettingsScanner
35 * @author Dmitry Samoshin aka gotty
37 public abstract class AbstractSettingsScanner extends AbstractRequestScanner implements Initiable {
39 private Settings settings;
41 protected abstract String getResourceName();
44 public void init() throws ScannerException {
45 SettingsBuilder settingsBuilder = ServiceRegistry.singleProvider(
48 settings = settingsBuilder.build(
53 protected Settings getSettings() {
57 protected String assignUrl(String tournamentId, String pageId) {
58 String tournamentUrl = assignUrlWithParams(
59 settings.getTournamentUrl(), settings.getTournamentQueryParams()
61 return RegexBuilder.build(
66 settings.isTournamentMultiPage() ? pageId : null
71 protected String assignUrl(String gameId) {
72 String gameUrl = settings.getGamePgnUrl() != null
73 ? settings.getGamePgnUrl()
74 : settings.getGameUrl();
75 return RegexBuilder.build(
77 assignUrlWithParams(gameUrl, settings.getGameQueryParams()),
78 new RegexParams(gameId)
82 protected String assignUrl(String gameId, String tournamentId, boolean withTournament) {
83 String gameUrl = settings.getGamePgnUrl() != null
84 ? settings.getGamePgnUrl()
85 : settings.getGameUrl();
86 return RegexBuilder.build(
88 assignUrlWithParams(gameUrl, settings.getGameQueryParams()),
97 protected String assignUrl(String query, boolean isUrlEncode) {
98 return RegexBuilder.build(
100 settings.getTournamentQuery(),
108 private String assignUrlWithParams(String url, String params) {
109 return params != null