import java.util.List;
import java.util.Map;
-import org.hedgecode.chess.scanner.ChessHogScannerException;
+import org.hedgecode.chess.scanner.Scanner;
+import org.hedgecode.chess.scanner.ScannerException;
+import org.hedgecode.chess.scanner.StringUtils;
import org.hedgecode.chess.scanner.entity.PGNGame;
import org.hedgecode.chess.scanner.entity.PGNTournament;
*
* @author Dmitry Samoshin aka gotty
*/
-public class ChessGamesScanner extends AbstractSettingsScanner {
+public class ChessGamesScanner extends AbstractSettingsScanner implements Scanner {
private static final String SETTINGS_FILENAME = "chessgames.settings";
}
@Override
- public PGNTournament scanTournament(String tournamentId) throws ChessHogScannerException {
+ public PGNTournament scanTournament(String tournamentId) throws ScannerException {
PGNTournament tournament = new PGNTournament(tournamentId);
assignTournamentGames(tournament);
return tournament;
}
@Override
- public PGNTournament findTournament(String tournamentName) throws ChessHogScannerException {
+ public PGNTournament findTournament(String tournamentName) throws ScannerException {
PGNTournament tournament = null;
Map<String, String> result = matchMap(
assignUrl(
}
@Override
- public PGNGame scanGame(String gameId) throws ChessHogScannerException {
+ public PGNGame scanGame(String gameId) throws ScannerException {
String pgn = request(
assignUrl(gameId)
);
- if (!isPgnFormat(pgn)) {
- throw new ChessHogScannerException(
+ if (!StringUtils.isPgn(pgn)) {
+ throw new ScannerException(
String.format("Failed to get PGN for requesting game ID: %s", gameId)
);
}
}
@Override
- public PGNGame scanGame(String gameId, String tournamentId) throws ChessHogScannerException {
+ public PGNGame scanGame(String gameId, String tournamentId) throws ScannerException {
return scanGame(gameId);
}
@Override
- public PGNGame scanUrl(String gameUrl) throws ChessHogScannerException {
- String pgn = regex(
- request(
- gameUrl
- ),
+ public PGNGame scanUrl(String gameUrl) throws ScannerException {
+ String gamePage = request(gameUrl);
+ String pgn = StringUtils.match(
+ gamePage,
getSettings().getGameUrlRegex()
);
- if (pgn == null || !isPgnFormat(pgn)) {
- throw new ChessHogScannerException(
+ if (pgn == null || !StringUtils.isPgn(pgn)) {
+ throw new ScannerException(
String.format("Failed to get PGN for requesting URL: %s", gameUrl)
);
}
);
}
- private void assignTournamentGames(PGNTournament tournament) throws ChessHogScannerException {
+ private void assignTournamentGames(PGNTournament tournament) throws ScannerException {
tournament.clearGames();
List<String> gamesId = new ArrayList<>();