Browse Source

fix #2654 add validation

Shinsuke Sugaya 3 years ago
parent
commit
5762adcf9c

+ 15 - 0
src/main/java/org/codelibs/fess/app/web/admin/dict/kuromoji/AdminDictKuromojiAction.java

@@ -278,6 +278,7 @@ public class AdminDictKuromojiAction extends FessAdminAction {
     public HtmlResponse create(final CreateForm form) {
     public HtmlResponse create(final CreateForm form) {
         verifyCrudMode(form.crudMode, CrudMode.CREATE, form.dictId);
         verifyCrudMode(form.crudMode, CrudMode.CREATE, form.dictId);
         validate(form, messages -> {}, this::asEditHtml);
         validate(form, messages -> {}, this::asEditHtml);
+        verifyForm(form);
         verifyToken(this::asEditHtml);
         verifyToken(this::asEditHtml);
         createKuromojiItem(form, this::asEditHtml).ifPresent(entity -> {
         createKuromojiItem(form, this::asEditHtml).ifPresent(entity -> {
             try {
             try {
@@ -298,6 +299,7 @@ public class AdminDictKuromojiAction extends FessAdminAction {
     public HtmlResponse update(final EditForm form) {
     public HtmlResponse update(final EditForm form) {
         verifyCrudMode(form.crudMode, CrudMode.EDIT, form.dictId);
         verifyCrudMode(form.crudMode, CrudMode.EDIT, form.dictId);
         validate(form, messages -> {}, this::asEditHtml);
         validate(form, messages -> {}, this::asEditHtml);
+        verifyForm(form);
         verifyToken(this::asEditHtml);
         verifyToken(this::asEditHtml);
         createKuromojiItem(form, this::asEditHtml).ifPresent(entity -> {
         createKuromojiItem(form, this::asEditHtml).ifPresent(entity -> {
             try {
             try {
@@ -384,6 +386,19 @@ public class AdminDictKuromojiAction extends FessAdminAction {
         }
         }
     }
     }
 
 
+    protected void verifyForm(final CreateForm form) {
+        if (form.token != null && form.token.split(" ").length > 1) {
+            throwValidationError(messages -> {
+                messages.addErrorsInvalidKuromojiToken("token", form.token);
+            }, this::asEditHtml);
+        }
+        if (form.segmentation != null && form.reading != null && form.segmentation.split(" ").length != form.reading.split(" ").length) {
+            throwValidationError(messages -> {
+                messages.addErrorsInvalidKuromojiSegmentation("segmentation", form.segmentation, form.reading);
+            }, this::asEditHtml);
+        }
+    }
+
     // ===================================================================================
     // ===================================================================================
     //                                                                              JSP
     //                                                                              JSP
     //                                                                           =========
     //                                                                           =========

+ 37 - 0
src/main/java/org/codelibs/fess/mylasta/action/FessMessages.java

@@ -293,6 +293,12 @@ public class FessMessages extends FessLabels {
     /** The key of the message: Failed to upload the Mapping file. */
     /** The key of the message: Failed to upload the Mapping file. */
     public static final String ERRORS_failed_to_upload_mapping_file = "{errors.failed_to_upload_mapping_file}";
     public static final String ERRORS_failed_to_upload_mapping_file = "{errors.failed_to_upload_mapping_file}";
 
 
+    /** The key of the message: {0} is invalid. */
+    public static final String ERRORS_invalid_kuromoji_token = "{errors.invalid_kuromoji_token}";
+
+    /** The key of the message: The number of segmentations {0} does not the match number of readings {1}. */
+    public static final String ERRORS_invalid_kuromoji_segmentation = "{errors.invalid_kuromoji_segmentation}";
+
     /** The key of the message: "{1}" in "{0}" is invalid. */
     /** The key of the message: "{1}" in "{0}" is invalid. */
     public static final String ERRORS_invalid_str_is_included = "{errors.invalid_str_is_included}";
     public static final String ERRORS_invalid_str_is_included = "{errors.invalid_str_is_included}";
 
 
@@ -1809,6 +1815,37 @@ public class FessMessages extends FessLabels {
         return this;
         return this;
     }
     }
 
 
+    /**
+     * Add the created action message for the key 'errors.invalid_kuromoji_token' with parameters.
+     * <pre>
+     * message: {0} is invalid.
+     * </pre>
+     * @param property The property name for the message. (NotNull)
+     * @param arg0 The parameter arg0 for message. (NotNull)
+     * @return this. (NotNull)
+     */
+    public FessMessages addErrorsInvalidKuromojiToken(String property, String arg0) {
+        assertPropertyNotNull(property);
+        add(property, new UserMessage(ERRORS_invalid_kuromoji_token, arg0));
+        return this;
+    }
+
+    /**
+     * Add the created action message for the key 'errors.invalid_kuromoji_segmentation' with parameters.
+     * <pre>
+     * message: The number of segmentations {0} does not the match number of readings {1}.
+     * </pre>
+     * @param property The property name for the message. (NotNull)
+     * @param arg0 The parameter arg0 for message. (NotNull)
+     * @param arg1 The parameter arg1 for message. (NotNull)
+     * @return this. (NotNull)
+     */
+    public FessMessages addErrorsInvalidKuromojiSegmentation(String property, String arg0, String arg1) {
+        assertPropertyNotNull(property);
+        add(property, new UserMessage(ERRORS_invalid_kuromoji_segmentation, arg0, arg1));
+        return this;
+    }
+
     /**
     /**
      * Add the created action message for the key 'errors.invalid_str_is_included' with parameters.
      * Add the created action message for the key 'errors.invalid_str_is_included' with parameters.
      * <pre>
      * <pre>

+ 2 - 0
src/main/resources/fess_message.properties

@@ -119,6 +119,8 @@ errors.failed_to_download_badword_file=Failed to download the Badword file.
 errors.failed_to_upload_badword_file=Failed to upload the Badword file.
 errors.failed_to_upload_badword_file=Failed to upload the Badword file.
 errors.failed_to_download_mapping_file=Failed to download the Mapping file.
 errors.failed_to_download_mapping_file=Failed to download the Mapping file.
 errors.failed_to_upload_mapping_file=Failed to upload the Mapping file.
 errors.failed_to_upload_mapping_file=Failed to upload the Mapping file.
+errors.invalid_kuromoji_token={0} is invalid.
+errors.invalid_kuromoji_segmentation=The number of segmentations {0} does not the match number of readings {1}.
 errors.invalid_str_is_included="{1}" in "{0}" is invalid.
 errors.invalid_str_is_included="{1}" in "{0}" is invalid.
 errors.blank_password=Password is required.
 errors.blank_password=Password is required.
 errors.invalid_confirm_password=Confirm Password does not match.
 errors.invalid_confirm_password=Confirm Password does not match.

+ 2 - 0
src/main/resources/fess_message_en.properties

@@ -115,6 +115,8 @@ errors.failed_to_download_badword_file=Failed to download the Badword file.
 errors.failed_to_upload_badword_file=Failed to upload the Badword file.
 errors.failed_to_upload_badword_file=Failed to upload the Badword file.
 errors.failed_to_download_mapping_file=Failed to download the Mapping file.
 errors.failed_to_download_mapping_file=Failed to download the Mapping file.
 errors.failed_to_upload_mapping_file=Failed to upload the Mapping file.
 errors.failed_to_upload_mapping_file=Failed to upload the Mapping file.
+errors.invalid_kuromoji_token={0} is invalid.
+errors.invalid_kuromoji_segmentation=The number of segmentations {0} does not the match number of readings {1}.
 errors.invalid_str_is_included="{1}" in "{0}" is invalid.
 errors.invalid_str_is_included="{1}" in "{0}" is invalid.
 errors.blank_password=Password is required.
 errors.blank_password=Password is required.
 errors.invalid_confirm_password=Confirm Password does not match.
 errors.invalid_confirm_password=Confirm Password does not match.

+ 2 - 0
src/main/resources/fess_message_ja.properties

@@ -111,6 +111,8 @@ errors.failed_to_download_badword_file = 除外ワードファイルのダウン
 errors.failed_to_upload_badword_file = 除外ワードファイルのアップロードに失敗しました。
 errors.failed_to_upload_badword_file = 除外ワードファイルのアップロードに失敗しました。
 errors.failed_to_download_mapping_file = マッピングファイルのダウンロードに失敗しました。
 errors.failed_to_download_mapping_file = マッピングファイルのダウンロードに失敗しました。
 errors.failed_to_upload_mapping_file = マッピングファイルのアップロードに失敗しました。
 errors.failed_to_upload_mapping_file = マッピングファイルのアップロードに失敗しました。
+errors.invalid_kuromoji_token={0} はトークンとして正しくありません。
+errors.invalid_kuromoji_segmentation={0} の分割数と {1}の分割数が一致しません。
 errors.invalid_str_is_included = {0}では{1}は無効です。
 errors.invalid_str_is_included = {0}では{1}は無効です。
 errors.blank_password = パスワードが必要になります。
 errors.blank_password = パスワードが必要になります。
 errors.invalid_confirm_password = パスワードの確認と一致しません。
 errors.invalid_confirm_password = パスワードの確認と一致しません。

+ 2 - 0
src/main/resources/fess_message_ru.properties

@@ -111,6 +111,8 @@ errors.failed_to_download_protwords_file=Failed to download the Protwords file.
 errors.failed_to_upload_protwords_file=Failed to upload the Protwords file.
 errors.failed_to_upload_protwords_file=Failed to upload the Protwords file.
 errors.failed_to_download_mapping_file=Failed to download the Mapping file.
 errors.failed_to_download_mapping_file=Failed to download the Mapping file.
 errors.failed_to_upload_mapping_file=Failed to upload the Mapping file.
 errors.failed_to_upload_mapping_file=Failed to upload the Mapping file.
+errors.invalid_kuromoji_token={0} is invalid.
+errors.invalid_kuromoji_segmentation=The number of segmentations {0} does not the match number of readings {1}.
 errors.invalid_str_is_included="{1}" in "{0}" is invalid.
 errors.invalid_str_is_included="{1}" in "{0}" is invalid.
 errors.blank_password=Password is required.
 errors.blank_password=Password is required.
 errors.invalid_confirm_password=Confirm Password does not match.
 errors.invalid_confirm_password=Confirm Password does not match.