浏览代码

migrating preview actions to lasta way

jflute 10 年之前
父节点
当前提交
bb2ae07102

+ 0 - 326
src/main/java/org/codelibs/fess/app/web/admin/KeyMatchAction.java

@@ -1,326 +0,0 @@
-/*
- * Copyright 2009-2015 the CodeLibs Project and the Others.
- *
- * 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.
- */
-
-package org.codelibs.fess.app.web.admin;
-
-import java.beans.Beans;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Resource;
-
-import org.codelibs.core.beans.util.BeanUtil;
-import org.codelibs.fess.annotation.Token;
-import org.codelibs.fess.app.web.base.FessAdminAction;
-import org.codelibs.fess.beans.FessBeans;
-import org.codelibs.fess.crud.CommonConstants;
-import org.codelibs.fess.crud.CrudMessageException;
-import org.codelibs.fess.crud.util.SAStrutsUtil;
-import org.codelibs.fess.es.exentity.KeyMatch;
-import org.codelibs.fess.exception.SSCActionMessagesException;
-import org.codelibs.fess.helper.SystemHelper;
-import org.codelibs.fess.pager.KeyMatchPager;
-import org.codelibs.fess.service.KeyMatchService;
-import org.codelibs.fess.util.ComponentUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class KeyMatchAction extends FessAdminAction {
-
-    private static final Logger logger = LoggerFactory.getLogger(KeyMatchAction.class);
-
-    // for list
-
-    public List<KeyMatch> keyMatchItems;
-
-    // for edit/confirm/delete
-
-    //@ActionForm
-    @Resource
-    protected KeyMatchForm keyMatchForm;
-
-    @Resource
-    protected KeyMatchService keyMatchService;
-
-    @Resource
-    protected KeyMatchPager keyMatchPager;
-
-    @Resource
-    protected SystemHelper systemHelper;
-
-    public String getHelpLink() {
-        return systemHelper.getHelpLink("keyMatch");
-    }
-
-    protected String displayList(final boolean redirect) {
-        // page navi
-        keyMatchItems = keyMatchService.getKeyMatchList(keyMatchPager);
-
-        // restore from pager
-        BeanUtil.copyBeanToBean(keyMatchPager, keyMatchForm.searchParams, option -> option.exclude(CommonConstants.PAGER_CONVERSION_RULE));
-
-        if (redirect) {
-            return "index?redirect=true";
-        } else {
-            return "index.jsp";
-        }
-    }
-
-    //@Execute(validator = false, input = "error.jsp")
-    public String index() {
-        return displayList(false);
-    }
-
-    //@Execute(validator = false, input = "error.jsp", urlPattern = "list/{pageNumber}")
-    public String list() {
-        // page navi
-        if (StringUtil.isNotBlank(keyMatchForm.pageNumber)) {
-            try {
-                keyMatchPager.setCurrentPageNumber(Integer.parseInt(keyMatchForm.pageNumber));
-            } catch (final NumberFormatException e) {
-                if (logger.isDebugEnabled()) {
-                    logger.debug("Invalid value: " + keyMatchForm.pageNumber, e);
-                }
-            }
-        }
-
-        return displayList(false);
-    }
-
-    //@Execute(validator = false, input = "error.jsp")
-    public String search() {
-        BeanUtil.copyBeanToBean(keyMatchForm.searchParams, keyMatchPager, option -> option.exclude(CommonConstants.PAGER_CONVERSION_RULE));
-
-        return displayList(false);
-    }
-
-    //@Execute(validator = false, input = "error.jsp")
-    public String reset() {
-        keyMatchPager.clear();
-
-        return displayList(false);
-    }
-
-    //@Execute(validator = false, input = "error.jsp")
-    public String back() {
-        return displayList(false);
-    }
-
-    @Token(save = true, validate = false)
-    //@Execute(validator = false, input = "error.jsp")
-    public String editagain() {
-        return "edit.jsp";
-    }
-
-    //@Execute(validator = false, input = "error.jsp", urlPattern = "confirmpage/{crudMode}/{id}")
-    public String confirmpage() {
-        if (keyMatchForm.crudMode != CommonConstants.CONFIRM_MODE) {
-            throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.CONFIRM_MODE,
-                    keyMatchForm.crudMode });
-        }
-
-        loadKeyMatch();
-
-        return "confirm.jsp";
-    }
-
-    @Token(save = true, validate = false)
-    //@Execute(validator = false, input = "error.jsp")
-    public String createpage() {
-        // page navi
-        keyMatchForm.initialize();
-        keyMatchForm.crudMode = CommonConstants.CREATE_MODE;
-
-        return "edit.jsp";
-    }
-
-    @Token(save = true, validate = false)
-    //@Execute(validator = false, input = "error.jsp", urlPattern = "editpage/{crudMode}/{id}")
-    public String editpage() {
-        if (keyMatchForm.crudMode != CommonConstants.EDIT_MODE) {
-            throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.EDIT_MODE, keyMatchForm.crudMode });
-        }
-
-        loadKeyMatch();
-
-        return "edit.jsp";
-    }
-
-    @Token(save = true, validate = false)
-    //@Execute(validator = false, input = "error.jsp")
-    public String editfromconfirm() {
-        keyMatchForm.crudMode = CommonConstants.EDIT_MODE;
-
-        loadKeyMatch();
-
-        return "edit.jsp";
-    }
-
-    @Token(save = false, validate = true, keep = true)
-    //@Execute(validator = true, input = "edit.jsp")
-    public String confirmfromcreate() {
-        return "confirm.jsp";
-    }
-
-    @Token(save = false, validate = true, keep = true)
-    //@Execute(validator = true, input = "edit.jsp")
-    public String confirmfromupdate() {
-        return "confirm.jsp";
-    }
-
-    @Token(save = true, validate = false)
-    //@Execute(validator = false, input = "error.jsp", urlPattern = "deletepage/{crudMode}/{id}")
-    public String deletepage() {
-        if (keyMatchForm.crudMode != CommonConstants.DELETE_MODE) {
-            throw new ActionMessagesException("errors.crud_invalid_mode",
-                    new Object[] { CommonConstants.DELETE_MODE, keyMatchForm.crudMode });
-        }
-
-        loadKeyMatch();
-
-        return "confirm.jsp";
-    }
-
-    @Token(save = true, validate = false)
-    //@Execute(validator = false, input = "error.jsp")
-    public String deletefromconfirm() {
-        keyMatchForm.crudMode = CommonConstants.DELETE_MODE;
-
-        loadKeyMatch();
-
-        return "confirm.jsp";
-    }
-
-    protected Map<String, String> createKeyMap() {
-        final Map<String, String> keys = new HashMap<String, String>();
-
-        keys.put("id", keyMatchForm.id);
-
-        return keys;
-    }
-
-    protected void loadKeyMatch() {
-
-        final KeyMatch keyMatch = keyMatchService.getKeyMatch(createKeyMap());
-        if (keyMatch == null) {
-            // throw an exception
-            throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { keyMatchForm.id });
-        }
-
-        BeanUtil.copyBeanToBean(keyMatch, keyMatchForm, option -> option.exclude("searchParams", "mode"));
-    }
-
-    protected KeyMatch createKeyMatch() {
-        KeyMatch keyMatch;
-        final String username = systemHelper.getUsername();
-        final long currentTime = systemHelper.getCurrentTimeAsLong();
-        if (keyMatchForm.crudMode == CommonConstants.EDIT_MODE) {
-            keyMatch = keyMatchService.getKeyMatch(createKeyMap());
-            if (keyMatch == null) {
-                // throw an exception
-                throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { keyMatchForm.id });
-            }
-        } else {
-            keyMatch = new KeyMatch();
-            keyMatch.setCreatedBy(username);
-            keyMatch.setCreatedTime(currentTime);
-        }
-        keyMatch.setUpdatedBy(username);
-        keyMatch.setUpdatedTime(currentTime);
-        BeanUtil.copyBeanToBean(keyMatchForm, keyMatch, option -> option.exclude(CommonConstants.COMMON_CONVERSION_RULE));
-
-        return keyMatch;
-    }
-
-    @Token(save = false, validate = true)
-    //@Execute(validator = true, input = "edit.jsp")
-    public String create() {
-        ComponentUtil.getKeyMatchHelper().update();
-        try {
-            final KeyMatch keyMatch = createKeyMatch();
-            keyMatchService.store(keyMatch);
-            SAStrutsUtil.addSessionMessage("success.crud_create_crud_table");
-
-            return displayList(true);
-        } catch (final ActionMessagesException e) {
-            logger.error(e.getMessage(), e);
-            throw e;
-        } catch (final CrudMessageException e) {
-            logger.error(e.getMessage(), e);
-            throw new ActionMessagesException(e.getMessageId(), e.getArgs());
-        } catch (final Exception e) {
-            logger.error(e.getMessage(), e);
-            throw new ActionMessagesException("errors.crud_failed_to_create_crud_table");
-        }
-    }
-
-    @Token(save = false, validate = true)
-    //@Execute(validator = true, input = "edit.jsp")
-    public String update() {
-        try {
-            final KeyMatch keyMatch = createKeyMatch();
-            keyMatchService.store(keyMatch);
-            SAStrutsUtil.addSessionMessage("success.crud_update_crud_table");
-
-            final String result = displayList(true);
-            ComponentUtil.getKeyMatchHelper().update();
-            return result;
-        } catch (final ActionMessagesException e) {
-            logger.error(e.getMessage(), e);
-            throw e;
-        } catch (final CrudMessageException e) {
-            logger.error(e.getMessage(), e);
-            throw new ActionMessagesException(e.getMessageId(), e.getArgs());
-        } catch (final Exception e) {
-            logger.error(e.getMessage(), e);
-            throw new ActionMessagesException("errors.crud_failed_to_update_crud_table");
-        }
-    }
-
-    //@Execute(validator = false, input = "error.jsp")
-    public String delete() {
-        if (keyMatchForm.crudMode != CommonConstants.DELETE_MODE) {
-            throw new SSCActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.DELETE_MODE,
-                    keyMatchForm.crudMode });
-        }
-
-        try {
-            final KeyMatch keyMatch = keyMatchService.getKeyMatch(createKeyMap());
-            if (keyMatch == null) {
-                // throw an exception
-                throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { keyMatchForm.id });
-            }
-
-            keyMatchService.delete(keyMatch);
-            SAStrutsUtil.addSessionMessage("success.crud_delete_crud_table");
-
-            ComponentUtil.getKeyMatchHelper().update();
-
-            return displayList(true);
-        } catch (final ActionMessagesException e) {
-            logger.error(e.getMessage(), e);
-            throw e;
-        } catch (final CrudMessageException e) {
-            logger.error(e.getMessage(), e);
-            throw new SSCActionMessagesException(e, e.getMessageId(), e.getArgs());
-        } catch (final Exception e) {
-            logger.error(e.getMessage(), e);
-            throw new SSCActionMessagesException(e, "errors.crud_failed_to_delete_crud_table");
-        }
-    }
-
-}

+ 92 - 93
src/main/java/org/codelibs/fess/app/web/admin/AdminDesignAction.java → src/main/java/org/codelibs/fess/app/web/admin/design/AdminDesignAction.java

@@ -14,7 +14,7 @@
  * governing permissions and limitations under the License.
  */
 
-package org.codelibs.fess.app.web.admin;
+package org.codelibs.fess.app.web.admin.design;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -38,13 +38,11 @@ import org.codelibs.fess.annotation.Token;
 import org.codelibs.fess.app.web.base.FessAdminAction;
 import org.codelibs.fess.crud.util.SAStrutsUtil;
 import org.codelibs.fess.helper.SystemHelper;
-import org.lastaflute.di.util.LdiFileUtil;
 import org.lastaflute.web.Execute;
 import org.lastaflute.web.callback.ActionRuntime;
 import org.lastaflute.web.response.ActionResponse;
 import org.lastaflute.web.response.HtmlResponse;
 import org.lastaflute.web.response.StreamResponse;
-import org.lastaflute.web.servlet.request.ResponseManager;
 import org.lastaflute.web.util.LaServletContextUtil;
 import org.lastaflute.web.validation.VaErrorHook;
 import org.slf4j.Logger;
@@ -55,39 +53,65 @@ import org.slf4j.LoggerFactory;
  * @author jflute
  */
 public class AdminDesignAction extends FessAdminAction implements Serializable {
-    
-    private static final long serialVersionUID = 1L;
 
+    private static final long serialVersionUID = 1L;
     private static final Logger logger = LoggerFactory.getLogger(AdminDesignAction.class);
 
     // ===================================================================================
     //                                                                           Attribute
     //                                                                           =========
     @Resource
-    private ResponseManager responseManager;
-    @Resource
     private DynamicProperties crawlerProperties;
     @Resource
     private SystemHelper systemHelper;
 
+    // ===================================================================================
+    //                                                                               Hook
+    //                                                                              ======
+    @Override
+    public ActionResponse hookBefore(ActionRuntime runtime) {
+        checkEditorStatus(runtime);
+        return super.hookBefore(runtime);
+    }
+
+    private void checkEditorStatus(ActionRuntime runtime) {
+        if (cannotEdit()) {
+            throwValidationError(messages -> messages.addErrorsDesignEditorDisabled(GLOBAL), toMainHtml());
+        }
+    }
+
+    @Override
+    public void hookFinally(ActionRuntime runtime) {
+        super.hookFinally(runtime);
+        if (runtime.isForwardToHtml()) {
+            runtime.registerData("fileNameItems", loadFileNameItems());
+            runtime.registerData("editable", cannotEdit());
+        }
+    }
+
+    private List<String> loadFileNameItems() {
+        final File baseDir = new File(getServletContext().getRealPath("/"));
+        final List<String> fileNameItems = new ArrayList<String>();
+        final List<File> fileList = getAccessibleFileList(baseDir);
+        final int length = baseDir.getAbsolutePath().length();
+        for (final File file : fileList) {
+            fileNameItems.add(file.getAbsolutePath().substring(length));
+        }
+        return fileNameItems;
+    }
+
     // ===================================================================================
     //                                                                             Execute
     //                                                                             =======
     @Token(save = true, validate = false)
     @Execute
     public HtmlResponse index() {
-        return asHtml(path_AdminDesign_AdminDesignJsp).useForm(AdminDesignForm.class);
-    }
-
-    @Token(save = true, validate = false)
-    @Execute
-    public HtmlResponse back() {
-        return asHtml(path_AdminDesign_AdminDesignJsp).useForm(AdminDesignForm.class);
+        return asHtml(path_AdminDesign_AdminDesignJsp).useForm(DesignForm.class);
     }
 
     @Execute
-    public HtmlResponse upload(AdminDesignForm form) {
-        validate(form, messages -> {}, toMainHtml());
+    public HtmlResponse upload(DesignForm form) {
+        validate(form, messages -> {} , toMainHtml());
         final String uploadedFileName = form.designFile.getFileName();
         String fileName = form.designFileName;
         if (StringUtil.isBlank(fileName)) {
@@ -131,8 +155,9 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
         }
 
         try {
-            LdiFileUtil.write(uploadFile.getAbsolutePath(), form.designFile.getFileData());
-            SAStrutsUtil.addSessionMessage("success.upload_design_file", fileName);
+            write(uploadFile.getAbsolutePath(), form.designFile.getFileData());
+            final String currentFileName = fileName;
+            saveInfo(messages -> messages.addSuccessUploadDesignFile(GLOBAL, currentFileName));
         } catch (final Exception e) {
             logger.error("Failed to write an image file: {}", fileName, e);
             throwValidationError(messages -> messages.addErrorsFailedToWriteDesignImageFile(GLOBAL), toMainHtml());
@@ -153,11 +178,45 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
         return false;
     }
 
+    @Execute
+    public StreamResponse download(DesignForm form) {
+        final File file = getTargetFile(form);
+        if (file == null) {
+            throwValidationError(messages -> messages.addErrorsTargetFileDoesNotExist(GLOBAL, form.fileName), toMainHtml());
+        }
+        FileInputStream fis = null;
+        try {
+            fis = new FileInputStream(file);
+        } catch (final FileNotFoundException e) {
+            logger.error("Not found the file: {}", file.getAbsolutePath(), e);
+            throwValidationError(messages -> messages.addErrorsFailedToDownloadFile(GLOBAL, form.fileName), toMainHtml());
+        }
+        return asStream(file.getName()).stream(fis);
+    }
+
+    @Token(save = false, validate = true)
+    @Execute
+    public HtmlResponse delete(DesignForm form) {
+        final File file = getTargetFile(form);
+        if (file == null) {
+            throwValidationError(messages -> messages.addErrorsTargetFileDoesNotExist(GLOBAL, form.fileName), toMainHtml());
+        }
+        if (!file.delete()) {
+            logger.error("Failed to delete {}", file.getAbsolutePath());
+            throwValidationError(messages -> messages.addErrorsFailedToDeleteFile(GLOBAL, form.fileName), toMainHtml());
+        }
+        SAStrutsUtil.addSessionMessage("success.delete_file", form.fileName);
+        return redirect(getClass());
+    }
+
+    // -----------------------------------------------------
+    //                                                 Edit 
+    //                                                ------
     @Token(save = true, validate = false)
     @Execute
-    public HtmlResponse edit(AdminDesignForm form) {
+    public HtmlResponse edit(DesignEditForm form) {
         final String jspType = "view";
-        final File jspFile = getJspFile(form, jspType);
+        final File jspFile = getJspFile(form.fileName, jspType);
         try {
             form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
         } catch (final UnsupportedEncodingException e) {
@@ -168,9 +227,9 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
 
     @Token(save = true, validate = false)
     @Execute
-    public HtmlResponse editAsUseDefault(AdminDesignForm form) {
+    public HtmlResponse editAsUseDefault(DesignEditForm form) {
         final String jspType = "orig/view";
-        final File jspFile = getJspFile(form, jspType);
+        final File jspFile = getJspFile(form.fileName, jspType);
         try {
             form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
         } catch (final UnsupportedEncodingException e) {
@@ -181,17 +240,17 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
 
     @Token(save = false, validate = true)
     @Execute
-    public HtmlResponse update(AdminDesignForm form) {
+    public HtmlResponse update(DesignEditForm form) {
         final String jspType = "view";
-        final File jspFile = getJspFile(form, jspType);
+        final File jspFile = getJspFile(form.fileName, jspType);
 
         if (form.content == null) {
             form.content = StringUtil.EMPTY;
         }
 
         try {
-            LdiFileUtil.write(jspFile.getAbsolutePath(), form.content.getBytes(Constants.UTF_8));
-            SAStrutsUtil.addSessionMessage("success.update_design_jsp_file", systemHelper.getDesignJspFileName(form.fileName));
+            write(jspFile.getAbsolutePath(), form.content.getBytes(Constants.UTF_8));
+            saveInfo(messages -> messages.addSuccessUpdateDesignJspFile(GLOBAL, systemHelper.getDesignJspFileName(form.fileName)));
         } catch (final Exception e) {
             logger.error("Failed to update {}", form.fileName, e);
             throwValidationError(messages -> messages.addErrorsFailedToUpdateJspFile(GLOBAL), toMainHtml());
@@ -199,76 +258,16 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
         return redirect(getClass());
     }
 
+    @Token(save = true, validate = false)
     @Execute
-    public StreamResponse download(AdminDesignForm form) {
-        final File file = getTargetFile(form);
-        if (file == null) {
-            throwValidationError(messages -> messages.addErrorsTargetFileDoesNotExist(GLOBAL, form.fileName), toMainHtml());
-        }
-        FileInputStream fis = null;
-        try {
-            fis = new FileInputStream(file);
-        } catch (final FileNotFoundException e) {
-            logger.error("Not found the file: {}", file.getAbsolutePath(), e);
-            throwValidationError(messages -> messages.addErrorsFailedToDownloadFile(GLOBAL, form.fileName), toMainHtml());
-        }
-        return asStream(file.getName()).stream(fis);
-    }
-
-    @Token(save = false, validate = true)
-    @Execute
-    public HtmlResponse delete(AdminDesignForm form) {
-        final File file = getTargetFile(form);
-        if (file == null) {
-            throwValidationError(messages -> messages.addErrorsTargetFileDoesNotExist(GLOBAL, form.fileName), toMainHtml());
-        }
-        if (!file.delete()) {
-            logger.error("Failed to delete {}", file.getAbsolutePath());
-            throwValidationError(messages -> messages.addErrorsFailedToDeleteFile(GLOBAL, form.fileName), toMainHtml());
-        }
-        SAStrutsUtil.addSessionMessage("success.delete_file", form.fileName);
-        return redirect(getClass());
-    }
-
-    // ===================================================================================
-    //                                                                               Hook
-    //                                                                              ======
-    @Override
-    public ActionResponse hookBefore(ActionRuntime runtime) {
-        checkEditorStatus(runtime);
-        return super.hookBefore(runtime);
-    }
-
-    private void checkEditorStatus(ActionRuntime runtime) {
-        if (cannotEdit()) {
-            throwValidationError(messages -> messages.addErrorsDesignEditorDisabled(GLOBAL), toMainHtml());
-        }
-    }
-
-    @Override
-    public void hookFinally(ActionRuntime runtime) {
-        super.hookFinally(runtime);
-        if (runtime.isForwardToHtml()) {
-            runtime.registerData("fileNameItems", loadFileNameItems());
-            runtime.registerData("editable", cannotEdit());
-        }
-    }
-
-    private List<String> loadFileNameItems() {
-        final File baseDir = new File(getServletContext().getRealPath("/"));
-        final List<String> fileNameItems = new ArrayList<String>();
-        final List<File> fileList = getAccessibleFileList(baseDir);
-        final int length = baseDir.getAbsolutePath().length();
-        for (final File file : fileList) {
-            fileNameItems.add(file.getAbsolutePath().substring(length));
-        }
-        return fileNameItems;
+    public HtmlResponse back() {
+        return asHtml(path_AdminDesign_AdminDesignJsp).useForm(DesignForm.class);
     }
 
     // ===================================================================================
     //                                                                        Assist Logic
     //                                                                        ============
-    private File getTargetFile(AdminDesignForm form) {
+    private File getTargetFile(DesignForm form) {
         final File baseDir = new File(getServletContext().getRealPath("/"));
         final File targetFile = new File(getServletContext().getRealPath(form.fileName));
         final List<File> fileList = getAccessibleFileList(baseDir);
@@ -293,8 +292,8 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
         return fileList;
     }
 
-    private File getJspFile(final AdminDesignForm form, final String jspType) {
-        final String jspFileName = systemHelper.getDesignJspFileName(form.fileName);
+    private File getJspFile(String fileName, String jspType) {
+        final String jspFileName = systemHelper.getDesignJspFileName(fileName);
         if (jspFileName == null) {
             throwValidationError(messages -> messages.addErrorsInvalidDesignJspFileName(GLOBAL), toMainHtml());
         }
@@ -310,7 +309,7 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
             return asHtml(path_AdminDesign_AdminDesignJsp);
         };
     }
-    
+
     private boolean cannotEdit() {
         return Constants.FALSE.equals(crawlerProperties.getProperty(Constants.WEB_DESIGN_EDITOR_PROPERTY, Constants.TRUE));
     }

+ 27 - 0
src/main/java/org/codelibs/fess/app/web/admin/design/DesignEditForm.java

@@ -0,0 +1,27 @@
+/*
+ * Copyright 2009-2015 the CodeLibs Project and the Others.
+ *
+ * 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.
+ */
+
+package org.codelibs.fess.app.web.admin.design;
+
+/**
+ * @author codelibs
+ * @author jflute
+ */
+public class DesignEditForm {
+
+    public String fileName;
+    public String content;
+}

+ 5 - 5
src/main/java/org/codelibs/fess/app/web/admin/AdminDesignForm.java → src/main/java/org/codelibs/fess/app/web/admin/design/DesignForm.java

@@ -14,17 +14,20 @@
  * governing permissions and limitations under the License.
  */
 
-package org.codelibs.fess.app.web.admin;
+package org.codelibs.fess.app.web.admin.design;
 
 import java.io.Serializable;
 
+import org.codelibs.fess.mylasta.tentative.Required;
 import org.lastaflute.web.ruts.multipart.MultipartFormFile;
 
-public class AdminDesignForm implements Serializable {
+public class DesignForm implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    // TODO jflute target needed? (2015/07/25)
     //@Required(target = "upload")
+    @Required
     public MultipartFormFile designFile;
 
     public String designFileName;
@@ -32,7 +35,4 @@ public class AdminDesignForm implements Serializable {
     // TODO jflute unneeded? no validator at the method (2015/07/25)
     //@Required(target = "edit,editAsUseDefault,download,delete")
     public String fileName;
-
-    public String content;
-
 }

+ 285 - 0
src/main/java/org/codelibs/fess/app/web/admin/keymatch/AdminKeyMatchAction.java

@@ -0,0 +1,285 @@
+/*
+ * Copyright 2009-2015 the CodeLibs Project and the Others.
+ *
+ * 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.
+ */
+
+package org.codelibs.fess.app.web.admin.keymatch;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.codelibs.core.beans.util.BeanUtil;
+import org.codelibs.fess.annotation.Token;
+import org.codelibs.fess.app.web.base.FessAdminAction;
+import org.codelibs.fess.crud.CommonConstants;
+import org.codelibs.fess.crud.util.SAStrutsUtil;
+import org.codelibs.fess.es.exentity.KeyMatch;
+import org.codelibs.fess.helper.SystemHelper;
+import org.codelibs.fess.pager.KeyMatchPager;
+import org.codelibs.fess.service.KeyMatchService;
+import org.codelibs.fess.util.ComponentUtil;
+import org.lastaflute.web.Execute;
+import org.lastaflute.web.callback.ActionRuntime;
+import org.lastaflute.web.response.HtmlResponse;
+import org.lastaflute.web.response.render.RenderData;
+
+/**
+ * @author codelibs
+ * @author jflute
+ */
+public class AdminKeyMatchAction extends FessAdminAction {
+
+    // ===================================================================================
+    //                                                                           Attribute
+    //                                                                           =========
+    @Resource
+    private KeyMatchService keyMatchService;
+    @Resource
+    private KeyMatchPager keyMatchPager;
+    @Resource
+    private SystemHelper systemHelper;
+
+    // ===================================================================================
+    //                                                                               Hook
+    //                                                                              ======
+    @Override
+    protected void setupHtmlData(ActionRuntime runtime) {
+        super.setupHtmlData(runtime);
+        runtime.registerData("helpLink", getHelpLink());
+    }
+
+    private String getHelpLink() {
+        return systemHelper.getHelpLink("keyMatch");
+    }
+
+    // ===================================================================================
+    //                                                                      Search Execute
+    //                                                                      ==============
+    @Execute
+    public HtmlResponse index(KeyMatchSearchForm form) {
+        return asHtml(path_AdminKeyMatch_IndexJsp).renderWith(data -> {
+            searchPaging(data, form);
+        });
+    }
+
+    @Execute
+    public HtmlResponse list(Integer pageNumber, KeyMatchSearchForm form) {
+        keyMatchPager.setCurrentPageNumber(pageNumber);
+        return asHtml(path_AdminKeyMatch_IndexJsp).renderWith(data -> {
+            searchPaging(data, form);
+        });
+    }
+
+    @Execute
+    public HtmlResponse search(KeyMatchSearchForm form) {
+        BeanUtil.copyBeanToBean(form.searchParams, keyMatchPager, op -> op.exclude(CommonConstants.PAGER_CONVERSION_RULE));
+        return asHtml(path_AdminKeyMatch_IndexJsp).renderWith(data -> {
+            searchPaging(data, form);
+        });
+    }
+
+    @Execute
+    public HtmlResponse reset(KeyMatchSearchForm form) {
+        keyMatchPager.clear();
+        return asHtml(path_AdminKeyMatch_IndexJsp).renderWith(data -> {
+            searchPaging(data, form);
+        });
+    }
+
+    @Execute
+    public HtmlResponse back(KeyMatchSearchForm form) {
+        return asHtml(path_AdminKeyMatch_IndexJsp).renderWith(data -> {
+            searchPaging(data, form);
+        });
+    }
+
+    protected void searchPaging(RenderData data, KeyMatchSearchForm form) {
+        data.register("keyMatchItems", keyMatchService.getKeyMatchList(keyMatchPager)); // page navi
+
+        // restore from pager
+        BeanUtil.copyBeanToBean(keyMatchPager, form.searchParams, op -> op.exclude(CommonConstants.PAGER_CONVERSION_RULE));
+    }
+
+    // ===================================================================================
+    //                                                                        Edit Execute
+    //                                                                        ============
+    // -----------------------------------------------------
+    //                                            Entry Page
+    //                                            ----------
+    @Token(save = true, validate = false)
+    @Execute
+    public HtmlResponse createpage(KeyMatchEditForm form) {
+        form.crudMode = CommonConstants.CREATE_MODE;
+        return asHtml(path_AdminKeyMatch_EditJsp);
+    }
+
+    @Token(save = true, validate = false)
+    @Execute
+    public HtmlResponse editpage(int crudMode, String id, KeyMatchEditForm form) {
+        verifyCrudMode(form, CommonConstants.EDIT_MODE);
+        loadKeyMatch(form);
+        return asHtml(path_AdminKeyMatch_EditJsp);
+    }
+
+    @Token(save = true, validate = false)
+    @Execute
+    public HtmlResponse editagain(KeyMatchEditForm form) {
+        return asHtml(path_AdminKeyMatch_EditJsp);
+    }
+
+    @Token(save = true, validate = false)
+    @Execute
+    public HtmlResponse editfromconfirm(KeyMatchEditForm form) {
+        form.crudMode = CommonConstants.EDIT_MODE;
+        loadKeyMatch(form);
+        return asHtml(path_AdminKeyMatch_EditJsp);
+    }
+
+    @Token(save = true, validate = false)
+    @Execute
+    public HtmlResponse deletepage(int crudMode, String id, KeyMatchEditForm form) {
+        verifyCrudMode(form, CommonConstants.DELETE_MODE);
+        loadKeyMatch(form);
+        return asHtml(path_AdminKeyMatch_ConfirmJsp);
+    }
+
+    @Token(save = true, validate = false)
+    @Execute
+    public HtmlResponse deletefromconfirm(KeyMatchEditForm form) {
+        form.crudMode = CommonConstants.DELETE_MODE;
+        loadKeyMatch(form);
+        return asHtml(path_AdminKeyMatch_ConfirmJsp);
+    }
+
+    // -----------------------------------------------------
+    //                                               Confirm
+    //                                               -------
+    @Execute
+    public HtmlResponse confirmpage(int crudMode, String id, KeyMatchEditForm form) {
+        verifyCrudMode(form, CommonConstants.CONFIRM_MODE);
+        loadKeyMatch(form);
+        return asHtml(path_AdminKeyMatch_ConfirmJsp);
+    }
+
+    @Token(save = false, validate = true, keep = true)
+    @Execute
+    public HtmlResponse confirmfromcreate(KeyMatchEditForm form) {
+        validate(form, messages -> {} , () -> {
+            return asHtml(path_AdminKeyMatch_EditJsp);
+        });
+        return asHtml(path_AdminKeyMatch_ConfirmJsp);
+    }
+
+    @Token(save = false, validate = true, keep = true)
+    @Execute
+    public HtmlResponse confirmfromupdate(KeyMatchEditForm form) {
+        validate(form, messages -> {} , () -> {
+            return asHtml(path_AdminKeyMatch_EditJsp);
+        });
+        return asHtml(path_AdminKeyMatch_ConfirmJsp);
+    }
+
+    // -----------------------------------------------------
+    //                                         Actually Crud
+    //                                         -------------
+    @Token(save = false, validate = true)
+    @Execute
+    public HtmlResponse create(KeyMatchEditForm form) {
+        validate(form, messages -> {} , () -> {
+            return asHtml(path_AdminKeyMatch_EditJsp);
+        });
+        keyMatchService.store(createKeyMatch(form));
+        saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
+        ComponentUtil.getKeyMatchHelper().update();
+        return redirect(getClass());
+    }
+
+    @Token(save = false, validate = true)
+    @Execute
+    public HtmlResponse update(KeyMatchEditForm form) {
+        validate(form, messages -> {} , () -> {
+            return asHtml(path_AdminKeyMatch_EditJsp);
+        });
+        keyMatchService.store(createKeyMatch(form));
+        saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
+        ComponentUtil.getKeyMatchHelper().update();
+        return redirect(getClass());
+    }
+
+    @Execute
+    public HtmlResponse delete(KeyMatchEditForm form) {
+        verifyCrudMode(form, CommonConstants.DELETE_MODE);
+        keyMatchService.delete(getKeyMatch(form));
+        SAStrutsUtil.addSessionMessage("success.crud_delete_crud_table");
+        ComponentUtil.getKeyMatchHelper().update();
+        return redirect(getClass());
+    }
+
+    // ===================================================================================
+    //                                                                        Assist Logic
+    //                                                                        ============
+    protected void verifyCrudMode(KeyMatchEditForm form, int expectedMode) {
+        if (form.crudMode != expectedMode) {
+            throwValidationError(messages -> {
+                messages.addErrorsCrudInvalidMode(GLOBAL, String.valueOf(expectedMode), String.valueOf(form.crudMode));
+            } , () -> {
+                return asHtml(path_AdminKeyMatch_EditJsp);
+            });
+        }
+    }
+
+    // -----------------------------------------------------
+    //                                             Key Match
+    //                                             ---------
+    protected void loadKeyMatch(KeyMatchEditForm form) {
+        final KeyMatch keyMatch = getKeyMatch(form);
+        // TODO jflute modeがいない...crudModeの間違い? (2015/08/02)
+        BeanUtil.copyBeanToBean(keyMatch, form, option -> option.exclude("mode"));
+    }
+
+    protected KeyMatch getKeyMatch(KeyMatchEditForm form) {
+        final KeyMatch keyMatch = keyMatchService.getKeyMatch(createKeyMap(form));
+        if (keyMatch == null) {
+            throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), () -> {
+                return asHtml(path_AdminKeyMatch_EditJsp);
+            });
+        }
+        return keyMatch;
+    }
+
+    protected KeyMatch createKeyMatch(KeyMatchEditForm form) {
+        KeyMatch keyMatch;
+        final String username = systemHelper.getUsername();
+        final long currentTime = systemHelper.getCurrentTimeAsLong();
+        if (form.crudMode == CommonConstants.EDIT_MODE) {
+            keyMatch = getKeyMatch(form);
+        } else {
+            keyMatch = new KeyMatch();
+            keyMatch.setCreatedBy(username);
+            keyMatch.setCreatedTime(currentTime);
+        }
+        keyMatch.setUpdatedBy(username);
+        keyMatch.setUpdatedTime(currentTime);
+        BeanUtil.copyBeanToBean(form, keyMatch, op -> op.exclude(CommonConstants.COMMON_CONVERSION_RULE));
+        return keyMatch;
+    }
+
+    protected Map<String, String> createKeyMap(KeyMatchEditForm form) {
+        final Map<String, String> keys = new HashMap<String, String>();
+        keys.put("id", form.id);
+        return keys;
+    }
+}

+ 6 - 11
src/main/java/org/codelibs/fess/app/web/admin/KeyMatchForm.java → src/main/java/org/codelibs/fess/app/web/admin/keymatch/KeyMatchEditForm.java

@@ -14,7 +14,7 @@
  * governing permissions and limitations under the License.
  */
 
-package org.codelibs.fess.app.web.admin;
+package org.codelibs.fess.app.web.admin.keymatch;
 
 import java.io.Serializable;
 import java.util.HashMap;
@@ -22,22 +22,17 @@ import java.util.Map;
 
 import org.codelibs.fess.util.ComponentUtil;
 
-public class KeyMatchForm implements Serializable {
+/**
+ * @author codelibs
+ * @author jflute
+ */
+public class KeyMatchEditForm implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    //@IntegerType
-    public String pageNumber;
-
-    public Map<String, String> searchParams = new HashMap<String, String>();
-
     //@IntegerType
     public int crudMode;
 
-    public String getCurrentPageNumber() {
-        return pageNumber;
-    }
-
     //@Required(target = "confirmfromupdate,update,delete")
     //@Maxbytelength(maxbytelength = 1000)
     public String id;

+ 32 - 0
src/main/java/org/codelibs/fess/app/web/admin/keymatch/KeyMatchSearchForm.java

@@ -0,0 +1,32 @@
+/*
+ * Copyright 2009-2015 the CodeLibs Project and the Others.
+ *
+ * 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.
+ */
+
+package org.codelibs.fess.app.web.admin.keymatch;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author codelibs
+ * @author jflute
+ */
+public class KeyMatchSearchForm implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    public Map<String, String> searchParams = new HashMap<String, String>();
+}

+ 23 - 0
src/main/java/org/codelibs/fess/app/web/base/FessAdminAction.java

@@ -15,6 +15,29 @@
  */
 package org.codelibs.fess.app.web.base;
 
+import javax.annotation.Resource;
+
+import org.codelibs.fess.mylasta.action.FessMessages;
+import org.lastaflute.di.util.LdiFileUtil;
+import org.lastaflute.web.servlet.session.SessionManager;
+import org.lastaflute.web.validation.VaMessenger;
+
+/**
+ * @author codelibs
+ * @author jflute
+ */
 public abstract class FessAdminAction extends FessBaseAction {
 
+    @Resource
+    private SessionManager sessionManager;
+
+    protected void write(String path, byte[] data) {
+        LdiFileUtil.write(path, data);
+    }
+
+    protected void saveInfo(VaMessenger<FessMessages> validationMessagesLambda) {
+        FessMessages messages = createMessages();
+        validationMessagesLambda.message(messages);
+        sessionManager.info().save(messages);
+    }
 }

+ 7 - 0
src/main/java/org/codelibs/fess/app/web/base/FessBaseAction.java

@@ -104,8 +104,15 @@ public abstract class FessBaseAction extends TypicalAction // has several interf
     @Override
     public void hookFinally(ActionRuntime runtime) {
         super.hookFinally(runtime);
+        if (runtime.isForwardToHtml()) {
+            setupHtmlData(runtime);
+        }
+    }
+    
+    protected void setupHtmlData(ActionRuntime runtime) {
     }
 
+
     // ===================================================================================
     //                                                                      Access Context
     //                                                                      ==============

+ 30 - 0
src/main/java/org/codelibs/fess/mylasta/tentative/Required.java

@@ -0,0 +1,30 @@
+/*
+ * Copyright 2012 the CodeLibs Project and the Others.
+ *
+ * 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.
+ */
+package org.codelibs.fess.mylasta.tentative;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * TODO jflute LastaFluteで対応するまで暫定
+ * @author jflute
+ */
+@Target(ElementType.FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Required {
+}