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 org.hedgecode.chess.scanner.Initiable;
20 import org.hedgecode.chess.scanner.ScannerException;
21 import org.hedgecode.chess.scanner.Settings;
22 import org.hedgecode.chess.scanner.SettingsBuilder;
23 import org.hedgecode.chess.scanner.regex.RegexBuilder;
24 import org.hedgecode.chess.scanner.regex.RegexParams;
25 import org.hedgecode.chess.scanner.spi.ServiceRegistry;
27 import static org.hedgecode.chess.scanner.regex.RegexBuilder.Type;
30 * AbstractSettingsScanner
32 * @author Dmitry Samoshin aka gotty
34 public abstract class AbstractSettingsScanner extends AbstractRequestScanner implements Initiable {
36 private Settings settings;
38 protected abstract String getResourceName();
41 public void init() throws ScannerException {
42 SettingsBuilder settingsBuilder = ServiceRegistry.singleProvider(
45 settings = settingsBuilder.build(
50 protected Settings getSettings() {
54 protected String assignUrl(String tournamentId, String pageId) {
55 String tournamentUrl = assignUrlWithParams(
56 settings.getTournamentUrl(), settings.getTournamentQueryParams()
58 return RegexBuilder.build(
63 settings.isTournamentMultiPage() ? pageId : null
68 protected String assignUrl(String gameId) {
69 String gameUrl = settings.getGamePgnUrl() != null
70 ? settings.getGamePgnUrl()
71 : settings.getGameUrl();
72 return RegexBuilder.build(
74 assignUrlWithParams(gameUrl, settings.getGameQueryParams()),
75 new RegexParams(gameId)
79 protected String assignUrl(String gameId, String tournamentId, boolean withTournament) {
80 String gameUrl = settings.getGamePgnUrl() != null
81 ? settings.getGamePgnUrl()
82 : settings.getGameUrl();
83 return RegexBuilder.build(
85 assignUrlWithParams(gameUrl, settings.getGameQueryParams()),
94 protected String assignUrl(String query, boolean isUrlEncode) {
95 return RegexBuilder.build(
97 settings.getTournamentQuery(),
105 private String assignUrlWithParams(String url, String params) {
106 return params != null