Merge pull request #303 from jflute/lastaflute
Lastaflute: migrating AdminKeymatchAction
This commit is contained in:
commit
5accc5e030
10 changed files with 540 additions and 563 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
@ -26,7 +26,6 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.codelibs.core.io.FileUtil;
|
||||
|
@ -38,14 +37,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;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -55,39 +51,68 @@ 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
|
||||
protected void setupHtmlData(ActionRuntime runtime) {
|
||||
super.setupHtmlData(runtime);
|
||||
runtime.registerData("editable", cannotEdit());
|
||||
runtime.registerData("fileNameItems", loadFileNameItems());
|
||||
runtime.registerData("helpLink", systemHelper.getHelpLink("design"));
|
||||
}
|
||||
|
||||
private boolean cannotEdit() {
|
||||
return Constants.FALSE.equals(crawlerProperties.getProperty(Constants.WEB_DESIGN_EDITOR_PROPERTY, Constants.TRUE));
|
||||
}
|
||||
|
||||
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 +156,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,54 +179,8 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Token(save = true, validate = false)
|
||||
@Execute
|
||||
public HtmlResponse edit(AdminDesignForm form) {
|
||||
final String jspType = "view";
|
||||
final File jspFile = getJspFile(form, jspType);
|
||||
try {
|
||||
form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
throw new FessSystemException("Invalid encoding", e);
|
||||
}
|
||||
return asHtml(path_AdminDesign_AdminDesignEditJsp);
|
||||
}
|
||||
|
||||
@Token(save = true, validate = false)
|
||||
@Execute
|
||||
public HtmlResponse editAsUseDefault(AdminDesignForm form) {
|
||||
final String jspType = "orig/view";
|
||||
final File jspFile = getJspFile(form, jspType);
|
||||
try {
|
||||
form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
throw new FessSystemException("Invalid encoding", e);
|
||||
}
|
||||
return asHtml(path_AdminDesign_AdminDesignEditJsp);
|
||||
}
|
||||
|
||||
@Token(save = false, validate = true)
|
||||
@Execute
|
||||
public HtmlResponse update(AdminDesignForm form) {
|
||||
final String jspType = "view";
|
||||
final File jspFile = getJspFile(form, 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));
|
||||
} catch (final Exception e) {
|
||||
logger.error("Failed to update {}", form.fileName, e);
|
||||
throwValidationError(messages -> messages.addErrorsFailedToUpdateJspFile(GLOBAL), toMainHtml());
|
||||
}
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
||||
@Execute
|
||||
public StreamResponse download(AdminDesignForm form) {
|
||||
public StreamResponse download(DesignForm form) {
|
||||
final File file = getTargetFile(form);
|
||||
if (file == null) {
|
||||
throwValidationError(messages -> messages.addErrorsTargetFileDoesNotExist(GLOBAL, form.fileName), toMainHtml());
|
||||
|
@ -217,7 +197,7 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
|
|||
|
||||
@Token(save = false, validate = true)
|
||||
@Execute
|
||||
public HtmlResponse delete(AdminDesignForm form) {
|
||||
public HtmlResponse delete(DesignForm form) {
|
||||
final File file = getTargetFile(form);
|
||||
if (file == null) {
|
||||
throwValidationError(messages -> messages.addErrorsTargetFileDoesNotExist(GLOBAL, form.fileName), toMainHtml());
|
||||
|
@ -226,49 +206,69 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
|
|||
logger.error("Failed to delete {}", file.getAbsolutePath());
|
||||
throwValidationError(messages -> messages.addErrorsFailedToDeleteFile(GLOBAL, form.fileName), toMainHtml());
|
||||
}
|
||||
SAStrutsUtil.addSessionMessage("success.delete_file", form.fileName);
|
||||
saveInfo(messages -> messages.addSuccessDeleteFile(GLOBAL, form.fileName));
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
||||
// ===================================================================================
|
||||
// Hook
|
||||
// ======
|
||||
@Override
|
||||
public ActionResponse hookBefore(ActionRuntime runtime) {
|
||||
checkEditorStatus(runtime);
|
||||
return super.hookBefore(runtime);
|
||||
// -----------------------------------------------------
|
||||
// Edit
|
||||
// ------
|
||||
@Token(save = true, validate = false)
|
||||
@Execute
|
||||
public HtmlResponse edit(DesignEditForm form) {
|
||||
final String jspType = "view";
|
||||
final File jspFile = getJspFile(form.fileName, jspType);
|
||||
try {
|
||||
form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
throw new FessSystemException("Invalid encoding", e);
|
||||
}
|
||||
return asHtml(path_AdminDesign_AdminDesignEditJsp);
|
||||
}
|
||||
|
||||
private void checkEditorStatus(ActionRuntime runtime) {
|
||||
if (cannotEdit()) {
|
||||
throwValidationError(messages -> messages.addErrorsDesignEditorDisabled(GLOBAL), toMainHtml());
|
||||
@Token(save = true, validate = false)
|
||||
@Execute
|
||||
public HtmlResponse editAsUseDefault(DesignEditForm form) {
|
||||
final String jspType = "orig/view";
|
||||
final File jspFile = getJspFile(form.fileName, jspType);
|
||||
try {
|
||||
form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
throw new FessSystemException("Invalid encoding", e);
|
||||
}
|
||||
return asHtml(path_AdminDesign_AdminDesignEditJsp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hookFinally(ActionRuntime runtime) {
|
||||
super.hookFinally(runtime);
|
||||
if (runtime.isForwardToHtml()) {
|
||||
runtime.registerData("fileNameItems", loadFileNameItems());
|
||||
runtime.registerData("editable", cannotEdit());
|
||||
@Token(save = false, validate = true)
|
||||
@Execute
|
||||
public HtmlResponse update(DesignEditForm form) {
|
||||
final String jspType = "view";
|
||||
final File jspFile = getJspFile(form.fileName, jspType);
|
||||
|
||||
if (form.content == null) {
|
||||
form.content = StringUtil.EMPTY;
|
||||
}
|
||||
|
||||
try {
|
||||
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());
|
||||
}
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
||||
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;
|
||||
@Token(save = true, validate = false)
|
||||
@Execute
|
||||
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 +293,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());
|
||||
}
|
||||
|
@ -305,22 +305,12 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
|
|||
return jspFile;
|
||||
}
|
||||
|
||||
// ===================================================================================
|
||||
// Small Helper
|
||||
// ============
|
||||
private VaErrorHook toMainHtml() {
|
||||
return () -> {
|
||||
return asHtml(path_AdminDesign_AdminDesignJsp);
|
||||
};
|
||||
}
|
||||
|
||||
private boolean cannotEdit() {
|
||||
return Constants.FALSE.equals(crawlerProperties.getProperty(Constants.WEB_DESIGN_EDITOR_PROPERTY, Constants.TRUE));
|
||||
}
|
||||
|
||||
private ServletContext getServletContext() {
|
||||
return LaServletContextUtil.getServletContext();
|
||||
}
|
||||
|
||||
// TODO fess needed? public? by jflute (2015/07/25)
|
||||
public String getHelpLink() {
|
||||
return systemHelper.getHelpLink("design");
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -0,0 +1,272 @@
|
|||
/*
|
||||
* 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.fess.annotation.Token;
|
||||
import org.codelibs.fess.app.web.base.FessAdminAction;
|
||||
import org.codelibs.fess.crud.CommonConstants;
|
||||
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;
|
||||
import org.lastaflute.web.validation.VaErrorHook;
|
||||
|
||||
/**
|
||||
* @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", 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) {
|
||||
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
|
||||
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 -> {} , toEditHtml());
|
||||
return asHtml(path_AdminKeyMatch_ConfirmJsp);
|
||||
}
|
||||
|
||||
@Token(save = false, validate = true, keep = true)
|
||||
@Execute
|
||||
public HtmlResponse confirmfromupdate(KeyMatchEditForm form) {
|
||||
validate(form, messages -> {} , toEditHtml());
|
||||
return asHtml(path_AdminKeyMatch_ConfirmJsp);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Actually Crud
|
||||
// -------------
|
||||
@Token(save = false, validate = true)
|
||||
@Execute
|
||||
public HtmlResponse create(KeyMatchEditForm form) {
|
||||
validate(form, messages -> {} , toEditHtml());
|
||||
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 -> {} , toEditHtml());
|
||||
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));
|
||||
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
|
||||
ComponentUtil.getKeyMatchHelper().update();
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
||||
// ===================================================================================
|
||||
// Assist Logic
|
||||
// ============
|
||||
protected void loadKeyMatch(KeyMatchEditForm form) {
|
||||
copyBeanToBean(getKeyMatch(form), form, op -> op.exclude("crudMode"));
|
||||
}
|
||||
|
||||
protected KeyMatch getKeyMatch(KeyMatchEditForm form) {
|
||||
final KeyMatch keyMatch = keyMatchService.getKeyMatch(createKeyMap(form));
|
||||
if (keyMatch == null) {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml());
|
||||
}
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
// ===================================================================================
|
||||
// Small Helper
|
||||
// ============
|
||||
protected void verifyCrudMode(KeyMatchEditForm form, int expectedMode) {
|
||||
if (form.crudMode != expectedMode) {
|
||||
throwValidationError(messages -> {
|
||||
messages.addErrorsCrudInvalidMode(GLOBAL, String.valueOf(expectedMode), String.valueOf(form.crudMode));
|
||||
} , toEditHtml());
|
||||
}
|
||||
}
|
||||
|
||||
protected VaErrorHook toEditHtml() {
|
||||
return () -> {
|
||||
return asHtml(path_AdminKeyMatch_EditJsp);
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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;
|
|
@ -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>();
|
||||
}
|
|
@ -15,6 +15,68 @@
|
|||
*/
|
||||
package org.codelibs.fess.app.web.base;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.codelibs.core.beans.util.BeanUtil;
|
||||
import org.codelibs.core.beans.util.CopyOptions;
|
||||
import org.codelibs.fess.mylasta.action.FessMessages;
|
||||
import org.lastaflute.di.util.LdiFileUtil;
|
||||
import org.lastaflute.web.servlet.session.SessionManager;
|
||||
import org.lastaflute.web.util.LaServletContextUtil;
|
||||
import org.lastaflute.web.validation.VaMessenger;
|
||||
|
||||
/**
|
||||
* @author codelibs
|
||||
* @author jflute
|
||||
*/
|
||||
public abstract class FessAdminAction extends FessBaseAction {
|
||||
|
||||
// ===================================================================================
|
||||
// Attribute
|
||||
// =========
|
||||
@Resource
|
||||
private SessionManager sessionManager;
|
||||
|
||||
// ===================================================================================
|
||||
// Small Helper
|
||||
// ============
|
||||
protected void saveInfo(VaMessenger<FessMessages> validationMessagesLambda) {
|
||||
FessMessages messages = createMessages();
|
||||
validationMessagesLambda.message(messages);
|
||||
sessionManager.info().save(messages);
|
||||
}
|
||||
|
||||
protected void write(String path, byte[] data) {
|
||||
LdiFileUtil.write(path, data);
|
||||
}
|
||||
|
||||
protected void copyBeanToBean(Object src, Object dest, Consumer<CopyOptions> option) {
|
||||
BeanUtil.copyBeanToBean(src, dest, option);
|
||||
}
|
||||
|
||||
protected ServletContext getServletContext() {
|
||||
return LaServletContextUtil.getServletContext();
|
||||
}
|
||||
|
||||
// ===================================================================================
|
||||
// Document
|
||||
// ========
|
||||
/**
|
||||
* {@inheritDoc} <br>
|
||||
* Application Origin Methods:
|
||||
* <pre>
|
||||
* <span style="font-size: 130%; color: #553000">[Small Helper]</span>
|
||||
* o saveInfo() <span style="color: #3F7E5E">// save messages to session</span>
|
||||
* o write() <span style="color: #3F7E5E">// write text to specified file</span>
|
||||
* o copyBeanToBean() <span style="color: #3F7E5E">// copy bean to bean by BeanUtil</span>
|
||||
* o getServletContext() <span style="color: #3F7E5E">// get servlet context</span>
|
||||
* </pre>
|
||||
*/
|
||||
@Override
|
||||
public void document1_CallableSuperMethod() {
|
||||
super.document1_CallableSuperMethod();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,16 +31,8 @@
|
|||
*/
|
||||
package org.codelibs.fess.app.web.base;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.codelibs.fess.mylasta.action.FessHtmlPath;
|
||||
import org.codelibs.fess.mylasta.action.FessMessages;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.dbflute.helper.HandyDate;
|
||||
import org.dbflute.hook.AccessContext;
|
||||
import org.dbflute.optional.OptionalObject;
|
||||
import org.dbflute.optional.OptionalThing;
|
||||
|
@ -51,7 +43,6 @@ import org.lastaflute.web.callback.ActionRuntime;
|
|||
import org.lastaflute.web.login.LoginManager;
|
||||
import org.lastaflute.web.login.UserBean;
|
||||
import org.lastaflute.web.response.ActionResponse;
|
||||
import org.lastaflute.web.servlet.request.RequestManager;
|
||||
import org.lastaflute.web.validation.ActionValidator;
|
||||
import org.lastaflute.web.validation.LaValidatable;
|
||||
|
||||
|
@ -67,14 +58,6 @@ public abstract class FessBaseAction extends TypicalAction // has several interf
|
|||
/** The application type for FESs, e.g. used by access context. */
|
||||
protected static final String APP_TYPE = "FES"; // #change_it_first
|
||||
|
||||
// ===================================================================================
|
||||
// Attribute
|
||||
// =========
|
||||
@Resource
|
||||
private RequestManager requestManager;
|
||||
@Resource
|
||||
private FessConfig fessConfig;
|
||||
|
||||
// ===================================================================================
|
||||
// Hook
|
||||
// ======
|
||||
|
@ -104,6 +87,12 @@ 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) {
|
||||
}
|
||||
|
||||
// ===================================================================================
|
||||
|
@ -166,98 +155,4 @@ public abstract class FessBaseAction extends TypicalAction // has several interf
|
|||
public FessMessages createMessages() { // application may call
|
||||
return new FessMessages(); // overriding to change return type to concrete-class
|
||||
}
|
||||
|
||||
// ===================================================================================
|
||||
// Conversion Helper
|
||||
// =================
|
||||
// #app_customize you can customize the conversion logic
|
||||
// -----------------------------------------------------
|
||||
// to Local Date
|
||||
// -------------
|
||||
protected OptionalThing<LocalDate> toDate(String exp) { // application may call
|
||||
if (isNotEmpty(exp)) {
|
||||
return OptionalThing.of(new HandyDate(exp, myConvZone()).getLocalDate());
|
||||
} else {
|
||||
return OptionalThing.ofNullable(null, () -> {
|
||||
throw new IllegalStateException("The specified expression for local date was null or empty: " + exp);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected OptionalThing<LocalDateTime> toDateTime(String exp) { // application may call
|
||||
if (isNotEmpty(exp)) {
|
||||
return OptionalThing.of(new HandyDate(exp, myConvZone()).getLocalDateTime());
|
||||
} else {
|
||||
return OptionalThing.ofNullable(null, () -> {
|
||||
throw new IllegalStateException("The specified expression for local date was null or empty: " + exp);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// to Display Date
|
||||
// ---------------
|
||||
protected OptionalThing<String> toDispDate(LocalDate date) { // application may call
|
||||
if (date != null) {
|
||||
return OptionalThing.of(new HandyDate(date, myConvZone()).toDisp(myDatePattern()));
|
||||
} else {
|
||||
return OptionalThing.ofNullable(null, () -> {
|
||||
throw new IllegalStateException("The specified local date was null.");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected OptionalThing<String> toDispDate(LocalDateTime dateTime) { // application may call
|
||||
if (dateTime != null) {
|
||||
return OptionalThing.of(new HandyDate(dateTime, myConvZone()).toDisp(myDatePattern()));
|
||||
} else {
|
||||
return OptionalThing.ofNullable(null, () -> {
|
||||
throw new IllegalStateException("The specified local date-time was null.");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected OptionalThing<String> toDispDateTime(LocalDateTime dateTime) { // application may call
|
||||
if (dateTime != null) {
|
||||
return OptionalThing.of(new HandyDate(dateTime, myConvZone()).toDisp(myDateTimePattern()));
|
||||
} else {
|
||||
return OptionalThing.ofNullable(null, () -> {
|
||||
throw new IllegalStateException("The specified local date-time was null.");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Conversion Resource
|
||||
// -------------------
|
||||
protected String myDatePattern() {
|
||||
return "yyyy/MM/dd";
|
||||
}
|
||||
|
||||
protected String myDateTimePattern() {
|
||||
return "yyyy/MM/dd HH:mm:ss";
|
||||
}
|
||||
|
||||
protected TimeZone myConvZone() {
|
||||
return requestManager.getUserTimeZone();
|
||||
}
|
||||
|
||||
// ===================================================================================
|
||||
// Document
|
||||
// ========
|
||||
/**
|
||||
* {@inheritDoc} <br>
|
||||
* Application Origin Methods:
|
||||
* <pre>
|
||||
* <span style="font-size: 130%; color: #553000">[Conversion Helper]</span>
|
||||
* o toDate(exp) <span style="color: #3F7E5E">// convert expression to local date</span>
|
||||
* o toDateTime(exp) <span style="color: #3F7E5E">// convert expression to local date-time</span>
|
||||
* o toDispDate(date) <span style="color: #3F7E5E">// convert local date to display expression</span>
|
||||
* o toDispDateTime(date) <span style="color: #3F7E5E">// convert local date-time to display expression</span>
|
||||
* </pre>
|
||||
*/
|
||||
@Override
|
||||
public void document1_CallableSuperMethod() {
|
||||
super.document1_CallableSuperMethod();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
}
|
Loading…
Add table
Reference in a new issue