1 16 17 package org.springframework.web.portlet.handler; 18 19 import javax.portlet.ActionRequest; 20 import javax.portlet.ActionResponse; 21 import javax.portlet.RenderRequest; 22 import javax.portlet.RenderResponse; 23 24 import org.springframework.util.Assert; 25 import org.springframework.web.context.request.WebRequestInterceptor; 26 import org.springframework.web.portlet.HandlerInterceptor; 27 import org.springframework.web.portlet.ModelAndView; 28 import org.springframework.web.portlet.context.PortletWebRequest; 29 30 46 public class WebRequestHandlerInterceptorAdapter implements HandlerInterceptor { 47 48 private final WebRequestInterceptor requestInterceptor; 49 50 private final boolean renderPhaseOnly; 51 52 53 58 public WebRequestHandlerInterceptorAdapter(WebRequestInterceptor requestInterceptor) { 59 this(requestInterceptor, true); 60 } 61 62 68 public WebRequestHandlerInterceptorAdapter(WebRequestInterceptor requestInterceptor, boolean renderPhaseOnly) { 69 Assert.notNull(requestInterceptor, "WebRequestInterceptor must not be null"); 70 this.requestInterceptor = requestInterceptor; 71 this.renderPhaseOnly = renderPhaseOnly; 72 } 73 74 75 public boolean preHandleAction(ActionRequest request, ActionResponse response, Object handler) throws Exception { 76 if (!this.renderPhaseOnly) { 77 this.requestInterceptor.preHandle(new PortletWebRequest(request)); 78 } 79 return true; 80 } 81 82 public void afterActionCompletion( 83 ActionRequest request, ActionResponse response, Object handler, Exception ex) throws Exception { 84 85 if (!this.renderPhaseOnly) { 86 this.requestInterceptor.afterCompletion(new PortletWebRequest(request), ex); 87 } 88 } 89 90 public boolean preHandleRender(RenderRequest request, RenderResponse response, Object handler) throws Exception { 91 this.requestInterceptor.preHandle(new PortletWebRequest(request)); 92 return true; 93 } 94 95 public void postHandleRender( 96 RenderRequest request, RenderResponse response, Object handler, ModelAndView modelAndView) throws Exception { 97 98 this.requestInterceptor.postHandle(new PortletWebRequest(request), 99 (modelAndView != null ? modelAndView.getModelMap() : null)); 100 } 101 102 public void afterRenderCompletion( 103 RenderRequest request, RenderResponse response, Object handler, Exception ex) throws Exception { 104 105 this.requestInterceptor.afterCompletion(new PortletWebRequest(request), ex); 106 } 107 108 } 109 | Popular Tags |