1 5 package com.opensymphony.webwork.interceptor; 6 7 import com.opensymphony.webwork.ServletActionContext; 8 import com.opensymphony.webwork.WebWorkStatics; 9 import com.opensymphony.webwork.util.ServletContextAware; 10 import com.opensymphony.xwork.ActionContext; 11 import com.opensymphony.xwork.ActionInvocation; 12 import com.opensymphony.xwork.interceptor.AroundInterceptor; 13 14 import javax.servlet.http.HttpServletRequest ; 15 import javax.servlet.http.HttpServletResponse ; 16 17 18 36 public class ServletConfigInterceptor extends AroundInterceptor implements WebWorkStatics { 37 39 42 protected void after(ActionInvocation dispatcher, String result) throws Exception { 43 } 44 45 53 protected void before(ActionInvocation invocation) throws Exception { 54 final Object action = invocation.getAction(); 55 final ActionContext context = ActionContext.getContext(); 56 57 if (action instanceof ServletRequestAware) { 58 HttpServletRequest request = (HttpServletRequest ) context.get(HTTP_REQUEST); 59 ((ServletRequestAware) action).setServletRequest(request); 60 } 61 62 if (action instanceof ServletResponseAware) { 63 HttpServletResponse response = (HttpServletResponse ) context.get(HTTP_RESPONSE); 64 ((ServletResponseAware) action).setServletResponse(response); 65 } 66 67 if (action instanceof ParameterAware) { 68 ((ParameterAware) action).setParameters(context.getParameters()); 69 } 70 71 if (action instanceof SessionAware) { 72 ((SessionAware) action).setSession(context.getSession()); 73 } 74 75 if (action instanceof ApplicationAware) { 76 ((ApplicationAware) action).setApplication(context.getApplication()); 77 } 78 79 if (action instanceof PrincipalAware) { 80 HttpServletRequest request = (HttpServletRequest ) context.get(HTTP_REQUEST); 81 ((PrincipalAware) action).setPrincipalProxy(new PrincipalProxy(request)); 82 } 83 if (action instanceof ServletContextAware) { 84 ((ServletContextAware) action).setServletContext(ServletActionContext.getServletContext()); 85 } 86 } 87 } 88 | Popular Tags |