From: gotty Date: Wed, 22 Jan 2020 02:04:59 +0000 (+0300) Subject: [LIB-13] Locale resource settings X-Git-Url: https://git.hedgecode.org/?a=commitdiff_plain;h=d0c369def92e6876e8f37d257e2fe1b38013b005;p=chesshog-scanner.git [LIB-13] Locale resource settings --- diff --git a/src/main/java/org/hedgecode/chess/scanner/ChessHogScanner.java b/src/main/java/org/hedgecode/chess/scanner/ChessHogScanner.java index 3ea995c..87037de 100644 --- a/src/main/java/org/hedgecode/chess/scanner/ChessHogScanner.java +++ b/src/main/java/org/hedgecode/chess/scanner/ChessHogScanner.java @@ -76,13 +76,13 @@ public final class ChessHogScanner { hostName = new URL(url).getHost(); } catch (MalformedURLException cause) { throw new ScannerException( - String.format("Incorrect URL: %s", url), cause + "scanner.incorrect.url", cause, url ); } ScannerType type = ScannerType.byHost(hostName); if (type == null) { throw new ScannerException( - String.format("Host %s is not among the known for the scanner", hostName) + "scanner.host.unknown", hostName ); } return scanner(type).scanUrl(url); diff --git a/src/main/java/org/hedgecode/chess/scanner/ScannerException.java b/src/main/java/org/hedgecode/chess/scanner/ScannerException.java index 0ea2872..856dd5d 100644 --- a/src/main/java/org/hedgecode/chess/scanner/ScannerException.java +++ b/src/main/java/org/hedgecode/chess/scanner/ScannerException.java @@ -16,6 +16,8 @@ package org.hedgecode.chess.scanner; +import java.util.ResourceBundle; + /** * ScannerException * @@ -23,16 +25,24 @@ package org.hedgecode.chess.scanner; */ public class ScannerException extends Exception { - public ScannerException(String message) { - super(message); - } + private static final ResourceBundle LOCALE_BUNDLE = + ResourceBundle.getBundle(ScannerConstants.LOCALE_BUNDLE_FILE); - public ScannerException(Throwable cause) { - super(cause); + public ScannerException(String key, Object... args) { + super( + String.format( + LOCALE_BUNDLE.getString(key), args + ) + ); } - public ScannerException(String message, Throwable cause) { - super(message, cause); + public ScannerException(String key, Throwable cause, Object... args) { + super( + String.format( + LOCALE_BUNDLE.getString(key), args + ), + cause + ); } } diff --git a/src/main/java/org/hedgecode/chess/scanner/json/JSONSettingsBuilder.java b/src/main/java/org/hedgecode/chess/scanner/json/JSONSettingsBuilder.java index e0ddbcc..3431cb5 100644 --- a/src/main/java/org/hedgecode/chess/scanner/json/JSONSettingsBuilder.java +++ b/src/main/java/org/hedgecode/chess/scanner/json/JSONSettingsBuilder.java @@ -54,7 +54,7 @@ public class JSONSettingsBuilder implements SettingsBuilder { ); } catch (IOException cause) { throw new ScannerException( - String.format("Failed to get settings from resource file: %s", jsonFileName), cause + "scanner.failed.settings", cause, jsonFileName ); } return settings; diff --git a/src/main/java/org/hedgecode/chess/scanner/portal/AbstractRequestScanner.java b/src/main/java/org/hedgecode/chess/scanner/portal/AbstractRequestScanner.java index d6aa38b..1ed66d5 100644 --- a/src/main/java/org/hedgecode/chess/scanner/portal/AbstractRequestScanner.java +++ b/src/main/java/org/hedgecode/chess/scanner/portal/AbstractRequestScanner.java @@ -68,7 +68,7 @@ public abstract class AbstractRequestScanner implements Scanner { } } catch (IOException cause) { throw new ScannerException( - String.format("Error occurred for requesting URL: %s", url), cause + "scanner.request.error", cause, url ); } return sb.toString(); @@ -181,7 +181,7 @@ public abstract class AbstractRequestScanner implements Scanner { } } catch (IOException cause) { throw new ScannerException( - String.format("Error occurred for requesting URL: %s", url), cause + "scanner.request.error", cause, url ); } return matcher.result(); diff --git a/src/main/java/org/hedgecode/chess/scanner/portal/AbstractSettingsScanner.java b/src/main/java/org/hedgecode/chess/scanner/portal/AbstractSettingsScanner.java index 4126115..a4dcfad 100644 --- a/src/main/java/org/hedgecode/chess/scanner/portal/AbstractSettingsScanner.java +++ b/src/main/java/org/hedgecode/chess/scanner/portal/AbstractSettingsScanner.java @@ -16,9 +16,6 @@ package org.hedgecode.chess.scanner.portal; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import org.hedgecode.chess.scanner.Initiable; import org.hedgecode.chess.scanner.ScannerException; import org.hedgecode.chess.scanner.Settings; diff --git a/src/main/java/org/hedgecode/chess/scanner/portal/Chess24Scanner.java b/src/main/java/org/hedgecode/chess/scanner/portal/Chess24Scanner.java index 476bc7e..b89ef0c 100644 --- a/src/main/java/org/hedgecode/chess/scanner/portal/Chess24Scanner.java +++ b/src/main/java/org/hedgecode/chess/scanner/portal/Chess24Scanner.java @@ -21,6 +21,8 @@ import org.hedgecode.chess.scanner.ScannerException; import org.hedgecode.chess.scanner.entity.PGNGame; import org.hedgecode.chess.scanner.entity.PGNTournament; +import static org.hedgecode.chess.scanner.ScannerConstants.*; + /** * Chess24Scanner * @@ -38,14 +40,14 @@ public class Chess24Scanner extends AbstractSettingsScanner implements Scanner { @Override public PGNTournament scanTournament(String tournamentId) throws ScannerException { throw new ScannerException( - "The scanner functional of portal chess24.com is under development!" + "scanner.portal.under.development", DOMAIN_CHESS24 ); } @Override public PGNTournament findTournament(String tournamentName) throws ScannerException { throw new ScannerException( - "The scanner functional of portal chess24.com is under development!" + "scanner.portal.under.development", DOMAIN_CHESS24 ); } @@ -57,14 +59,14 @@ public class Chess24Scanner extends AbstractSettingsScanner implements Scanner { @Override public PGNGame scanGame(String gameId, String tournamentId) throws ScannerException { throw new ScannerException( - "The scanner functional of portal chess24.com is under development!" + "scanner.portal.under.development", DOMAIN_CHESS24 ); } @Override public PGNGame scanUrl(String gameUrl) throws ScannerException { throw new ScannerException( - "The scanner functional of portal chess24.com is under development!" + "scanner.portal.under.development", DOMAIN_CHESS24 ); } diff --git a/src/main/java/org/hedgecode/chess/scanner/portal/Chess2700Scanner.java b/src/main/java/org/hedgecode/chess/scanner/portal/Chess2700Scanner.java index ac0c8f3..e90b66d 100644 --- a/src/main/java/org/hedgecode/chess/scanner/portal/Chess2700Scanner.java +++ b/src/main/java/org/hedgecode/chess/scanner/portal/Chess2700Scanner.java @@ -22,6 +22,8 @@ import org.hedgecode.chess.scanner.StringUtils; import org.hedgecode.chess.scanner.entity.PGNGame; import org.hedgecode.chess.scanner.entity.PGNTournament; +import static org.hedgecode.chess.scanner.ScannerConstants.*; + /** * Chess2700Scanner * @@ -39,14 +41,14 @@ public class Chess2700Scanner extends AbstractSettingsScanner implements Scanner @Override public PGNTournament scanTournament(String tournamentId) throws ScannerException { throw new ScannerException( - "2700Chess does not support searching for a tournament by ID!" + "scanner.portal.search.unavailable.tournament.id", DOMAIN_2700CHESS ); } @Override public PGNTournament findTournament(String tournamentName) throws ScannerException { throw new ScannerException( - "2700Chess does not support searching for a tournament by name!" + "scanner.portal.search.unavailable.tournament.name", DOMAIN_2700CHESS ); } @@ -70,13 +72,13 @@ public class Chess2700Scanner extends AbstractSettingsScanner implements Scanner ); if (pgn == null) { throw new ScannerException( - String.format("Failed to get PGN for requesting URL: %s", gameUrl) + "scanner.failed.request.url", gameUrl ); } pgn = StringUtils.formatCrlf(pgn); if (!StringUtils.isPgn(pgn)) { throw new ScannerException( - String.format("Incorrect PGN for requesting URL: %s", gameUrl) + "scanner.incorrect.pgn.url", gameUrl ); } return new PGNGame( diff --git a/src/main/java/org/hedgecode/chess/scanner/portal/ChessBombScanner.java b/src/main/java/org/hedgecode/chess/scanner/portal/ChessBombScanner.java index 096a36e..96e90e8 100644 --- a/src/main/java/org/hedgecode/chess/scanner/portal/ChessBombScanner.java +++ b/src/main/java/org/hedgecode/chess/scanner/portal/ChessBombScanner.java @@ -27,6 +27,8 @@ import org.hedgecode.chess.scanner.format.chessbomb.Format; import org.hedgecode.chess.scanner.format.chessbomb.GameFormat; import org.hedgecode.chess.scanner.format.chessbomb.TournamentFormat; +import static org.hedgecode.chess.scanner.ScannerConstants.*; + /** * ChessBombScanner * @@ -82,7 +84,7 @@ public class ChessBombScanner extends AbstractSettingsScanner implements Scanner @Override public PGNGame scanGame(String gameId) throws ScannerException { throw new ScannerException( - "ChessBomb does not support searching game without a tournament name!" + "scanner.portal.search.without.tournament.name", DOMAIN_CHESSBOMB ); } @@ -124,7 +126,7 @@ public class ChessBombScanner extends AbstractSettingsScanner implements Scanner ); if (encodeString == null) { throw new ScannerException( - String.format("Failed to decode source data for requesting URL: %s", url) + "scanner.failed.decode.url", url ); } return new String( diff --git a/src/main/java/org/hedgecode/chess/scanner/portal/ChessComScanner.java b/src/main/java/org/hedgecode/chess/scanner/portal/ChessComScanner.java index 313d8e0..1827b3c 100644 --- a/src/main/java/org/hedgecode/chess/scanner/portal/ChessComScanner.java +++ b/src/main/java/org/hedgecode/chess/scanner/portal/ChessComScanner.java @@ -21,6 +21,8 @@ import org.hedgecode.chess.scanner.ScannerException; import org.hedgecode.chess.scanner.entity.PGNGame; import org.hedgecode.chess.scanner.entity.PGNTournament; +import static org.hedgecode.chess.scanner.ScannerConstants.*; + /** * ChessComScanner * @@ -38,14 +40,14 @@ public class ChessComScanner extends AbstractSettingsScanner implements Scanner @Override public PGNTournament scanTournament(String tournamentId) throws ScannerException { throw new ScannerException( - "The scanner functional of portal chess.com is under development!" + "scanner.portal.under.development", DOMAIN_CHESSCOM ); } @Override public PGNTournament findTournament(String tournamentName) throws ScannerException { throw new ScannerException( - "The scanner functional of portal chess.com is under development!" + "scanner.portal.under.development", DOMAIN_CHESSCOM ); } @@ -57,14 +59,14 @@ public class ChessComScanner extends AbstractSettingsScanner implements Scanner @Override public PGNGame scanGame(String gameId, String tournamentId) throws ScannerException { throw new ScannerException( - "The scanner functional of portal chess.com is under development!" + "scanner.portal.under.development", DOMAIN_CHESSCOM ); } @Override public PGNGame scanUrl(String gameUrl) throws ScannerException { throw new ScannerException( - "The scanner functional of portal chess.com is under development!" + "scanner.portal.under.development", DOMAIN_CHESSCOM ); } diff --git a/src/main/java/org/hedgecode/chess/scanner/portal/ChessGamesScanner.java b/src/main/java/org/hedgecode/chess/scanner/portal/ChessGamesScanner.java index 56fc032..392f398 100644 --- a/src/main/java/org/hedgecode/chess/scanner/portal/ChessGamesScanner.java +++ b/src/main/java/org/hedgecode/chess/scanner/portal/ChessGamesScanner.java @@ -78,7 +78,7 @@ public class ChessGamesScanner extends AbstractSettingsScanner implements Scanne ); if (!StringUtils.isPgn(pgn)) { throw new ScannerException( - String.format("Failed to get PGN for requesting game ID: %s", gameId) + "scanner.failed.request.game", gameId ); } return new PGNGame( @@ -100,7 +100,7 @@ public class ChessGamesScanner extends AbstractSettingsScanner implements Scanne ); if (pgn == null || !StringUtils.isPgn(pgn)) { throw new ScannerException( - String.format("Failed to get PGN for requesting URL: %s", gameUrl) + "scanner.failed.request.url", gameUrl ); } return new PGNGame( diff --git a/src/main/java/org/hedgecode/chess/scanner/portal/LiChessScanner.java b/src/main/java/org/hedgecode/chess/scanner/portal/LiChessScanner.java index 820e513..eac5047 100644 --- a/src/main/java/org/hedgecode/chess/scanner/portal/LiChessScanner.java +++ b/src/main/java/org/hedgecode/chess/scanner/portal/LiChessScanner.java @@ -28,6 +28,7 @@ import org.hedgecode.chess.scanner.entity.PGNTournament; import org.hedgecode.chess.scanner.format.lichess.Format; import org.hedgecode.chess.scanner.format.lichess.GameFormat; +import static org.hedgecode.chess.scanner.ScannerConstants.*; import static org.hedgecode.chess.scanner.format.PGNConstants.*; /** @@ -54,7 +55,7 @@ public class LiChessScanner extends AbstractSettingsScanner implements Scanner { @Override public PGNTournament findTournament(String tournamentName) throws ScannerException { throw new ScannerException( - "Lichess does not support searching for a tournament by name!" + "scanner.portal.search.unavailable,name", DOMAIN_LICHESS ); } @@ -65,7 +66,7 @@ public class LiChessScanner extends AbstractSettingsScanner implements Scanner { ); if (!StringUtils.isPgn(pgn)) { throw new ScannerException( - String.format("Failed to get PGN for requesting game ID: %s", gameId) + "scanner.failed.request.game", gameId ); } return new PGNGame( @@ -92,7 +93,7 @@ public class LiChessScanner extends AbstractSettingsScanner implements Scanner { ); if (pgn == null) { throw new ScannerException( - String.format("Failed to get source data for requesting URL: %s", gameUrl) + "scanner.failed.source.data", gameUrl ); } GameFormat gameFormat = Format.formatGame(pgn); @@ -104,7 +105,7 @@ public class LiChessScanner extends AbstractSettingsScanner implements Scanner { pgn = StringEscapeUtils.unescapeHtml4(pgn); if (!StringUtils.isPgn(pgn)) { throw new ScannerException( - String.format("Failed to get PGN for requesting URL: %s", gameUrl) + "scanner.failed.request.url", gameUrl ); } return new PGNGame( diff --git a/src/main/resources/org/hedgecode/chess/scanner/LocalStrings.properties b/src/main/resources/org/hedgecode/chess/scanner/LocalStrings.properties new file mode 100644 index 0000000..0013b2a --- /dev/null +++ b/src/main/resources/org/hedgecode/chess/scanner/LocalStrings.properties @@ -0,0 +1,30 @@ +# 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. + +# Default localized string information +# Localized for Locale en_US + +scanner.incorrect.url=Incorrect URL: %s +scanner.incorrect.pgn.url=Incorrect PGN for requesting URL: %s +scanner.host.unknown=Host %s is not among the known for the scanner +scanner.request.error=Error occurred for requesting URL: %s +scanner.failed.settings=Failed to get settings from resource file: %s +scanner.failed.request.game=Failed to get PGN for requesting game ID: %s +scanner.failed.request.url=Failed to get PGN for requesting URL: %s +scanner.failed.source.data=Failed to get source data for requesting URL: %s +scanner.failed.decode.url=Failed to decode source data for requesting URL: %s +scanner.portal.under.development=The scanner functional of portal %s is under development +scanner.portal.search.unavailable.tournament.id=%s does not support searching for a tournament by ID +scanner.portal.search.unavailable.tournament.name=%s does not support searching for a tournament by name +scanner.portal.search.without.tournament.name=%s does not support searching game without a tournament name diff --git a/src/main/resources/org/hedgecode/chess/scanner/LocalStrings_ru.properties b/src/main/resources/org/hedgecode/chess/scanner/LocalStrings_ru.properties new file mode 100644 index 0000000..535f1b7 --- /dev/null +++ b/src/main/resources/org/hedgecode/chess/scanner/LocalStrings_ru.properties @@ -0,0 +1,29 @@ +# 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. + +# Localized for Locale ru_RU + +scanner.incorrect.url=\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 URL: %s +scanner.incorrect.pgn.url=\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 PGN \u043F\u043E \u0437\u0430\u043F\u0440\u043E\u0441\u0443 URL: %s +scanner.host.unknown=\u0425\u043E\u0441\u0442 %s \u043D\u0435 \u0432\u0445\u043E\u0434\u0438\u0442 \u0432 \u0447\u0438\u0441\u043B\u043E \u0438\u0437\u0432\u0435\u0441\u0442\u043D\u044B\u0445 \u0441\u043A\u0430\u043D\u0435\u0440\u0443 +scanner.request.error=\u041F\u0440\u043E\u0438\u0437\u043E\u0448\u043B\u0430 \u043E\u0448\u0438\u0431\u043A\u0430 \u043F\u043E \u0437\u0430\u043F\u0440\u043E\u0441\u0443 URL: %s +scanner.failed.settings=\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u043E\u043B\u0443\u0447\u0438\u0442\u044C \u043D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0438 \u0438\u0437 \u0444\u0430\u0439\u043B\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u043E\u0432: %s +scanner.failed.request.game=\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u043E\u043B\u0443\u0447\u0438\u0442\u044C PGN \u043F\u043E \u0437\u0430\u043F\u0440\u043E\u0441\u0443 ID \u043F\u0430\u0440\u0442\u0438\u0438: %s +scanner.failed.request.url=\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u043E\u043B\u0443\u0447\u0438\u0442\u044C PGN \u043F\u043E \u0437\u0430\u043F\u0440\u043E\u0441\u0443 URL: %s +scanner.failed.source.data=\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u043E\u043B\u0443\u0447\u0438\u0442\u044C \u0434\u0430\u043D\u043D\u044B\u0435 \u043F\u043E \u0437\u0430\u043F\u0440\u043E\u0441\u0443 URL: %s +scanner.failed.decode.url=\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0434\u0435\u043A\u043E\u0434\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u0434\u0430\u043D\u043D\u044B\u0435 \u043F\u043E \u0437\u0430\u043F\u0440\u043E\u0441\u0443 URL: %s +scanner.portal.under.development=\u0424\u0443\u043D\u043A\u0446\u0438\u043E\u043D\u0430\u043B \u0441\u043A\u0430\u043D\u0435\u0440\u0430 \u043F\u043E\u0440\u0442\u0430\u043B\u0430 %s \u043D\u0430\u0445\u043E\u0434\u0438\u0442\u0441\u044F \u0432 \u0441\u0442\u0430\u0434\u0438\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043E\u0442\u043A\u0438 +scanner.portal.search.unavailable.tournament.id=%s \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043F\u043E\u0438\u0441\u043A \u0442\u0443\u0440\u043D\u0438\u0440\u0430 \u043F\u043E ID +scanner.portal.search.unavailable.tournament.name=%s \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043F\u043E\u0438\u0441\u043A \u0442\u0443\u0440\u043D\u0438\u0440\u0430 \u043F\u043E \u0438\u043C\u0435\u043D\u0438 +scanner.portal.search.without.tournament.name=%s \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043F\u043E\u0438\u0441\u043A \u0438\u0433\u0440\u044B \u0431\u0435\u0437 \u043D\u0430\u0437\u0432\u0430\u043D\u0438\u044F \u0442\u0443\u0440\u043D\u0438\u0440\u0430