--- /dev/null
+/*
+ * Copyright (c) 2019-2020. Developed by Hedgecode.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.hedgecode.chess.scanner.portal;
+
+import org.hedgecode.chess.scanner.ChessHogScannerException;
+import org.hedgecode.chess.scanner.Initiable;
+import org.hedgecode.chess.scanner.Settings;
+import org.hedgecode.chess.scanner.SettingsBuilder;
+import org.hedgecode.chess.scanner.regex.RegexBuilder;
+import org.hedgecode.chess.scanner.regex.RegexParams;
+import org.hedgecode.chess.scanner.regex.RegexType;
+import org.hedgecode.chess.scanner.spi.ServiceRegistry;
+
+/**
+ * AbstractSettingsScanner
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public abstract class AbstractSettingsScanner extends AbstractRequestScanner implements Initiable {
+
+ private Settings settings;
+
+ protected abstract String getResourceName();
+
+ @Override
+ public void init() throws ChessHogScannerException {
+ SettingsBuilder settingsBuilder = ServiceRegistry.singleProvider(
+ SettingsBuilder.class
+ );
+ settings = settingsBuilder.build(
+ getResourceName()
+ );
+ }
+
+ protected Settings getSettings() {
+ return settings;
+ }
+
+ protected String assignUrl(String tournamentId, String pageId) {
+ return RegexBuilder.build(
+ RegexType.TOURNAMENT,
+ settings.getTournamentUrl(),
+ new RegexParams(
+ tournamentId,
+ settings.isTournamentMultiPage() ? pageId : null
+ )
+ );
+ }
+
+ protected String assignUrl(String gameId) {
+ String gameUrl = settings.getGamePgnUrl() != null
+ ? settings.getGamePgnUrl()
+ : settings.getGameUrl();
+ return RegexBuilder.build(
+ RegexType.GAME,
+ gameUrl,
+ new RegexParams(gameId)
+ );
+ }
+
+ protected String assignUrl(String query, boolean isUrlEncode) {
+ return RegexBuilder.build(
+ RegexType.QUERY,
+ settings.getTournamentQuery(),
+ new RegexParams(query, isUrlEncode)
+ );
+ }
+
+}