myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1003670 - /myfaces/commons/trunk/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ExternalContextUtils.java
Date Fri, 01 Oct 2010 22:09:07 GMT
Author: lu4242
Date: Fri Oct  1 22:09:07 2010
New Revision: 1003670

URL: http://svn.apache.org/viewvc?rev=1003670&view=rev
Log:
add ExternalContextUtils getRequestType method to sync with tomahawk

Modified:
    myfaces/commons/trunk/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ExternalContextUtils.java

Modified: myfaces/commons/trunk/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ExternalContextUtils.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ExternalContextUtils.java?rev=1003670&r1=1003669&r2=1003670&view=diff
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ExternalContextUtils.java
(original)
+++ myfaces/commons/trunk/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ExternalContextUtils.java
Fri Oct  1 22:09:07 2010
@@ -147,16 +147,72 @@ public final class ExternalContextUtils
         return RequestType.SERVLET;
     }
 
-  private static final Log _LOG = LogFactory.getLog(TagUtils.class);
+    /**
+     * This method is used when a ExternalContext object is not available,
+     * like in TomahawkFacesContextFactory.
+     * 
+     * According to TOMAHAWK-1331, the object context could receive an
+     * instance of javax.portlet.PortletContext or javax.portlet.PortletConfig,
+     * so we check both cases.
+     * 
+     * @param context
+     * @param request
+     * @return
+     */
+    public static final RequestType getRequestType(Object context, Object request)
+    {
+        //Stuff is laid out strangely in this class in order to optimize
+        //performance.  We want to do as few instanceof's as possible so
+        //things are laid out according to the expected frequency of the
+        //various requests occurring.
+
+        if(_PORTLET_CONTEXT_CLASS != null)
+        {
+            if (_PORTLET_CONFIG_CLASS.isInstance(context) ||
+                _PORTLET_CONTEXT_CLASS.isInstance(context))
+            {
+                //We are inside of a portlet container
+                
+                if(_PORTLET_RENDER_REQUEST_CLASS.isInstance(request))
+                {
+                    return RequestType.RENDER;
+                }
+                
+                if(_PORTLET_RESOURCE_REQUEST_CLASS != null)
+                {
+                    if(_PORTLET_ACTION_REQUEST_CLASS.isInstance(request))
+                    {
+                        return RequestType.ACTION;
+                    }
+
+                    //We are in a JSR-286 container
+                    if(_PORTLET_RESOURCE_REQUEST_CLASS.isInstance(request))
+                    {
+                        return RequestType.RESOURCE;
+                    }
+                    
+                    return RequestType.EVENT;
+                }
+                
+                return RequestType.ACTION;
+            }
+        }
+        
+        return RequestType.SERVLET;
+    }
+
+    private static final Log _LOG = LogFactory.getLog(ExternalContextUtils.class);
 
     private static final Class<?>    _PORTLET_ACTION_REQUEST_CLASS;
     private static final Class<?> _PORTLET_RENDER_REQUEST_CLASS;
     private static final Class<?> _PORTLET_RESOURCE_REQUEST_CLASS; //Will be present
in JSR-286 containers only
     private static final Class<?>    _PORTLET_CONTEXT_CLASS;
+    private static final Class<?>    _PORTLET_CONFIG_CLASS;
     
     static
     {
         Class<?> context;
+        Class<?> config;
         Class<?> actionRequest;
         Class<?> renderRequest;
         Class<?> resourceRequest;
@@ -164,6 +220,7 @@ public final class ExternalContextUtils
         {
             ClassLoader loader = Thread.currentThread().getContextClassLoader();
             context = loader.loadClass("javax.portlet.PortletContext");
+            config = loader.loadClass("javax.portlet.PortletConfig");
             actionRequest = loader.loadClass("javax.portlet.ActionRequest");
             renderRequest = loader.loadClass("javax.portlet.RenderRequest");
             
@@ -179,12 +236,14 @@ public final class ExternalContextUtils
         catch (ClassNotFoundException e)
         {
             context = null;
+            config = null;
             actionRequest = null;
             renderRequest = null;
             resourceRequest = null;
         }
 
         _PORTLET_CONTEXT_CLASS = context;
+        _PORTLET_CONFIG_CLASS = config;
         _PORTLET_ACTION_REQUEST_CLASS = actionRequest;
         _PORTLET_RENDER_REQUEST_CLASS = renderRequest;
         _PORTLET_RESOURCE_REQUEST_CLASS = resourceRequest;



Mime
View raw message