You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ar...@apache.org on 2010/01/28 00:00:36 UTC

svn commit: r903898 - in /myfaces/trinidad/branches/1.2.12.2-branch: ./ trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component/ trinidad-sandbox/sa...

Author: arobinson74
Date: Wed Jan 27 23:00:36 2010
New Revision: 903898

URL: http://svn.apache.org/viewvc?rev=903898&view=rev
Log:
TRINIDAD-1699

Add isSecure method to ExternalContextUtils

Modified:
    myfaces/trinidad/branches/1.2.12.2-branch/   (props changed)
    myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java
    myfaces/trinidad/branches/1.2.12.2-branch/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component/   (props changed)
    myfaces/trinidad/branches/1.2.12.2-branch/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event/   (props changed)

Propchange: myfaces/trinidad/branches/1.2.12.2-branch/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 27 23:00:36 2010
@@ -3,4 +3,4 @@
 /myfaces/trinidad/branches/1.2.9.1-branch:697924,699406,699496
 /myfaces/trinidad/branches/TRINIDAD-1402:745675
 /myfaces/trinidad/branches/jwaldman_StyleMap:754977-770778
-/myfaces/trinidad/trunk:819601,819622,834147,886881,893043
+/myfaces/trinidad/trunk:819601,819622,834147,886881,893043,903338

Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java?rev=903898&r1=903897&r2=903898&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java Wed Jan 27 23:00:36 2010
@@ -31,22 +31,23 @@
 
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 
+
 /**
- * This provides some functionality for determining some things about the 
+ * This provides some functionality for determining some things about the
  * native request object that is not provided by the base utils.
  *
  * @version 2.0
  */
 public final class ExternalContextUtils
 {
-  
+
   /**
    * Returns <code>true</code> if a particular class relating to the supplied
-   * request type is available on the current classpath or <code>false</code> 
+   * request type is available on the current classpath or <code>false</code>
    * if it is not.  This class assumes that all containers have a servlet type
-   * request available, but the portlet request types are all dependant on the 
+   * request available, but the portlet request types are all dependant on the
    * portlet container being used.
-   * 
+   *
    * @param type the RequestType to test
    * @return a boolean value of <code>true</code> if the container contains the
    *         request type in the classpath
@@ -58,15 +59,15 @@
     {
       case SERVLET:
         return true;
-        
+
       case ACTION:
       case RENDER:
         return _PORTLET_CONTEXT_CLASS != null;
-      
+
       case RESOURCE:
       case EVENT:
         return _PORTLET_RENDER_REQUEST_CLASS != null;
-        
+
       default:
         return false;
     }
@@ -75,13 +76,13 @@
   /**
    * Returns <code>true</code> if a particular request type is supported by the
    * container.  For a request type to be supported, the required objects must
-   * be on the classpath AND and, in the case of Portlet RequestTypes, an 
+   * be on the classpath AND and, in the case of Portlet RequestTypes, an
    * appropriate bridge must be avaialble which supports those objects.  This
-   * means that if the supplied RequestType is RESOURCE, the 
+   * means that if the supplied RequestType is RESOURCE, the
    * javax.portlet.ResourceRequest object must be available on the classpath AND
    * a bridge which supports the Portlet 2.0 specification would also need to be
    * available.
-   * 
+   *
    * @param type the RequestType to test
    * @return a boolean value of <code>true</code> if the container supports the
    *         current request type
@@ -93,23 +94,23 @@
     {
       case SERVLET:
         return true;
-        
+
       case ACTION:
       case RENDER:
         return _PORTLET_10_SUPPORTED;
-      
+
       case RESOURCE:
       case EVENT:
         return _PORTLET_20_SUPPORTED;
-        
+
       default:
         return false;
     }
   }
-  
+
   /**
    * Returns the requestType of this ExternalContext.
-   * 
+   *
    * @param ec the current external context
    * @return the appropriate RequestType for this external context
    * @see RequestType
@@ -155,12 +156,12 @@
 
     return RequestType.SERVLET;
   }
-  
+
   /**
    * Returns the current active session id or <code>null</code> if there is
    * none.  If a session is not already created, this method will create one
    * for you.
-   * 
+   *
    * @param ec the current external context
    * @return a string containing the requestedSessionId
    */
@@ -172,14 +173,14 @@
   /**
    * Returns the current active session id or <code>null</code> if there is
    * none.
-   * 
+   *
    * @param ec the current external context
    * @param create create a new session if one is not created
    * @return a string containing the requestedSessionId
    */
   public static String getSessionId(ExternalContext ec, boolean create)
   {
-    Object session = ec.getSession(create);   
+    Object session = ec.getSession(create);
     return (null!=session)?(String)_runMethod(session, "getId"):null;
   }
 
@@ -205,7 +206,7 @@
   {
     return (Boolean) _runMethod(ec.getRequest(), "isRequestedSessionIdValid");
   }
-  
+
   /**
    * Returns the contextPath of the ServletContext or <code>null</code> for portlets
    *
@@ -230,14 +231,14 @@
    * @param ec the current external context
    * @return a String containing the request context path
    * @see ExternalContext#getRequestContextPath()
-   * 
+   *
    * @deprecated use ExternalContext.getRequestContextPath() as of JSF 1.2.  This method
    *             does not appropriately handle portlet environments, but the functionality
    *             is maintained to prevent needing to change the contract.
    */
   @Deprecated
   public static String getRequestContextPath(ExternalContext ec)
-  { 
+  {
     if(!isPortlet(ec))
     {
       return ec.getRequestContextPath();
@@ -249,14 +250,14 @@
   }
 
   /**
-   * Returns the requestURI of the HttpServletRequest or <code>null</code> for 
+   * Returns the requestURI of the HttpServletRequest or <code>null</code> for
    * portlet requests
    *
    * @param ec the current external context
    * @return A string containing the current request uri
    */
   public static String getRequestURI(ExternalContext ec)
-  { 
+  {
     if (!isPortlet(ec))
     {
       return ((HttpServletRequest) ec.getRequest()).getRequestURI();
@@ -273,7 +274,7 @@
    * @param ec the current external context
    * @return a string containing the request's character encoding
    * @see ExternalContext#getRequestCharacterEncoding()
-   * 
+   *
    * @deprecated replaced by an API in JSF.  Use ExternalContext.getRequestCharacterEncoding()
    */
   @Deprecated
@@ -281,11 +282,11 @@
   {
     return ec.getRequestCharacterEncoding();
   }
-  
+
   /**
    * Returns the name of the underlying context or <code>null</code> if something
    * went wrong in trying to retrieve the context.
-   * 
+   *
    * @param ec the current external context
    * @return a String containing the context name
    */
@@ -350,7 +351,7 @@
    */
   public static InputStream getRequestInputStream(ExternalContext ec)
       throws IOException
-  { 
+  {
     RequestType type = getRequestType(ec);
     if(type.isRequestFromClient())
     {
@@ -364,20 +365,20 @@
         return ((ServletRequest) ec.getRequest()).getInputStream();
       }
     }
-    
+
     return null;
   }
 
   /**
-   * Returns <code>true</code> if this externalContext represents an "action". 
-   * An action request is any ServletRequest or a portlet ActionRequest or 
+   * Returns <code>true</code> if this externalContext represents an "action".
+   * An action request is any ServletRequest or a portlet ActionRequest or
    * ResourceRequest.
    *
    * @param ec the current external context
    * @return a boolean of <code>true</code> if this request is an action-type
    *         request.
    * @see #isRequestFromClient(ExternalContext)
-   *         
+   *
    * @deprecated replaced with {@link #isRequestFromClient(ExternalContext)}
    */
   @Deprecated
@@ -392,11 +393,11 @@
    * 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)
    */
@@ -411,11 +412,11 @@
    * 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 "render" type response.
-   * 
+   *
    * @see RequestType#isResponseWritable()
    * @see #getRequestType(ExternalContext)
    * @since 2.0
@@ -431,11 +432,11 @@
    * 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
    *         represents a request from the client.
-   * 
+   *
    * @see RequestType#isResponseWritable()
    * @see #getRequestType(ExternalContext)
    * @since 2.0
@@ -444,15 +445,15 @@
   {
     return getRequestType(ec).isRequestFromClient();
   }
-  
+
   /**
    * Returns wherther of not this external context represents a true HttpServletRequest or
-   * not.  Some portal containers implement the PortletRequest/Response objects as 
+   * not.  Some portal containers implement the PortletRequest/Response objects as
    * HttpServletRequestWrappers, and those objects should not be treated as an
    * HttpServlerRequest.  As such, this method first tests to see if the request is
    * a portlet request and, if not, then tests to see if the request is an instanceof
    * HttpServletRequest.
-   * 
+   *
    * @param ec the current external context
    * @return a boolean value of <code>true</code> if the current request is an
    *         HttpServletRequest
@@ -462,10 +463,29 @@
   {
     return (!isPortlet(ec) && (ec.getRequest() instanceof HttpServletRequest));
   }
-  
+
+  /**
+   * Provides access to {@link ServletRequest#isSecure()} or {@link javax.portlet.PortletRequest#isSecure()}
+   * @param ec
+   * @return
+   */
+  public static boolean isSecure(
+    ExternalContext ec)
+  {
+    Object req = ec.getRequest();
+    if (isPortlet(ec))
+    {
+      return (Boolean)_runMethod(req, "isSecure");
+    }
+    else
+    {
+      return ((ServletRequest)req).isSecure();
+    }
+  }
+
   /**
    * Runs a method on an object and returns the result
-   * 
+   *
    * @param obj the object to run the method on
    * @param methodName the name of the method
    * @return the results of the method run
@@ -483,7 +503,7 @@
     }
 
   }
-  
+
   // prevent this from being instantiated
   private ExternalContextUtils()
   {}
@@ -517,7 +537,7 @@
 
       try
       {
-        resourceRequest = ClassLoaderUtils.loadClass("javax.portlet.ResourceRequest"); 
+        resourceRequest = ClassLoaderUtils.loadClass("javax.portlet.ResourceRequest");
       }
       catch (ClassNotFoundException e)
       {
@@ -534,19 +554,19 @@
       renderRequest = null;
       resourceRequest = null;
     }
-    
+
     //Find bridge to tell if portal is supported
-    if(context != null) 
+    if(context != null)
     {
       try
       {
         Class<?> bridge = ClassLoaderUtils.loadClass("javax.portlet.faces.Bridge");
-        
+
         if(bridge != null)
         {
           portlet10Supported = true;
 
-          //Standard bridge defines a spec name which can be used to 
+          //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);
@@ -554,11 +574,11 @@
           {
             portlet20Supported = true;
           }
-          
+
           if(_LOG.isInfo())
           {
             String ver = (portlet20Supported)?"2.0":"1.0";
-            _LOG.info("Portlet Environment Detected: " + ver);            
+            _LOG.info("Portlet Environment Detected: " + ver);
           }
         }
       }

Propchange: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 27 23:00:36 2010
@@ -2,4 +2,4 @@
 /myfaces/trinidad/branches/1.2.11.4-branch/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component:794062,794792,798299
 /myfaces/trinidad/branches/1.2.9.1-branch/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component:699406,699496
 /myfaces/trinidad/branches/TRINIDAD-1402/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component:745675
-/myfaces/trinidad/trunk/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component:819601,819622,834147,886881,893043
+/myfaces/trinidad/trunk/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component:819601,819622,834147,886881,893043,903338

Propchange: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 27 23:00:36 2010
@@ -2,4 +2,4 @@
 /myfaces/trinidad/branches/1.2.11.4-branch/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event:794062,794792,798299
 /myfaces/trinidad/branches/1.2.9.1-branch/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event:699406,699496
 /myfaces/trinidad/branches/TRINIDAD-1402/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event:745675
-/myfaces/trinidad/trunk/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event:819601,819622,834147,886881,893043
+/myfaces/trinidad/trunk/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event:819601,819622,834147,886881,893043,903338