You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by de...@apache.org on 2017/09/17 12:30:34 UTC
[myfaces-trinidad] 11/36: TRINIDAD-1699
This is an automated email from the ASF dual-hosted git repository.
deki pushed a commit to branch 1.2.12.2-branch
in repository https://gitbox.apache.org/repos/asf/myfaces-trinidad.git
commit 06ec7bf7b02a140eab0b79df45443aaf595bf8a9
Author: Andrew Robinson <ar...@apache.org>
AuthorDate: Wed Jan 27 23:00:36 2010 +0000
TRINIDAD-1699
Add isSecure method to ExternalContextUtils
---
.../trinidad/util/ExternalContextUtils.java | 124 ++++++++++++---------
1 file changed, 72 insertions(+), 52 deletions(-)
diff --git a/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java b/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java
index e2437e1..30e77fd 100644
--- a/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java
+++ b/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java
@@ -31,22 +31,23 @@ import javax.servlet.http.HttpServletRequest;
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 @@ public final class ExternalContextUtils
{
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 @@ public final class ExternalContextUtils
/**
* 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 @@ public final class ExternalContextUtils
{
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 @@ public final class ExternalContextUtils
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 @@ public final class ExternalContextUtils
/**
* 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 @@ public final class ExternalContextUtils
{
return (Boolean) _runMethod(ec.getRequest(), "isRequestedSessionIdValid");
}
-
+
/**
* Returns the contextPath of the ServletContext or <code>null</code> for portlets
*
@@ -230,14 +231,14 @@ public final class ExternalContextUtils
* @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 @@ public final class ExternalContextUtils
}
/**
- * 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 @@ public final class ExternalContextUtils
* @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 @@ public final class ExternalContextUtils
{
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 final class ExternalContextUtils
*/
public static InputStream getRequestInputStream(ExternalContext ec)
throws IOException
- {
+ {
RequestType type = getRequestType(ec);
if(type.isRequestFromClient())
{
@@ -364,20 +365,20 @@ public final class ExternalContextUtils
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 @@ public final class ExternalContextUtils
* 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 @@ public final class ExternalContextUtils
* 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 @@ public final class ExternalContextUtils
* 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 @@ public final class ExternalContextUtils
{
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 @@ public final class ExternalContextUtils
{
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 @@ public final class ExternalContextUtils
}
}
-
+
// prevent this from being instantiated
private ExternalContextUtils()
{}
@@ -517,7 +537,7 @@ public final class ExternalContextUtils
try
{
- resourceRequest = ClassLoaderUtils.loadClass("javax.portlet.ResourceRequest");
+ resourceRequest = ClassLoaderUtils.loadClass("javax.portlet.ResourceRequest");
}
catch (ClassNotFoundException e)
{
@@ -534,19 +554,19 @@ public final class ExternalContextUtils
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 @@ public final class ExternalContextUtils
{
portlet20Supported = true;
}
-
+
if(_LOG.isInfo())
{
String ver = (portlet20Supported)?"2.0":"1.0";
- _LOG.info("Portlet Environment Detected: " + ver);
+ _LOG.info("Portlet Environment Detected: " + ver);
}
}
}
--
To stop receiving notification emails like this one, please contact
"commits@myfaces.apache.org" <co...@myfaces.apache.org>.