Author: igorz
Date: 2007-12-13 06:49:23 -0500 (Thu, 13 Dec 2007)
New Revision: 91218

Modified:
   branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Control.cs
   branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Page.cs
   branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Page.jsf.cs
   branches/mainsoft/JSF/mcs/class/System.Web/System.Web/HttpContext.cs
   branches/mainsoft/JSF/mcs/class/System.Web/System.Web/HttpRequest.jvm.cs
   branches/mainsoft/JSF/mcs/class/System.Web/System.Web/HttpServerUtility.cs
Log:
support Transfer/Execute and CrossPagePostBack

Modified: branches/mainsoft/JSF/mcs/class/System.Web/System.Web/HttpContext.cs
===================================================================
--- branches/mainsoft/JSF/mcs/class/System.Web/System.Web/HttpContext.cs        
2007-12-13 11:48:50 UTC (rev 91217)
+++ branches/mainsoft/JSF/mcs/class/System.Web/System.Web/HttpContext.cs        
2007-12-13 11:49:23 UTC (rev 91218)
@@ -72,7 +72,6 @@
                object config_timeout;
                int timeout_possible;
                DateTime time_stamp = DateTime.UtcNow;
-               bool inTransit; // the page is being transferred to another
 
 #if NET_2_0
 #if TARGET_JVM
@@ -87,11 +86,6 @@
                ProfileBase profile = null;
                LinkedList<IHttpHandler> handlers;
 #endif
-
-               internal bool InTransit {
-                       get { return inTransit; }
-                       set { inTransit = value; }
-               }
                
                public HttpContext (HttpWorkerRequest wr)
                {
@@ -632,19 +626,5 @@
                }
 #endif
 #endregion
-
-#if NET_2_0
-               Page last_page;
-               
-               internal Page LastPage {
-                       get {
-                               return last_page;
-                       }
-
-                       set {
-                               last_page = value;
-                       }
-               }
-#endif
        }
 }

Modified: 
branches/mainsoft/JSF/mcs/class/System.Web/System.Web/HttpRequest.jvm.cs
===================================================================
--- branches/mainsoft/JSF/mcs/class/System.Web/System.Web/HttpRequest.jvm.cs    
2007-12-13 11:48:50 UTC (rev 91217)
+++ branches/mainsoft/JSF/mcs/class/System.Web/System.Web/HttpRequest.jvm.cs    
2007-12-13 11:49:23 UTC (rev 91218)
@@ -226,6 +226,7 @@
 
                internal void SetWorkerRequest (HttpWorkerRequest wr) {
                        worker_request = wr;
+                       current_exe_path = null;
                }
 
        }

Modified: 
branches/mainsoft/JSF/mcs/class/System.Web/System.Web/HttpServerUtility.cs
===================================================================
--- branches/mainsoft/JSF/mcs/class/System.Web/System.Web/HttpServerUtility.cs  
2007-12-13 11:48:50 UTC (rev 91217)
+++ branches/mainsoft/JSF/mcs/class/System.Web/System.Web/HttpServerUtility.cs  
2007-12-13 11:49:23 UTC (rev 91218)
@@ -102,52 +102,63 @@
                internal
 #endif
                void Execute (string path, TextWriter writer, bool preserveForm)
-               {                       
+               {
+                       Execute (path, writer, preserveForm, false);
+               }
+
+               void Execute (string path, TextWriter writer, bool 
preserveForm, bool isTransfer) {
                        if (path == null)
                                throw new ArgumentNullException ("path");
 
                        if (path.IndexOf (':') != -1)
                                throw new ArgumentException ("Invalid path.");
 
-                       HttpRequest request = context.Request;
-                       string oldQuery = request.QueryStringRaw;
+                       string queryString = null;
                        int qmark = path.IndexOf ('?');
                        if (qmark != -1) {
-                               request.QueryStringRaw = path.Substring (qmark 
+ 1);
+                               queryString = path.Substring (qmark + 1);
                                path = path.Substring (0, qmark);
+                       }
+
+                       string exePath = UrlUtils.Combine 
(context.Request.BaseVirtualDir, path);
+                       IHttpHandler handler = 
context.ApplicationInstance.GetHandler (context, exePath);
+
+                       Execute (handler, writer, preserveForm, exePath, 
queryString, isTransfer);
+               }
+
+               void Execute (IHttpHandler handler, TextWriter writer, bool 
preserveForm, string exePath, string queryString, bool isTransfer) {
+#if NET_2_0 && !TARGET_J2EE
+                       // If the target handler is not Page, the transfer must 
not occur.
+                       // InTransit == true means we're being called from 
Transfer
+                       if (isTransfer && !(handler is Page))
+                               throw new HttpException ("Transfer is possible 
only to .aspx files");
+#endif
+
+                       HttpRequest request = context.Request;
+                       string oldQuery = request.QueryStringRaw;
+                       if (queryString != null) {
+                               request.QueryStringRaw = queryString;
                        } else if (!preserveForm) {
-                               request.QueryStringRaw = "";
+                               request.QueryStringRaw = String.Empty;
                        }
 
                        HttpResponse response = context.Response;
-                       WebROCollection oldForm = null;
+                       WebROCollection oldForm = request.Form as 
WebROCollection;
                        if (!preserveForm) {
-                               oldForm = request.Form as WebROCollection;
                                request.SetForm (new WebROCollection ());
                        }
 
                        TextWriter output = writer;
                        if (output == null)
                                output = response.Output;
-
-                       string exePath = UrlUtils.Combine 
(request.BaseVirtualDir, path);
-                       IHttpHandler handler = 
context.ApplicationInstance.GetHandler (context, exePath);
-
-#if NET_2_0 && !TARGET_J2EE
-                       // If the target handler is not Page, the transfer must 
not occur.
-                       // InTransit == true means we're being called from 
Transfer
-                       if (context.InTransit && !(handler is Page))
-                               throw new HttpException ("Transfer is possible 
only to .aspx files");
-#endif
                        
-                       TextWriter previous = null;
+                       TextWriter previous = response.SetTextWriter (output);
                        string oldExePath = request.CurrentExecutionFilePath;
                        try {
 #if NET_2_0
                                context.PushHandler (handler);
 #endif
                                request.SetCurrentExePath (exePath);
-                               previous = response.SetTextWriter (output);
                                
                                if (!(handler is IHttpAsyncHandler)) {
 #if TARGET_J2EE
@@ -182,7 +193,6 @@
                                response.SetTextWriter (previous);
                                if (!preserveForm)
                                        request.SetForm (oldForm);
-                               context.InTransit = false;
 #if NET_2_0
                                context.PopHandler ();
 #endif
@@ -224,29 +234,11 @@
 
                public void Transfer (string path)
                {
-                       // If it's a page and a postback, don't pass form data
-                       // See bug #65613.
-                       bool preserveForm = true;
-                       if (context.Handler is Page) {
-                               Page page = (Page) context.Handler;
-                               preserveForm = !page.IsPostBack;
-                       }
-                       //#if NET_2_0
-                       //            else
-                       //                throw new HttpException ("Transfer 
may only be called from within a Page instance");
-                       //#endif
-
-                       Transfer (path, preserveForm);
+                       Transfer (path, true);
                }
 
                public void Transfer (string path, bool preserveForm) {
-                       //#if NET_2_0
-                       //            if (!(context.Handler is Page))
-                       //                throw new HttpException ("Transfer 
may only be called from within a Page instance");
-                       //#endif
-
-                       context.InTransit = true;
-                       Execute (path, null, preserveForm);
+                       Execute (path, null, preserveForm, true);
                        context.Response.End ();
                }
 #if NET_2_0
@@ -254,82 +246,22 @@
                {
                        if (handler == null)
                                throw new ArgumentNullException ("handler");
-                       //if (!(handler is Page))
-                       //    throw new HttpException ("Transfer may only be 
called from within a Page instance");
 
                        // TODO: see the MS doc and search for 
"enableViewStateMac": this method is not
                        // allowed for pages when preserveForm is true and the 
page IsCallback property
                        // is true.
-                       context.InTransit = true;
-                       Execute (handler, null, preserveForm);
+                       Execute (handler, null, preserveForm, 
context.Request.CurrentExecutionFilePath, null, true);
                        context.Response.End ();
                }
+#endif
 
+#if NET_2_0
                public void Execute (IHttpHandler handler, TextWriter writer, 
bool preserveForm)
                {
                        if (handler == null)
                                throw new ArgumentNullException ("handler");
 
-#if !TARGET_J2EE
-                       // If the target handler is not Page, the transfer must 
not occur.
-                       // InTransit == true means we're being called from 
Transfer
-                       if (context.InTransit && !(handler is Page))
-                               throw new HttpException ("Transfer is possible 
only to .aspx files");
-#endif
-
-                       HttpRequest request = context.Request;
-                       string oldQuery = request.QueryStringRaw;
-                       if (!preserveForm) {
-                               request.QueryStringRaw = "";
-                       }
-
-                       HttpResponse response = context.Response;
-                       WebROCollection oldForm = null;
-                       if (!preserveForm) {
-                               oldForm = request.Form as WebROCollection;
-                               request.SetForm (new WebROCollection ());
-                       }
-
-                       TextWriter output = writer;
-                       if (output == null)
-                               output = response.Output;
-
-                       TextWriter previous = null;
-                       try {
-                               previous = response.SetTextWriter (output);
-                               if (!(handler is IHttpAsyncHandler)) {
-#if TARGET_J2EE
-                                       if (!preserveForm && handler is 
IHttpExtendedHandler) {
-                                               IHttpExtendedHandler ehandler = 
(IHttpExtendedHandler) handler;
-                                               object oldState = 
ehandler.GetContextState (context);
-                                               if (oldState != null)
-                                                       
ehandler.SetContextState (context, null);
-                                               try {
-                                                       handler.ProcessRequest 
(context);
-                                               }
-                                               finally {
-                                                       if (oldState != null)
-                                                               
ehandler.SetContextState (context, oldState);
-                                               }
-                                       }
-                                       else
-#endif
-                                       handler.ProcessRequest (context);
-                               } else {
-                                       IHttpAsyncHandler asyncHandler = 
(IHttpAsyncHandler) handler;
-                                       IAsyncResult ar = 
asyncHandler.BeginProcessRequest (context, null, null);
-                                       ar.AsyncWaitHandle.WaitOne ();
-                                       asyncHandler.EndProcessRequest (ar);
-                               }
-                       } finally {
-                               if (oldQuery != null && oldQuery != "" && 
oldQuery != request.QueryStringRaw) {
-                                       oldQuery = oldQuery.Substring (1); // 
Ignore initial '?'
-                                       request.QueryStringRaw = oldQuery; // 
which is added here.
-                               }
-                               response.SetTextWriter (previous);
-                               if (!preserveForm)
-                                       request.SetForm (oldForm);
-                       }
+                       Execute (handler, writer, preserveForm, 
context.Request.CurrentExecutionFilePath, null, false);
                }
 
                public static byte[] UrlTokenDecode (string input)

Modified: branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Control.cs
===================================================================
--- branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Control.cs 
2007-12-13 11:48:50 UTC (rev 91217)
+++ branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Control.cs 
2007-12-13 11:49:23 UTC (rev 91218)
@@ -823,10 +823,10 @@
 
                Control LookForControlByName (string id)
                {
-#if TARGET_J2EE
-                       if (this == Page && id != null && id == 
Page.PortletNamespace)
-                               return this;
-#endif
+//#if TARGET_J2EE
+//            if (this == Page && id != null && id == Page.PortletNamespace)
+//                return this;
+//#endif
                        EnsureControlsCache ();
                        return (Control) _controlsCache [id];
                }

Modified: branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Page.cs
===================================================================
--- branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Page.cs    
2007-12-13 11:48:50 UTC (rev 91217)
+++ branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Page.cs    
2007-12-13 11:49:23 UTC (rev 91218)
@@ -387,7 +387,7 @@
 #if NET_2_0
                        return isPostBack;
 #else
-                       return _requestValueCollection != null && 
!HttpContext.Current.InTransit;
+                       return _requestValueCollection != null;
 #endif
                }
        }
@@ -760,6 +760,15 @@
        [EditorBrowsable (EditorBrowsableState.Advanced)]
        protected virtual NameValueCollection DeterminePostBackMode ()
        {
+#if !TARGET_J2EE
+               // if request was transfered from other page such Transfer
+#if NET_2_0
+               if(!isCrossPagePostBack)
+#endif
+               if (this != _context.Handler)
+                       return null;
+#endif
+
                HttpRequest req = Request;
                if (req == null)
                        return null;
@@ -777,14 +786,23 @@
                else
                        allow_load = (c.ID == GetTypeHashCode ());
 
-//#if TARGET_J2EE
-//        if (Context.IsActionRequest)
-//            return coll;
-//#endif
-
                if (coll != null && coll ["__VIEWSTATE"] == null && coll 
["__EVENTTARGET"] == null)
                        return null;
-
+#if TARGET_J2EE
+               if (this != _context.Handler) {
+                       if (getFacesContext () != null) {
+                               // check if it is PreviousPage
+                               string prevViewId = coll [PreviousPageID];
+                               if (!String.IsNullOrEmpty (prevViewId)) {
+                                       string appPath = 
VirtualPathUtility.RemoveTrailingSlash (Request.ApplicationPath);
+                                       prevViewId = prevViewId.Substring 
(appPath.Length);
+                                       isCrossPagePostBack = String.Compare 
(prevViewId, getFacesContext ().getExternalContext ().getRequestPathInfo (), 
StringComparison.OrdinalIgnoreCase) == 0;
+                               }
+                       }
+                       if (!isCrossPagePostBack)
+                               return null;
+               }
+#endif
                return coll;
        }
 
@@ -1177,6 +1195,15 @@
 #if NET_2_0
                _lifeCycle = PageLifeCycle.Unknown;
 #endif
+#if TARGET_J2EE
+               if (getFacesContext () != null) {
+                       _jsfHandler = context.CurrentHandler;
+                       context.PopHandler ();
+                       context.PushHandler (this);
+                       if (_jsfHandler == context.Handler)
+                               context.Handler = this;
+               }
+#endif
                SetContext (context);
                
                if (clientTarget != null)
@@ -1194,7 +1221,7 @@
                try {
                        InternalProcessRequest ();
                }
-#if TARGET_JVM
+#if TARGET_J2EE
                catch (Exception ex) {
                        HandleException (ex);
                        throw;
@@ -1232,6 +1259,17 @@
                                _lifeCycle = PageLifeCycle.End;
 #endif
                        } catch {}
+#if TARGET_J2EE
+                       if (getFacesContext () != null) {
+                               _context.PopHandler ();
+                               _context.PushHandler (_jsfHandler);
+                               if (this == _context.Handler)
+                                       _context.Handler = _jsfHandler;
+
+                               if(IsCrossPagePostBack)
+                                       _context.Items [CrossPagePostBack] = 
this;
+                       }
+#endif
                        if (Thread.CurrentThread.CurrentCulture.Equals 
(_appCulture) == false)
                                Thread.CurrentThread.CurrentCulture = 
_appCulture;
 
@@ -1301,22 +1339,14 @@
        protected void AsyncPageEndProcessRequest (IAsyncResult result) 
        {
        }
-
-       internal void ProcessCrossPagePostBack (HttpContext context)
-       {
-               isCrossPagePostBack = true;
-               ProcessRequest (context);
-       }
 #endif
 
        void InternalProcessRequest ()
        {
                _requestValueCollection = this.DeterminePostBackMode();
+               
+#if NET_2_0
 
-#if NET_2_0
-               HttpContext ctx = Context;
-                               
-               _lifeCycle = PageLifeCycle.Start;
                // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
                if (_requestValueCollection != null) {
                        if (!isCrossPagePostBack && _requestValueCollection 
[PreviousPageID] != null && _requestValueCollection [PreviousPageID] != 
Request.FilePath) {
@@ -1326,7 +1356,7 @@
                                isCallback = _requestValueCollection 
[CallbackArgumentID] != null;
                                // LAMESPEC: on Callback IsPostBack is set to 
false, but true.
                                //isPostBack = !isCallback;
-                               isPostBack = !ctx.InTransit;
+                               isPostBack = true;
                        }
                        string lastFocus = _requestValueCollection 
[LastFocusID];
                        if (!String.IsNullOrEmpty (lastFocus)) {
@@ -1334,9 +1364,11 @@
                        }
                }
                
-               // if request was transfered from other page - track Prev. Page
-               previousPage = ctx.LastPage;
-               ctx.LastPage = this;
+               if (!isCrossPagePostBack) {
+                       if (_context.PreviousHandler is Page) {
+                               previousPage = (Page) _context.PreviousHandler;
+                       }
+               }
 
                _lifeCycle = PageLifeCycle.PreInit;
                Trace.Write ("aspx.page", "Begin PreInit");
@@ -1361,8 +1393,11 @@
                renderingForm = false;  
 
 #if TARGET_J2EE
-               if (getFacesContext () != null)
+               if (getFacesContext () != null) {
+                       if (!(IsPostBack || IsCallback))
+                               getFacesContext ().renderResponse ();
                        return;
+               }
 #endif
 
                RestorePageState ();
@@ -1541,7 +1576,10 @@
                //--
                Trace.Write ("aspx.page", "Begin Render");
                HtmlTextWriter output = new HtmlTextWriter (Response.Output);
-               SetupResponseWriter (output);
+#if TARGET_J2EE
+               if (getFacesContext () != null)
+                       SetupResponseWriter (output);
+#endif
                RenderControl (output);
                Trace.Write ("aspx.page", "End Render");
        }
@@ -2636,8 +2674,21 @@
                if (_requestValueCollection != null) {
                        string prevPage = _requestValueCollection 
[PreviousPageID];
                        if (prevPage != null) {
+#if TARGET_J2EE
+                               if (getFacesContext () != null) {
+                                       IHttpHandler handler = 
Context.ApplicationInstance.GetHandler (Context, prevPage);
+                                       Server.Execute (handler, null, true);
+                                       if (_context.Items.Contains 
(CrossPagePostBack)) {
+                                               previousPage = (Page) 
_context.Items [CrossPagePostBack];
+                                               _context.Items.Remove 
(CrossPagePostBack);
+                                       }
+                                       return;
+                               }
+#else
                                previousPage = (Page) 
PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), 
Context);
-                               previousPage.ProcessCrossPagePostBack (Context);
+                               previousPage.isCrossPagePostBack = true;
+                               previousPage.ProcessRequest (Context);
+#endif
                        } 
                }
        }

Modified: branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Page.jsf.cs
===================================================================
--- branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Page.jsf.cs        
2007-12-13 11:48:50 UTC (rev 91217)
+++ branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Page.jsf.cs        
2007-12-13 11:49:23 UTC (rev 91218)
@@ -90,6 +90,8 @@
                bool [] _validatorsState;
                ICallbackEventHandler _callbackTarget;
                string _callbackEventError = String.Empty;
+               IHttpHandler _jsfHandler;
+               static readonly object CrossPagePostBack = new object ();
 
                void EnterThread (FacesContext context) {
                        if (_lifeCycle == PageLifeCycle.Unknown)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to