diff --git a/src/main/java/org/codelibs/fess/app/web/base/FessBaseAction.java b/src/main/java/org/codelibs/fess/app/web/base/FessBaseAction.java index 91a885a5c..1aa81c9f8 100644 --- a/src/main/java/org/codelibs/fess/app/web/base/FessBaseAction.java +++ b/src/main/java/org/codelibs/fess/app/web/base/FessBaseAction.java @@ -20,6 +20,7 @@ import javax.annotation.Resource; import org.codelibs.fess.app.web.base.login.FessLoginAssist; import org.codelibs.fess.helper.ActivityHelper; import org.codelibs.fess.helper.SystemHelper; +import org.codelibs.fess.helper.ViewHelper; import org.codelibs.fess.mylasta.action.FessHtmlPath; import org.codelibs.fess.mylasta.action.FessMessages; import org.codelibs.fess.mylasta.action.FessUserBean; @@ -78,6 +79,9 @@ public abstract class FessBaseAction extends TypicalAction // has several interf @Resource protected SystemHelper systemHelper; + @Resource + protected ViewHelper viewHelper; + @Resource private MessageManager messageManager; @@ -91,28 +95,28 @@ public abstract class FessBaseAction extends TypicalAction // has several interf // you should remove the 'final' if you need to override this @Override public ActionResponse godHandPrologue(final ActionRuntime runtime) { - return super.godHandPrologue(runtime); + return viewHelper.getActionHook().godHandPrologue(runtime, r -> super.godHandPrologue(r)); } @Override public final ActionResponse godHandMonologue(final ActionRuntime runtime) { - return super.godHandMonologue(runtime); + return viewHelper.getActionHook().godHandMonologue(runtime, r -> super.godHandMonologue(r)); } @Override public final void godHandEpilogue(final ActionRuntime runtime) { - super.godHandEpilogue(runtime); + viewHelper.getActionHook().godHandEpilogue(runtime, r -> super.godHandEpilogue(r)); } // #app_customize you can customize the action hook @Override public ActionResponse hookBefore(final ActionRuntime runtime) { // application may override - return super.hookBefore(runtime); + return viewHelper.getActionHook().hookBefore(runtime, r -> super.hookBefore(r)); } @Override public void hookFinally(final ActionRuntime runtime) { - super.hookFinally(runtime); + viewHelper.getActionHook().hookFinally(runtime, r -> super.hookFinally(r)); } // =================================================================================== diff --git a/src/main/java/org/codelibs/fess/helper/ViewHelper.java b/src/main/java/org/codelibs/fess/helper/ViewHelper.java index f831b189f..ab31c4bd1 100644 --- a/src/main/java/org/codelibs/fess/helper/ViewHelper.java +++ b/src/main/java/org/codelibs/fess/helper/ViewHelper.java @@ -29,6 +29,8 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; +import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -62,7 +64,9 @@ import org.codelibs.fess.util.ComponentUtil; import org.codelibs.fess.util.DocumentUtil; import org.codelibs.fess.util.ResourceUtil; import org.lastaflute.taglib.function.LaFunctions; +import org.lastaflute.web.response.ActionResponse; import org.lastaflute.web.response.StreamResponse; +import org.lastaflute.web.ruts.process.ActionRuntime; import org.lastaflute.web.util.LaRequestUtil; import org.lastaflute.web.util.LaResponseUtil; import org.lastaflute.web.util.LaServletContextUtil; @@ -132,6 +136,8 @@ public class ViewHelper { private String escapedHighlightPost = null; + protected ActionHook actionHook = new ActionHook(); + @PostConstruct public void init() { escapedHighlightPre = LaFunctions.h(originalHighlightTagPre); @@ -650,4 +656,34 @@ public class ViewHelper { return facetQueryViewList; } + public ActionHook getActionHook() { + return actionHook; + } + + public void setActionHook(ActionHook actionHook) { + this.actionHook = actionHook; + } + + public static class ActionHook { + + public ActionResponse godHandPrologue(ActionRuntime runtime, Function func) { + return func.apply(runtime); + } + + public ActionResponse godHandMonologue(ActionRuntime runtime, Function func) { + return func.apply(runtime); + } + + public void godHandEpilogue(ActionRuntime runtime, Consumer consumer) { + consumer.accept(runtime); + } + + public ActionResponse hookBefore(ActionRuntime runtime, Function func) { + return func.apply(runtime); + } + + public void hookFinally(ActionRuntime runtime, Consumer consumer) { + consumer.accept(runtime); + } + } }