[LIB-13] Locale resource settings
[chesshog-scanner.git] / src / main / java / org / hedgecode / chess / scanner / portal / Chess2700Scanner.java
1 /*
2  * Copyright (c) 2019-2020. Developed by Hedgecode.
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.hedgecode.chess.scanner.portal;
18
19 import org.hedgecode.chess.scanner.Scanner;
20 import org.hedgecode.chess.scanner.ScannerException;
21 import org.hedgecode.chess.scanner.StringUtils;
22 import org.hedgecode.chess.scanner.entity.PGNGame;
23 import org.hedgecode.chess.scanner.entity.PGNTournament;
24
25 import static org.hedgecode.chess.scanner.ScannerConstants.*;
26
27 /**
28  * Chess2700Scanner
29  *
30  * @author Dmitry Samoshin aka gotty
31  */
32 public class Chess2700Scanner extends AbstractSettingsScanner implements Scanner {
33
34     private static final String SETTINGS_FILENAME = "2700chess.settings";
35
36     @Override
37     protected String getResourceName() {
38         return SETTINGS_FILENAME;
39     }
40
41     @Override
42     public PGNTournament scanTournament(String tournamentId) throws ScannerException {
43         throw new ScannerException(
44                 "scanner.portal.search.unavailable.tournament.id", DOMAIN_2700CHESS
45         );
46     }
47
48     @Override
49     public PGNTournament findTournament(String tournamentName) throws ScannerException {
50         throw new ScannerException(
51                 "scanner.portal.search.unavailable.tournament.name", DOMAIN_2700CHESS
52         );
53     }
54
55     @Override
56     public PGNGame scanGame(String gameId) throws ScannerException {
57         return scanUrl(
58                 assignUrl(gameId)
59         );
60     }
61
62     @Override
63     public PGNGame scanGame(String gameId, String tournamentId) throws ScannerException {
64         return scanGame(gameId);
65     }
66
67     @Override
68     public PGNGame scanUrl(String gameUrl) throws ScannerException {
69         String pgn = match(
70                 gameUrl,
71                 getSettings().getGameUrlRegex()
72         );
73         if (pgn == null) {
74             throw new ScannerException(
75                     "scanner.failed.request.url", gameUrl
76             );
77         }
78         pgn = StringUtils.formatCrlf(pgn);
79         if (!StringUtils.isPgn(pgn)) {
80             throw new ScannerException(
81                     "scanner.incorrect.pgn.url", gameUrl
82             );
83         }
84         return new PGNGame(
85                 null,
86                 pgn
87         );
88     }
89
90 }