1 18 package org.apache.beehive.netui.pageflow.interceptor.request; 19 20 import org.apache.beehive.netui.pageflow.interceptor.InterceptorContext; 21 import org.apache.beehive.netui.pageflow.internal.InternalConstants; 22 import org.apache.beehive.netui.util.config.ConfigUtil; 23 import org.apache.beehive.netui.util.config.bean.RequestInterceptors; 24 25 import javax.servlet.http.HttpServletResponse ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.ServletContext ; 28 import java.util.ArrayList ; 29 import java.util.List ; 30 31 34 public class RequestInterceptorContext 35 extends InterceptorContext 36 { 37 private static final String INTERCEPTORS_LIST_ATTR = InternalConstants.ATTR_PREFIX + "requestInterceptors"; 38 39 private transient ServletContext _servletContext; 40 private transient HttpServletRequest _request; 41 private transient HttpServletResponse _response; 42 43 public RequestInterceptorContext( HttpServletRequest request, HttpServletResponse response, 44 ServletContext servletContext ) 45 { 46 _request = request; 47 _response = response; 48 _servletContext = servletContext; 49 } 50 51 public void cancelRequest( RequestInterceptor interceptor ) 52 { 53 setResultOverride( null, interceptor ); 54 } 55 56 public boolean requestWasCancelled() 57 { 58 return hasResultOverride() && getResultOverride() == null; 59 } 60 61 public HttpServletRequest getRequest() 62 { 63 return _request; 64 } 65 66 public HttpServletResponse getResponse() 67 { 68 return _response; 69 } 70 71 public ServletContext getServletContext() 72 { 73 return _servletContext; 74 } 75 76 public static void init( ServletContext servletContext ) 77 { 78 RequestInterceptors requestInterceptors = ConfigUtil.getConfig().getRequestInterceptors(); 79 80 if ( requestInterceptors != null ) 81 { 82 RequestInterceptors.Global globalRequestInterceptors = requestInterceptors.getGlobal(); 83 84 if ( globalRequestInterceptors != null ) 85 { 86 org.apache.beehive.netui.util.config.bean.Interceptor[] interceptors = 87 globalRequestInterceptors.getRequestInterceptorArray(); 88 ArrayList interceptorsList = new ArrayList (); 89 addInterceptors( interceptors, interceptorsList, RequestInterceptor.class ); 90 servletContext.setAttribute( INTERCEPTORS_LIST_ATTR, interceptorsList ); 91 } 92 } 93 } 94 95 public List getRequestInterceptors() 96 { 97 return ( List ) getServletContext().getAttribute( INTERCEPTORS_LIST_ATTR ); 98 } 99 100 public static void addInterceptor( ServletContext servletContext, RequestInterceptor interceptor ) 101 { 102 List interceptorsList = 103 ( List ) servletContext.getAttribute( INTERCEPTORS_LIST_ATTR ); 104 if ( interceptorsList == null ) interceptorsList = new ArrayList (); 105 interceptorsList.add( interceptor ); 106 servletContext.setAttribute( INTERCEPTORS_LIST_ATTR, interceptorsList ); 107 } 108 } 109 | Popular Tags |