1 18 package org.apache.beehive.netui.pageflow.internal; 19 20 import org.apache.beehive.netui.pageflow.FlowController; 21 import org.apache.beehive.netui.pageflow.PreviousPageInfo; 22 import org.apache.struts.upload.MultipartRequestWrapper; 23 24 import javax.servlet.http.HttpServletRequestWrapper ; 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.ServletRequest ; 27 import javax.servlet.ServletRequestWrapper ; 28 29 public final class PageFlowRequestWrapper 30 extends HttpServletRequestWrapper 31 { 32 private static final class State 33 { 34 public Integer forwardedRequestCount; 35 public String originalServletPath; 36 public FlowController currentFlowController; 37 public ViewRenderer viewRenderer; 38 public PreviousPageInfo previousPageInfo; 39 public boolean returningFromActionIntercept = false; 40 public String pageFlowScopedFormName; 41 public boolean processPopulateAlreadyCalled = false; 42 public boolean forwardedByButton = false; 43 public MultipartRequestWrapper multipartRequestWrapper; 44 } 45 46 private State _state = new State(); 47 48 public static PageFlowRequestWrapper get( ServletRequest servletRequest ) 49 { 50 servletRequest = InternalUtils.unwrapMultipart( servletRequest ); 51 assert servletRequest instanceof PageFlowRequestWrapper : servletRequest.getClass().getName(); 52 return ( PageFlowRequestWrapper ) servletRequest; 53 } 54 55 58 public static PageFlowRequestWrapper unwrap( ServletRequest servletRequest ) 59 { 60 servletRequest = InternalUtils.unwrapMultipart( servletRequest ); 61 62 while ( ! ( servletRequest instanceof PageFlowRequestWrapper ) ) 63 { 64 if ( ! ( servletRequest instanceof ServletRequestWrapper ) ) return null; 65 servletRequest = ( ( ServletRequestWrapper ) servletRequest ).getRequest(); 66 } 67 68 return ( PageFlowRequestWrapper ) servletRequest; 69 } 70 71 public void initFrom( PageFlowRequestWrapper wrapper ) 72 { 73 _state = wrapper._state; 74 } 75 76 public PageFlowRequestWrapper( HttpServletRequest delegate ) 77 { 78 super( delegate ); 79 } 80 81 public boolean isForwardedRequest() 82 { 83 return _state.forwardedRequestCount != null; 84 } 85 86 public int getForwardedRequestCount() 87 { 88 return _state.forwardedRequestCount != null ? _state.forwardedRequestCount.intValue() : 0; 89 } 90 91 public void setForwardedRequestCount( int count ) 92 { 93 _state.forwardedRequestCount = new Integer ( count ); 94 } 95 96 public String getOriginalServletPath() 97 { 98 return _state.originalServletPath; 99 } 100 101 public void setOriginalServletPath( String originalServletPath ) 102 { 103 _state.originalServletPath = originalServletPath; 104 } 105 106 public FlowController getCurrentFlowController() 107 { 108 return _state.currentFlowController; 109 } 110 111 public void setCurrentFlowController( FlowController currentFlowController ) 112 { 113 _state.currentFlowController = currentFlowController; 114 } 115 116 public ViewRenderer getViewRenderer() 117 { 118 return _state.viewRenderer; 119 } 120 121 public void setViewRenderer( ViewRenderer viewRenderer ) 122 { 123 _state.viewRenderer = viewRenderer; 124 } 125 126 public PreviousPageInfo getPreviousPageInfo( boolean remove ) 127 { 128 PreviousPageInfo retVal = _state.previousPageInfo; 129 if ( remove ) _state.previousPageInfo = null; 130 return retVal; 131 } 132 133 public void setPreviousPageInfo( PreviousPageInfo previousPageInfo ) 134 { 135 _state.previousPageInfo = previousPageInfo; 136 } 137 138 public boolean isReturningFromActionIntercept() 139 { 140 return _state.returningFromActionIntercept; 141 } 142 143 public void setReturningFromActionIntercept( boolean returningFromActionIntercept ) 144 { 145 _state.returningFromActionIntercept = returningFromActionIntercept; 146 } 147 148 public HttpServletRequest getHttpRequest() 149 { 150 return ( HttpServletRequest ) super.getRequest(); 151 } 152 153 public String getPageFlowScopedFormName() 154 { 155 return _state.pageFlowScopedFormName; 156 } 157 158 public void setPageFlowScopedFormName( String pageFlowScopedFormName ) 159 { 160 _state.pageFlowScopedFormName = pageFlowScopedFormName; 161 } 162 163 public boolean isProcessPopulateAlreadyCalled() 164 { 165 return _state.processPopulateAlreadyCalled; 166 } 167 168 public void setProcessPopulateAlreadyCalled( boolean processPopulateAlreadyCalled ) 169 { 170 _state.processPopulateAlreadyCalled = processPopulateAlreadyCalled; 171 } 172 173 public boolean isForwardedByButton() 174 { 175 return _state.forwardedByButton; 176 } 177 178 public void setForwardedByButton( boolean forwardedByButton ) 179 { 180 _state.forwardedByButton = forwardedByButton; 181 } 182 183 public MultipartRequestWrapper getMultipartRequestWrapper() 184 { 185 return _state.multipartRequestWrapper; 186 } 187 188 public void setMultipartRequestWrapper( MultipartRequestWrapper multipartRequestWrapper ) 189 { 190 _state.multipartRequestWrapper = multipartRequestWrapper; 191 } 192 193 public static PageFlowRequestWrapper wrapRequest( HttpServletRequest req ) 194 { 195 PageFlowRequestWrapper retVal; 196 if ( req instanceof PageFlowRequestWrapper ) 197 { 198 retVal = ( PageFlowRequestWrapper ) req; 199 } 200 else 201 { 202 retVal = new PageFlowRequestWrapper( req ); 203 } 204 205 ServletRequest j = retVal.getRequest(); 209 while ( j instanceof HttpServletRequestWrapper ) 210 { 211 if ( j instanceof PageFlowRequestWrapper ) 212 { 213 retVal.initFrom( ( PageFlowRequestWrapper ) j ); 214 break; 215 } 216 217 j = ( ( HttpServletRequestWrapper ) j ).getRequest(); 218 } 219 220 return retVal; 221 } 222 } 223 | Popular Tags |