Author: igorz
Date: 2007-12-02 11:37:12 -0500 (Sun, 02 Dec 2007)
New Revision: 90525

Modified:
   
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/AspNetFacesContext.cs
   
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseFacesStateManager.cs
   
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseFacesViewHandler.cs
   
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletFacesPageHandlerFactory.cs
   
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletFacesStateManager.cs
   
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletFacesViewHandler.cs
Log:
enhanced  JSF implementation

Modified: 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/AspNetFacesContext.cs
===================================================================
--- 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/AspNetFacesContext.cs
     2007-12-02 16:19:14 UTC (rev 90524)
+++ 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/AspNetFacesContext.cs
     2007-12-02 16:37:12 UTC (rev 90525)
@@ -11,24 +11,42 @@
        {
                readonly FacesContext _facesContex;
                readonly HttpContext _httpContext;
-               readonly Page _handler;
+               //readonly string _url;
+               //readonly string _path;
+               //Page _handler;
 
-               public Page Handler {
-                       get { return _handler; }
-               }
+               //public Page Handler {
+               //    get {
+               //        if (_handler == null)
+               //            _handler = (Page) 
PageParser.GetCompiledPageInstance (_url, _path, _httpContext);
+               //        return _handler;
+               //    }
+               //}
 
                public HttpContext Context {
                        get { return _httpContext; }
                }
 
-               protected AspNetFacesContext (FacesContext facesContex, 
HttpContext httpContext, Page handler) {
+               protected AspNetFacesContext (FacesContext facesContex, 
HttpContext httpContext) {
                        _facesContex = facesContex;
                        _httpContext = httpContext;
-                       _handler = handler;
                }
 
-               public static AspNetFacesContext WrapFacesContext (FacesContext 
facesContex, HttpContext httpContext, Page page) {
-                       AspNetFacesContext ctx = new AspNetFacesContext 
(facesContex, httpContext, page);
+               //protected AspNetFacesContext (FacesContext facesContex, 
HttpContext httpContext, Page handler) {
+               //    _facesContex = facesContex;
+               //    _httpContext = httpContext;
+               //    _handler = handler;
+               //}
+
+               //protected AspNetFacesContext (FacesContext facesContex, 
HttpContext httpContext, string url, string path) {
+               //    _facesContex = facesContex;
+               //    _httpContext = httpContext;
+               //    _url = url;
+               //    _path = path;
+               //}
+
+               public static AspNetFacesContext WrapFacesContext (FacesContext 
facesContex, HttpContext httpContext) {
+                       AspNetFacesContext ctx = new AspNetFacesContext 
(facesContex, httpContext);
                        FacesContext.setCurrentInstance (ctx);
                        return ctx;
                }

Modified: 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseFacesStateManager.cs
===================================================================
--- 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseFacesStateManager.cs
  2007-12-02 16:19:14 UTC (rev 90524)
+++ 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseFacesStateManager.cs
  2007-12-02 16:37:12 UTC (rev 90525)
@@ -25,17 +25,14 @@
                                                                                
                                                String renderKitId) {
 
                        UIViewRoot uiViewRoot = restoreTreeStructure 
(facesContext, viewId, renderKitId);
-                       if (uiViewRoot != null) {
-                               uiViewRoot.setViewId (viewId);
-                               restoreComponentState (facesContext, 
uiViewRoot, renderKitId);
-                               String restoredViewId = uiViewRoot.getViewId ();
-                               if (restoredViewId == null || 
!(restoredViewId.Equals (viewId))) {
-                                       return null;
-                               }
-                       }
+                       restoreComponentState (facesContext, uiViewRoot, 
renderKitId);
                        return uiViewRoot;
                }
 
+               protected override UIViewRoot restoreTreeStructure 
(FacesContext facesContext, string viewId, string renderKitId) {
+                       return facesContext.getApplication ().getViewHandler 
().createView (facesContext, viewId);
+               }
+
                protected override Object getComponentStateToSave (FacesContext 
facesContext) {
                        Console.WriteLine ("Entering getComponentStateToSave");
 

Modified: 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseFacesViewHandler.cs
===================================================================
--- 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseFacesViewHandler.cs
   2007-12-02 16:19:14 UTC (rev 90524)
+++ 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseFacesViewHandler.cs
   2007-12-02 16:37:12 UTC (rev 90525)
@@ -6,124 +6,62 @@
 using javax.faces.context;
 using javax.faces.component;
 using javax.faces.render;
+using System.Web.UI;
 
 namespace Mainsoft.Web.Hosting
 {
        public abstract class BaseFacesViewHandler : ViewHandler
        {
+               readonly ViewHandler _viewHandler;
 
-               public override Locale calculateLocale (FacesContext 
facesContext) {
-                       Iterator locales = facesContext.getExternalContext 
().getRequestLocales ();
-                       while (locales.hasNext ()) {
-                               Locale locale = (Locale) locales.next ();
-                               for (Iterator it = facesContext.getApplication 
().getSupportedLocales (); it.hasNext (); ) {
-                                       Locale supportLocale = (Locale) it.next 
();
-                                       // higher priority to a language match 
over an exact match
-                                       // that occures further down (see Jstl 
Reference 1.0 8.3.1)
-                                       if (locale.getLanguage ().Equals 
(supportLocale.getLanguage ()) &&
-                                               (supportLocale.getCountry () == 
null ||
-                                                       
supportLocale.getCountry ().Length == 0)) {
-                                               return supportLocale;
-                                       }
-                                       else if (supportLocale.Equals (locale)) 
{
-                                               return supportLocale;
-                                       }
-                               }
-                       }
+               public BaseFacesViewHandler (ViewHandler viewHandler) {
+                       _viewHandler = viewHandler;
+               }
 
-                       Locale defaultLocale = facesContext.getApplication 
().getDefaultLocale ();
-                       return defaultLocale != null ? defaultLocale : 
Locale.getDefault ();
+               public override string getActionURL (FacesContext facesContext, 
string viewId) {
+                       return _viewHandler.getActionURL (facesContext, viewId);
                }
 
+               public override Locale calculateLocale (FacesContext 
facesContext) {
+                       return _viewHandler.calculateLocale (facesContext);
+               }
+
                public override String calculateRenderKitId (FacesContext 
facesContext) {
-                       String renderKitId = facesContext.getApplication 
().getDefaultRenderKitId ();
-                       return (renderKitId != null) ? renderKitId : 
RenderKitFactory.HTML_BASIC_RENDER_KIT;
-                       //TODO: how to calculate from client?
+                       return _viewHandler.calculateRenderKitId (facesContext);
                }
 
-               /**
-                */
                public override UIViewRoot createView (FacesContext 
facesContext, String viewId) {
-                       Application application = facesContext.getApplication 
();
-                       ViewHandler applicationViewHandler = 
application.getViewHandler ();
-
-                       Locale currentLocale = null;
-                       String currentRenderKitId = null;
-                       UIViewRoot uiViewRoot = facesContext.getViewRoot ();
-                       if (uiViewRoot != null) {
-                               //Remember current locale and renderKitId
-                               currentLocale = uiViewRoot.getLocale ();
-                               currentRenderKitId = uiViewRoot.getRenderKitId 
();
-                       }
-
-                       uiViewRoot = (UIViewRoot) application.createComponent 
(UIViewRoot.COMPONENT_TYPE);
-                       //      as of JSF spec page 7-16:
-                       //      "It is the callers responsibility to ensure 
that setViewId() is called
-                       //      on the returned view, passing the same viewId 
value."
-                       //      so we do not set the viewId here
-
-                       //      ok, but the RI does so, so let's do it, too.
-                       uiViewRoot.setViewId (viewId);
-
-                       if (currentLocale != null) {
-                               //set old locale
-                               uiViewRoot.setLocale (currentLocale);
-                       }
-                       else {
-                               //calculate locale
-                               uiViewRoot.setLocale 
(applicationViewHandler.calculateLocale (facesContext));
-                       }
-
-                       if (currentRenderKitId != null) {
-                               //set old renderKit
-                               uiViewRoot.setRenderKitId (currentRenderKitId);
-                       }
-                       else {
-                               //calculate renderKit
-                               uiViewRoot.setRenderKitId 
(applicationViewHandler.calculateRenderKitId (facesContext));
-                       }
-
-                       AspNetFacesContext aspNetFacesContext = 
(AspNetFacesContext) facesContext;
-                       uiViewRoot.getChildren ().add (0, (UIComponent) 
(object) aspNetFacesContext.Handler);
+                       UIViewRoot uiViewRoot = _viewHandler.createView 
(facesContext, viewId);
+                       
+                       // create instance of Page by viewId
+                       StringBuilder sb = new StringBuilder ();
+                       sb.Append (facesContext.getExternalContext 
().getRequestContextPath ());
+                       int index = viewId.IndexOf ('?');
+                       if (index >= 0)
+                               sb.Append (viewId, 0, index);
+                       else
+                               sb.Append (viewId);
+                       UIComponent page = (UIComponent) 
PageParser.GetCompiledPageInstance (sb.ToString (), null, ((AspNetFacesContext) 
facesContext).Context);
+                       uiViewRoot.getChildren ().add (0, page);
+                       
                        return uiViewRoot;
                }
 
                public override String getResourceURL (FacesContext 
facesContext, String path) {
-                       if (path.Length > 0 && path [0] == '/') {
-                               return facesContext.getExternalContext 
().getRequestContextPath () + path;
-                       }
-                       else {
-                               return path;
-                       }
+                       return _viewHandler.getResourceURL (facesContext, path);
                }
 
                public override void renderView (FacesContext facesContext, 
UIViewRoot viewToRender) {
-                       if (viewToRender == null) {
+                       if (viewToRender == null)
                                throw new ArgumentNullException 
("viewToRender", "viewToRender must not be null");
-                       }
-
-                       AspNetFacesContext aspNetFacesContext = 
(AspNetFacesContext) facesContext;
-                       ((UIComponent) (object) 
aspNetFacesContext.Handler).encodeChildren (facesContext);
+                       ((UIComponent) viewToRender.getChildren ().get 
(0)).encodeChildren (facesContext);
                }
 
 
                public override UIViewRoot restoreView (FacesContext 
facesContext, String viewId) {
-                       Application application = facesContext.getApplication 
();
-                       ViewHandler applicationViewHandler = 
application.getViewHandler ();
-                       String renderKitId = 
applicationViewHandler.calculateRenderKitId (facesContext);
-                       UIViewRoot viewRoot = application.getStateManager 
().restoreView (facesContext,
-                                                                               
                                                                        viewId,
-                                                                               
                                                                        
renderKitId);
-                       return viewRoot;
+                       return _viewHandler.restoreView (facesContext, viewId);
                }
 
-               /**
-                * Writes a state marker that is replaced later by one or more 
hidden form
-                * inputs.
-                *
-                * @param facesContext
-                * @throws IOException
-                */
                public override void writeState (FacesContext facesContext) {
                        StateManager manager = facesContext.getApplication 
().getStateManager ();
                        StateManager.SerializedView serializedView = 
manager.saveSerializedView (facesContext);

Modified: 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletFacesPageHandlerFactory.cs
===================================================================
--- 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletFacesPageHandlerFactory.cs
 2007-12-02 16:19:14 UTC (rev 90524)
+++ 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletFacesPageHandlerFactory.cs
 2007-12-02 16:37:12 UTC (rev 90525)
@@ -40,10 +40,6 @@
                }
 
                public virtual IHttpHandler GetHandler (HttpContext context, 
string requestType, string url, string path) {
-                       IHttpHandler handler = 
PageParser.GetCompiledPageInstance (url, path, context);
-                       if (!(handler is Page))
-                               return handler;
-
                        HttpWorkerRequest wr = (HttpWorkerRequest) 
((IServiceProvider) context).GetService (typeof (HttpWorkerRequest));
                        HttpServletRequest request = (HttpServletRequest) 
((IServiceProvider) wr).GetService (typeof (HttpServletRequest));
                        HttpServletResponse response = (HttpServletResponse) 
((IServiceProvider) wr).GetService (typeof (HttpServletResponse));
@@ -54,7 +50,7 @@
                                                                                
                                   response,
                                                                                
                                   _lifecycle);
 
-                       return new ServletFacesPageHandler 
(AspNetFacesContext.WrapFacesContext (facesContext, context, (Page) handler), 
_lifecycle);
+                       return new ServletFacesPageHandler 
(AspNetFacesContext.WrapFacesContext (facesContext, context), _lifecycle);
                }
 
                public virtual void ReleaseHandler (IHttpHandler handler) {

Modified: 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletFacesStateManager.cs
===================================================================
--- 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletFacesStateManager.cs
       2007-12-02 16:19:14 UTC (rev 90524)
+++ 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletFacesStateManager.cs
       2007-12-02 16:37:12 UTC (rev 90525)
@@ -28,30 +28,6 @@
                        }
                }
 
-               protected override UIViewRoot restoreTreeStructure 
(FacesContext facesContext,
-                                                                               
                                                                         String 
viewId,
-                                                                               
                                                                         String 
renderKitId) {
-                       Console.WriteLine ("Entering restoreTreeStructure");
-
-                       UIViewRoot uiViewRoot;
-                       if (isSavingStateInClient (facesContext)) {
-                               RenderKit rk = RenderKitFactory.getRenderKit 
(facesContext, renderKitId);
-                               ResponseStateManager responseStateManager = 
rk.getResponseStateManager ();
-                               Object componentState = 
responseStateManager.getComponentStateToRestore (facesContext);
-                               if (componentState == null) {
-                                       Console.WriteLine ("Exiting 
restoreTreeStructure - No tree structure state found in client request");
-                                       return null;
-                               }
-                               uiViewRoot = facesContext.getApplication 
().getViewHandler ().createView (facesContext, viewId);
-                       }
-                       else {
-                               throw new NotImplementedException ();
-                       }
-
-                       Console.WriteLine ("Exiting restoreTreeStructure");
-                       return uiViewRoot;
-               }
-
                protected override void restoreComponentState (FacesContext 
facesContext,
                                                                                
                  javax.faces.component.UIViewRoot uiViewRoot,
                                                                                
                  String renderKitId) {
@@ -71,7 +47,7 @@
 
                        if (serializedComponentStates == null) {
                                Console.WriteLine ("No serialized component 
state found!");
-                               uiViewRoot.setViewId (null);
+                               facesContext.renderResponse ();
                                return;
                        }
 

Modified: 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletFacesViewHandler.cs
===================================================================
--- 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletFacesViewHandler.cs
        2007-12-02 16:19:14 UTC (rev 90524)
+++ 
branches/mainsoft/JSF/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletFacesViewHandler.cs
        2007-12-02 16:37:12 UTC (rev 90525)
@@ -13,15 +13,8 @@
 {
        public class ServletFacesViewHandler : BaseFacesViewHandler
        {
-               public override String getActionURL (FacesContext facesContext, 
String viewId) {
-
-                       String path = viewId;//                 getViewIdPath 
(facesContext, viewId);
-                       if (path.Length > 0 && path [0] == '/') {
-                               return facesContext.getExternalContext 
().getRequestContextPath () + path;
-                       }
-                       else {
-                               return path;
-                       }
+               public ServletFacesViewHandler (ViewHandler viewHandler)
+                       : base (viewHandler) {
                }
        }
 }

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

Reply via email to