KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > internal > PageFlowRequestWrapper


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

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 JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.ServletRequest JavaDoc;
27 import javax.servlet.ServletRequestWrapper JavaDoc;
28
29 public final class PageFlowRequestWrapper
30         extends HttpServletRequestWrapper JavaDoc
31 {
32     private static final class State
33     {
34         public Integer JavaDoc forwardedRequestCount;
35         public String JavaDoc originalServletPath;
36         public FlowController currentFlowController;
37         public ViewRenderer viewRenderer;
38         public PreviousPageInfo previousPageInfo;
39         public boolean returningFromActionIntercept = false;
40         public String JavaDoc 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 JavaDoc servletRequest )
49     {
50         servletRequest = InternalUtils.unwrapMultipart( servletRequest );
51         assert servletRequest instanceof PageFlowRequestWrapper : servletRequest.getClass().getName();
52         return ( PageFlowRequestWrapper ) servletRequest;
53     }
54     
55     /**
56      * Unwrap to find the PageFlowRequestWrapper. This method may return <code>null</code>.
57      */

58     public static PageFlowRequestWrapper unwrap( ServletRequest JavaDoc servletRequest )
59     {
60         servletRequest = InternalUtils.unwrapMultipart( servletRequest );
61         
62         while ( ! ( servletRequest instanceof PageFlowRequestWrapper ) )
63         {
64             if ( ! ( servletRequest instanceof ServletRequestWrapper JavaDoc ) ) return null;
65             servletRequest = ( ( ServletRequestWrapper JavaDoc ) 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 JavaDoc 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 JavaDoc( count );
94     }
95
96     public String JavaDoc getOriginalServletPath()
97     {
98         return _state.originalServletPath;
99     }
100
101     public void setOriginalServletPath( String JavaDoc 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 JavaDoc getHttpRequest()
149     {
150         return ( HttpServletRequest JavaDoc ) super.getRequest();
151     }
152     
153     public String JavaDoc getPageFlowScopedFormName()
154     {
155         return _state.pageFlowScopedFormName;
156     }
157     
158     public void setPageFlowScopedFormName( String JavaDoc 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 JavaDoc 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         //
206
// If there's *any* PageFlowRequestWrapper up the chain of wrapped requests, we must copy values from that.
207
//
208
ServletRequest JavaDoc j = retVal.getRequest();
209         while ( j instanceof HttpServletRequestWrapper JavaDoc )
210         {
211             if ( j instanceof PageFlowRequestWrapper )
212             {
213                 retVal.initFrom( ( PageFlowRequestWrapper ) j );
214                 break;
215             }
216             
217             j = ( ( HttpServletRequestWrapper JavaDoc ) j ).getRequest();
218         }
219         
220         return retVal;
221     }
222 }
223
Popular Tags