myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject [myfaces] branch master updated: refactored
Date Fri, 04 Oct 2019 20:35:04 GMT
This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/master by this push:
     new 48e0a55  refactored
48e0a55 is described below

commit 48e0a551433158cb95ff3d2ca402b242400a8db6
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Fri Oct 4 22:34:56 2019 +0200

    refactored
---
 .../myfaces/application/NavigationHandlerImpl.java |   6 -
 .../apache/myfaces/application/ViewIdSupport.java  |   8 +-
 .../apache/myfaces/util/ExternalContextUtils.java  | 303 ++-------------------
 3 files changed, 27 insertions(+), 290 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
b/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
index 686c44a..088523c 100755
--- a/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
@@ -164,12 +164,6 @@ public class NavigationHandlerImpl extends ConfigurableNavigationHandler
             }
             if (navigationCase.isRedirect() || isViewActionProcessingBroadcastAndRequiresRedirect)
             { 
-                //&& (!PortletUtil.isPortletRequest(facesContext)))
-                // Spec section 7.4.2 says "redirects not possible" in this case for portlets
-                //But since the introduction of portlet bridge and the 
-                //removal of portlet code in myfaces core 2.0, this condition
-                //no longer applies
-
                 // Need to add the FlowHandler parameters here.
                 FlowHandler flowHandler = facesContext.getApplication().getFlowHandler();
                 List<Flow> activeFlows = FlowHandlerImpl.getActiveFlows(facesContext,
flowHandler);
diff --git a/impl/src/main/java/org/apache/myfaces/application/ViewIdSupport.java b/impl/src/main/java/org/apache/myfaces/application/ViewIdSupport.java
index 0581deb..934c68b 100644
--- a/impl/src/main/java/org/apache/myfaces/application/ViewIdSupport.java
+++ b/impl/src/main/java/org/apache/myfaces/application/ViewIdSupport.java
@@ -49,12 +49,6 @@ public class ViewIdSupport
 
     private static final String JAVAX_SERVLET_INCLUDE_PATH_INFO = "javax.servlet.include.path_info";
     
-    /**
-     * Constant defined on javax.portlet.faces.Bridge class that helps to 
-     * define if the current request is a portlet request or not.
-     */
-    private static final String PORTLET_LIFECYCLE_PHASE = "javax.portlet.faces.phase";  
 
-    
     private static final Logger log = Logger.getLogger(ViewIdSupport.class.getName());
     
     private static final String VIEW_HANDLER_SUPPORT_SB = "oam.viewhandler.SUPPORT_SB";
@@ -558,7 +552,7 @@ public class ViewIdSupport
         boolean traceEnabled = log.isLoggable(Level.FINEST);
         
         String viewId = null;
-        if (requestMap.containsKey(PORTLET_LIFECYCLE_PHASE))
+        if (ExternalContextUtils.isPortlet(externalContext))
         {
             viewId = (String) externalContext.getRequestPathInfo();
         }
diff --git a/impl/src/main/java/org/apache/myfaces/util/ExternalContextUtils.java b/impl/src/main/java/org/apache/myfaces/util/ExternalContextUtils.java
index 47486eb..65a41d0 100644
--- a/impl/src/main/java/org/apache/myfaces/util/ExternalContextUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/util/ExternalContextUtils.java
@@ -18,9 +18,9 @@
  */
 package org.apache.myfaces.util;
 
+import java.util.Map;
 import org.apache.myfaces.util.lang.ClassUtils;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+
 
 import javax.faces.context.ExternalContext;
 import javax.servlet.ServletResponseWrapper;
@@ -37,72 +37,35 @@ import javax.servlet.http.HttpServletResponse;
  */
 public final class ExternalContextUtils
 {
+    private static final Class<?> PORTLET_CONTEXT_CLASS =
+            ClassUtils.simpleClassForName("javax.portlet.PortletContext", false);
+
+    /**
+     * Constant defined on javax.portlet.faces.Bridge class that helps to 
+     * define if the current request is a portlet request or not.
+     */
+    private static final String PORTLET_LIFECYCLE_PHASE = "javax.portlet.faces.phase";  
 
     
     /**
-     * Returns the requestType of this ExternalContext.
+     * This is a convenience function designed to perform a quick check of the current {@link
ExternalContext}.
      * 
-     * @param externalContext the current external context
-     * @return the appropriate RequestType for this external context
-     * @see RequestType
+     * @param ec the current external context
+     * @return <code>true</code> if the current {@link ExternalContext} is a
Porlet.
      */
-    public static final RequestType getRequestType(ExternalContext externalContext)
+    public static boolean isPortlet(ExternalContext ec)
     {
-        //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_10_SUPPORTED || _PORTLET_20_SUPPORTED)
+        Map<String, Object> requestMap = ec.getRequestMap();
+        if (requestMap.containsKey(PORTLET_LIFECYCLE_PHASE))
         {
-            if (_PORTLET_CONTEXT_CLASS.isInstance(externalContext.getContext()))
-            {
-                //We are inside of a portlet container
-                Object request = externalContext.getRequest();
-                
-                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 true;
         }
         
-        return RequestType.SERVLET;
-    }
+        if (PORTLET_CONTEXT_CLASS != null)
+        {
+            return PORTLET_CONTEXT_CLASS.isInstance(ec.getContext());
+        }
 
-    /**
-     * Returns the value of {@link RequestType#isPortlet()} for the current
-     * RequestType. This is a convenience function designed to perform a quick
-     * check of the current request. If more capabilities need to be tested for
-     * the given request, then it is more efficient to pull this information from
-     * the RequestType itself.
-     * 
-     * @param ec the current external context
-     * @return a boolean value of <code>true</code> if the current RequestType
-     *         is a portlet request.
-     * 
-     * @see RequestType#isPortlet()
-     * @see #getRequestType(ExternalContext)
-     */
-    public static boolean isPortlet(ExternalContext ec)
-    {
-        return getRequestType(ec).isPortlet();
+        return false;
     }
 
     /**
@@ -116,7 +79,6 @@ public final class ExternalContextUtils
      * @param ec the current external context
      * @return a boolean value of <code>true</code> if the current request is
an
      *         HttpServletRequest
-     * @since 1.1
      */
     public static boolean isHttpServletRequest(ExternalContext ec)
     {
@@ -142,113 +104,7 @@ public final class ExternalContextUtils
 
         return null;
     }
-
-    // prevent this from being instantiated
-    private ExternalContextUtils()
-    {
-    }
-
-    private static final Logger _LOG = Logger
-            .getLogger(ExternalContextUtils.class.getName());
-
-    // =-= Scott O'Bryan =-=
-    // Performance enhancement. These will be needed anyway, let's not get them every time.
-    private static final Class<?> _PORTLET_ACTION_REQUEST_CLASS;
-    private static final Class<?> _PORTLET_RENDER_REQUEST_CLASS;
-    private static final Class<?> _PORTLET_RESOURCE_REQUEST_CLASS;
-    private static final Class<?> _PORTLET_CONTEXT_CLASS;
-    private static final boolean _PORTLET_10_SUPPORTED;
-    private static final boolean _PORTLET_20_SUPPORTED;
-    private static final Class<?> _PORTLET_CONFIG_CLASS;
-
-    static
-    {
-        Class<?> context;
-        Class<?> config;
-        Class<?> actionRequest;
-        Class<?> renderRequest;
-        Class<?> resourceRequest;
-        boolean portlet20Supported = false;
-        boolean portlet10Supported = false;
-
-        try
-        {
-            context = ClassUtils.forName("javax.portlet.PortletContext");
-            config = ClassUtils.forName("javax.portlet.PortletConfig");
-            actionRequest = ClassUtils.forName("javax.portlet.ActionRequest");
-            renderRequest = ClassUtils.forName("javax.portlet.RenderRequest");
-
-            try
-            {
-                resourceRequest = ClassUtils.forName("javax.portlet.ResourceRequest");
-            }
-            catch (ClassNotFoundException e)
-            {
-                _LOG.fine("Portlet 2.0 API is not available on classpath.  Portlet 2.0 functionality
is disabled");
-                resourceRequest = null;
-            }
-        }
-        catch (final ClassNotFoundException e)
-        {
-            _LOG.fine("Portlet API is not available on the classpath.  Portlet configurations
are disabled.");
-            context = null;
-            config = null;
-            actionRequest = null;
-            renderRequest = null;
-            resourceRequest = null;
-        }
-
-        //Find bridge to tell if portal is supported
-        if (context != null)
-        {
-            // Portlet 1.0 API found. In this case we have to consider that exists alternate
-            // bridge implementations like in WebSphere and others.
-            portlet10Supported = true;
-
-            try
-            {
-                Class<?> bridge = ClassUtils.forName("javax.portlet.faces.Bridge");
-
-                if (bridge != null)
-                {
-                    //Standard bridge defines a spec name which can be used to 
-                    //determine Portlet 2.0 Support.
-                    String specName = bridge.getPackage()
-                            .getSpecificationTitle();
-                    _LOG.fine("Found Bridge: " + specName);
-                    if (specName != null && specName.startsWith("Portlet 2"))
-                    {
-                        portlet20Supported = true;
-                    }
-
-                    if (_LOG.isLoggable(Level.INFO))
-                    {
-                        String ver = (portlet20Supported) ? "2.0" : "1.0";
-                        _LOG.info("Portlet Environment Detected: " + ver);
-                    }
-                }
-            }
-            catch (ClassNotFoundException e)
-            {
-                _LOG.fine("Portlet API is present but Standard Apache Portlet Bridge is not.
"
-                        + " This could happen if you are using an alternate Portlet Bridge
solution.");
-
-                if (resourceRequest != null)
-                {
-                    portlet20Supported = true;
-                }
-            }
-        }
-
-        _PORTLET_CONTEXT_CLASS = context;
-        _PORTLET_CONFIG_CLASS = config;
-        _PORTLET_ACTION_REQUEST_CLASS = actionRequest;
-        _PORTLET_RENDER_REQUEST_CLASS = renderRequest;
-        _PORTLET_RESOURCE_REQUEST_CLASS = resourceRequest;
-        _PORTLET_10_SUPPORTED = portlet10Supported;
-        _PORTLET_20_SUPPORTED = portlet20Supported;
-    }
-
+    
     /**
      * Trys to obtain a HttpServletResponse from the Response.
      * Note that this method also trys to unwrap any ServletResponseWrapper
@@ -276,116 +132,9 @@ public final class ExternalContextUtils
         }
         return null; // not found
     }
-    
-    
-    
-    
-    /**
-     * Represents the type of request currently in the ExternalContext.
-     * All servlet requests will be of the SERVLET requestType whereas
-     * all of the other RequestTypes will be portlet type requests.  There
-     * are a number of convenience methods on the RequestType enumeration
-     * which can be used to determine the capabilities of the current request.
-     * 
-     * @version $Revision$ $Date$
-     */
-    public enum RequestType
-    {
-        /**
-         * The type for all servlet requests.  SERVLET request types are
-         * both client requests and response writable.
-         */
-        SERVLET(true, true, false),
-
-        /**
-         * The type for a portlet RenderRequest.  RENDER request types are
-         * for portlets and are response writable but are NOT client
-         * requests.
-         */
-        RENDER(false, true, true),
-
-        /**
-         * The type for a portlet ActionRequest.  ACTION request types are
-         * for portlets and are client requests but are NOT response 
-         * writable.
-         */
-        ACTION(true, false, true),
-
-        /**
-         * The type for a portlet ResourceRequest.  RESOURCE request types
-         * are for portlets and are both client requests and response 
-         * writable.  RESOURCE request types will only be returned in a
-         * Portlet 2.0 portlet container.
-         */
-        RESOURCE(true, true, true),
-
-        /**
-         * The type for a portlet EventRequest.  EVENT request types
-         * are for portlets and are neither client requests nor response 
-         * writable.  EVENT request types will only be returned in a
-         * Portlet 2.0 portlet container.
-         */        
-        EVENT(false, false, true);
-
-        private boolean _client;
-        private boolean _writable;
-        private boolean _portlet;
-
-        RequestType(boolean client, boolean writable, boolean portlet)
-        {
-            _client = client;
-            _writable  = writable;
-            _portlet    = portlet;
-        }
-
-        /**
-         * Returns <code>true</code> if this request was a direct
-         * result of a call from the client.  This implies that
-         * the current application is the "owner" of the current
-         * request and that it has access to the inputStream, can
-         * get and set character encodings, etc.  Currently all
-         * SERVLET, ACTION, and RESOURCE RequestTypes are client
-         * requests.
-         * 
-         * @return <code>true</code> if the current request is a
-         *         client data type request and <code>false</code>
-         *         if it is not.
-         */
-        public boolean isRequestFromClient()
-        {
-            return _client;
-        }
-
-        /**
-         * Returns <code>true</code> if the response for this
-         * RequestType is intended to produce output to the client.
-         * Currently the SERVLET, RENDER, and RESOURCE request are
-         * response writable.
-         *  
-         * @return <code>true</code> if the current request is 
-         *         intended to produce output and <code>false</code>
-         *         if it is not.
-         */
-        public boolean isResponseWritable()
-        {
-            return _writable;
-        }
 
-        /**
-         * Returns <code>true</code> if the response for this
-         * RequestType originated from a JSR-168 or JSR-286 
-         * portlet container.  Currently RENDER, ACTION,
-         * RESOURCE, and EVENT RequestTypes are all portlet
-         * requests.
-         * 
-         * @return <code>true</code> if the current request
-         *         originated inside of a JSR-168 or JSR-286
-         *         Portlet Container or <code>false</code> if
-         *         it did not.
-         */
-        public boolean isPortlet()
-        {
-            return _portlet;
-        }
+    // prevent this from being instantiated
+    private ExternalContextUtils()
+    {
     }
 }


Mime
View raw message