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.ChessHogScannerException;
20 import org.hedgecode.chess.scanner.Initiable;
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.regex.RegexType;
26 import org.hedgecode.chess.scanner.spi.ServiceRegistry;
29 * AbstractSettingsScanner
31 * @author Dmitry Samoshin aka gotty
33 public abstract class AbstractSettingsScanner extends AbstractRequestScanner implements Initiable {
35 private Settings settings;
37 protected abstract String getResourceName();
40 public void init() throws ChessHogScannerException {
41 SettingsBuilder settingsBuilder = ServiceRegistry.singleProvider(
44 settings = settingsBuilder.build(
49 protected Settings getSettings() {
53 protected String assignUrl(String tournamentId, String pageId) {
54 return RegexBuilder.build(
56 settings.getTournamentUrl(),
59 settings.isTournamentMultiPage() ? pageId : null
64 protected String assignUrl(String gameId) {
65 String gameUrl = settings.getGamePgnUrl() != null
66 ? settings.getGamePgnUrl()
67 : settings.getGameUrl();
68 return RegexBuilder.build(
71 new RegexParams(gameId)
75 protected String assignUrl(String query, boolean isUrlEncode) {
76 return RegexBuilder.build(
78 settings.getTournamentQuery(),
79 new RegexParams(query, isUrlEncode)