package org.theonefx.wcframework.mvc.wcweb; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class FiltedActionProxy extends ActionProxySupport { private final Log log = LogFactory.getLog(getClass()); private final FilterChain chain; public FiltedActionProxy(FilterChain chain, ActionInvoker invoker) { super(invoker); this.chain = chain; } @Override public void doExecute(ActionInvocationContext ctx) throws Exception { DefaultActionInvocation invocation = new DefaultActionInvocation(invoker, chain, ctx); View view = null; Object result = invocation.process(); if (result instanceof View) { view = (View) result; } else { // TODO 这里需要更多的判断,以确定该返回值是一个: // 1. resultcode // 2. 页面数据本身 // 3. 需要转意的对象 String code = (String) result; View[] views = invocation.getCurrentViews(); if (code == null) { // code为空 if (views == null) { views = invocation.getActionInvoker().getViews(); } if (views != null) { if (views.length == 1) { view = views[0]; } else { for (View v : views) { if (v.getName().equalsIgnoreCase("success")) { view = v; break; } } } } // 没有返回值,没有唯一的view,没有找到名字叫做success的view,没招了。。。。 if (log.isDebugEnabled()) { if (view == null) { log.debug("找不到默认的View"); } } } else { if (views == null) { views = invocation.getActionInvoker().getViews(); } if (views != null) { if (views.length == 1) { view = views[0]; } else { // 先从返回的views中找,这个views可能是action的也可能是filter的,但是这个肯定是ActionInvocation最后一次执行的控制器所定义的 for (View v : views) { if (v.getName().equalsIgnoreCase(code)) { view = v; } } // 如果从最后一次执行的控制器所定义的views里没有找到,那就到action定义的views里面找。 views = invocation.getActionInvoker().getViews(); for (View v : views) { if (v.getName().equalsIgnoreCase(code)) { view = v; } } } } // 有返回值,没有唯一的view,也没找到对应的view。。。。 if (log.isDebugEnabled()) { if (view == null) { log.debug("找不到[" + code + "]对应的View"); } } } } if (view != null) { if (ctx.getAttrs() != null) { view.setArgs(ctx.getAttrs()); } view.render(ctx.getRequest(), ctx.getResponse()); } } }