From 8132c02e9d31234ca27a0f1c3078d3595d5bcc81 Mon Sep 17 00:00:00 2001 From: Olyutorskii Date: Fri, 8 May 2020 14:05:53 +0900 Subject: [PATCH] split format templates. --- .../jp/sfjp/jindolf/config/ConfigDirUtils.java | 154 ++++++++++++--------- 1 file changed, 90 insertions(+), 64 deletions(-) diff --git a/src/main/java/jp/sfjp/jindolf/config/ConfigDirUtils.java b/src/main/java/jp/sfjp/jindolf/config/ConfigDirUtils.java index 17b8d57..c87f96f 100644 --- a/src/main/java/jp/sfjp/jindolf/config/ConfigDirUtils.java +++ b/src/main/java/jp/sfjp/jindolf/config/ConfigDirUtils.java @@ -25,6 +25,9 @@ import jp.sfjp.jindolf.view.LockErrorPane; /** * Jindolf設定格納ディレクトリに関するあれこれ。 + * + *

ファイル操作の異常系に関する、 + * ユーザとのインタラクション動作など。 */ public final class ConfigDirUtils{ @@ -53,7 +56,8 @@ public final class ConfigDirUtils{ + " ã‚ªãƒ—ション指定により、
" + "設定格納ディレクトリを使わずに起動することができます。
" + ""; - private static final String MSG_NOCONF = "" + private static final String MSG_NOCONF = + "" + "設定ディレクトリを使わずに起動を続行します。
" + "今回、各種設定の読み込み・保存はできません。
" + "" @@ -61,7 +65,13 @@ public final class ConfigDirUtils{ + " オプション" + "を使うとこの警告は出なくなります。" + ""; - private static final String FORM_FAILRM = "" + private static final String MSG_ABORT = + "" + + "設定ディレクトリの作成をせずに起動を中止します。
" + + MSG_POST + + ""; + private static final String FORM_FAILRM = + "" + "ロックファイルの強制解除に失敗しました。
" + "他に動いているJindolf" + "が見つからないのであれば、
" @@ -70,12 +80,51 @@ public final class ConfigDirUtils{ + "を削除してください。
" + "起動を中止します。" + ""; - private static final String FORM_ILLLOCK = "" + private static final String FORM_ILLLOCK = + "" + "ロックファイル
" + "{0}" + "を確保することができません。
" + "起動を中止します。" + ""; + private static final String FORM_MKDIRFAIL = + "" + + "ディレクトリ
" + + "{0}" + + "の作成に失敗しました。" + + "起動を中止します。
" + + MSG_POST + + ""; + private static final String FORM_ACCERR = + "" + + "ディレクトリ
" + + "{0}" + + "へのアクセスができません。" + + "起動を中止します。
" + + "このディレクトリへのアクセス権を調整し" + + "読み書きできるようにしてください。
" + + MSG_POST + + ""; + private static final String FORM_WRITEERR = + "" + + "ファイル
" + + "{0}" + + "への書き込みができません。" + + "起動を中止します。
" + + ""; + private static final String FORM_MKCONF = + "" + + "設定ファイル格納ディレクトリ
" + + "{0}を作成します。
" + + "このディレクトリを今から作成して構いませんか?
" + + "このディレクトリ名は、後からいつでもヘルプウィンドウで
" + + "確認することができます。" + + ""; + + private static final String LOG_MKDIRERR = + "ディレクトリ{0}を生成できません"; + private static final String LOG_CREATEERR = + "ファイル{0}を生成できません"; private static final int ERR_ABORT = 1; @@ -178,13 +227,7 @@ public final class ConfigDirUtils{ * VM終了する。 */ private static void abortQuitBuildConfigDir(){ - String msg = - "" - + "設定ディレクトリの作成をせずに起動を中止します。
" - + MSG_POST - + ""; - - showWarnMessage(msg); + showWarnMessage(MSG_ABORT); abort(); assert false; @@ -198,16 +241,8 @@ public final class ConfigDirUtils{ * @param path 生成できなかったディレクトリ */ private static void abortCantBuildDir(Path path){ - String form = - "" - + "ディレクトリ
" - + "{0}" - + "の作成に失敗しました。" - + "起動を中止します。
" - + MSG_POST - + ""; String fileName = getCenteredFileName(path); - String msg = MessageFormat.format(form, fileName); + String msg = MessageFormat.format(FORM_MKDIRFAIL, fileName); showErrorMessage(msg); abort(); @@ -223,18 +258,8 @@ public final class ConfigDirUtils{ * @param path アクセスできないディレクトリ */ private static void abortCantAccessDir(Path path){ - String form = - "" - + "ディレクトリ
" - + "{0}" - + "へのアクセスができません。" - + "起動を中止します。
" - + "このディレクトリへのアクセス権を調整し" - + "読み書きできるようにしてください。
" - + MSG_POST - + ""; String fileName = getCenteredFileName(path); - String msg = MessageFormat.format(form, fileName); + String msg = MessageFormat.format(FORM_ACCERR, fileName); showErrorMessage(msg); abort(); @@ -249,15 +274,8 @@ public final class ConfigDirUtils{ * @param path 書き込めなかったファイル */ private static void abortCantWrite(Path path){ - String form = - "" - + "ファイル
" - + "{0}" - + "への書き込みができません。" - + "起動を中止します。
" - + ""; String fileName = getCenteredFileName(path); - String msg = MessageFormat.format(form, fileName); + String msg = MessageFormat.format(FORM_WRITEERR, fileName); showErrorMessage(msg); abort(); @@ -267,6 +285,32 @@ public final class ConfigDirUtils{ } /** + * ディレクトリが生成できない異常系をログ出力する。 + * + * @param dirPath 生成できなかったディレクトリ + * @param cause 異常系原因 + */ + private static void logMkdirErr(Path dirPath, Throwable cause){ + String pathTxt = dirPath.toString(); + String msg = MessageFormat.format(LOG_MKDIRERR, pathTxt); + LOGGER.log(Level.SEVERE, msg, cause); + return; + } + + /** + * ファイルが生成できない異常系をログ出力する。 + * + * @param filePath 生成できなかったファイル + * @param cause 異常系原因 + */ + private static void logCreateErr(Path filePath, Throwable cause){ + String pathTxt = filePath.toString(); + String msg = MessageFormat.format(LOG_CREATEERR, pathTxt); + LOGGER.log(Level.SEVERE, msg, cause); + return; + } + + /** * 設定ディレクトリがアクセス可能でなければ * エラーダイアログを出してVM終了する。 * @@ -370,9 +414,7 @@ public final class ConfigDirUtils{ try{ Files.createDirectories(absPath); }catch(IOException | SecurityException e){ - String msg = MessageFormat.format( - "{0}を生成できません", absPath.toString()); - LOGGER.log(Level.SEVERE, msg, e); + logMkdirErr(absPath, e); abortCantBuildDir(absPath); assert false; } @@ -393,16 +435,8 @@ public final class ConfigDirUtils{ * @return 生成してよいと指示があればtrue */ private static boolean confirmBuildConfigDir(Path confDir){ - String form = - "" - + "設定ファイル格納ディレクトリ
" - + "{0}を作成します。
" - + "このディレクトリを今から作成して構いませんか?
" - + "このディレクトリ名は、後からいつでもヘルプウィンドウで
" - + "確認することができます。" - + ""; String confName = getCenteredFileName(confDir); - String msg = MessageFormat.format(form, confName); + String msg = MessageFormat.format(FORM_MKCONF, confName); JOptionPane pane; pane = new JOptionPane(msg, @@ -432,10 +466,8 @@ public final class ConfigDirUtils{ try{ Files.createDirectories(absPath); - }catch(IOException e){ - String msg = MessageFormat.format( - "ディレクトリ{0}を生成できません", absPath.toString()); - LOGGER.log(Level.SEVERE, msg, e); + }catch(IOException | SecurityException e){ + logMkdirErr(absPath, e); abortCantBuildDir(absPath); assert false; } @@ -448,11 +480,8 @@ public final class ConfigDirUtils{ ResourceManager.getResourceAsStream(RES_AVATARJSON)){ InputStream is = new BufferedInputStream(ris); Files.copy(is, jsonPath); - }catch(IOException e){ - String msg = MessageFormat.format( - "ファイル{0}を生成できませんでした", jsonPath.toString() - ); - LOGGER.log(Level.SEVERE, msg, e); + }catch(IOException | SecurityException e){ + logCreateErr(jsonPath, e); abortCantWrite(jsonPath); assert false; } @@ -558,11 +587,8 @@ public final class ConfigDirUtils{ ResourceManager.getResourceAsStream(RES_README)){ InputStream is = new BufferedInputStream(ris); Files.copy(is, readme); - }catch(IOException e){ - String msg = MessageFormat.format( - "{0}が生成できませんでした", readme.toString() - ); - LOGGER.log(Level.SEVERE, msg, e); + }catch(IOException | SecurityException e){ + logCreateErr(readme, e); abortCantWrite(readme); assert false; } -- 2.11.0