fix #914 add ActionHook
This commit is contained in:
parent
9331f3c8d2
commit
c28e9be164
2 changed files with 42 additions and 10 deletions
|
@ -19,11 +19,11 @@ import javax.annotation.Resource;
|
|||
|
||||
import org.codelibs.fess.app.web.base.login.FessLoginAssist;
|
||||
import org.codelibs.fess.helper.ActivityHelper;
|
||||
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;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.dbflute.hook.AccessContext;
|
||||
import org.dbflute.optional.OptionalThing;
|
||||
import org.lastaflute.core.time.TimeManager;
|
||||
|
@ -73,6 +73,9 @@ public abstract class FessBaseAction extends TypicalAction // has several interf
|
|||
@Resource
|
||||
protected TimeManager timeManager;
|
||||
|
||||
@Resource
|
||||
protected ViewHelper viewHelper;
|
||||
|
||||
// ===================================================================================
|
||||
// Hook
|
||||
// ======
|
||||
|
@ -80,31 +83,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) {
|
||||
if (runtime.getActionType().asSubclass(FessBaseAction.class) != null) {
|
||||
ComponentUtil.getViewHelper().registerUserData(runtime);
|
||||
}
|
||||
super.hookFinally(runtime);
|
||||
viewHelper.getActionHook().hookFinally(runtime, r -> super.hookFinally(r));
|
||||
}
|
||||
|
||||
// ===================================================================================
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -61,6 +63,7 @@ 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;
|
||||
|
@ -138,6 +141,8 @@ public class ViewHelper {
|
|||
|
||||
private String escapedHighlightPost = null;
|
||||
|
||||
protected ActionHook actionHook = new ActionHook();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
escapedHighlightPre = LaFunctions.h(originalHighlightTagPre);
|
||||
|
@ -647,7 +652,34 @@ public class ViewHelper {
|
|||
return facetQueryViewList;
|
||||
}
|
||||
|
||||
public void registerUserData(final ActionRuntime runtime) {
|
||||
public ActionHook getActionHook() {
|
||||
return actionHook;
|
||||
}
|
||||
|
||||
public void setActionHook(ActionHook actionHook) {
|
||||
this.actionHook = actionHook;
|
||||
}
|
||||
|
||||
public static class ActionHook {
|
||||
|
||||
public ActionResponse godHandPrologue(ActionRuntime runtime, Function<ActionRuntime, ActionResponse> func) {
|
||||
return func.apply(runtime);
|
||||
}
|
||||
|
||||
public ActionResponse godHandMonologue(ActionRuntime runtime, Function<ActionRuntime, ActionResponse> func) {
|
||||
return func.apply(runtime);
|
||||
}
|
||||
|
||||
public void godHandEpilogue(ActionRuntime runtime, Consumer<ActionRuntime> consumer) {
|
||||
consumer.accept(runtime);
|
||||
}
|
||||
|
||||
public ActionResponse hookBefore(ActionRuntime runtime, Function<ActionRuntime, ActionResponse> func) {
|
||||
return func.apply(runtime);
|
||||
}
|
||||
|
||||
public void hookFinally(ActionRuntime runtime, Consumer<ActionRuntime> consumer) {
|
||||
consumer.accept(runtime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue