You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by an...@apache.org on 2011/09/28 17:42:22 UTC
svn commit: r1176924 - in /myfaces/trinidad/branches/trinidad-1.2.x:
trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/
trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/
trinidad-impl/src/main/java/org/apache/myf...
Author: andys
Date: Wed Sep 28 15:42:22 2011
New Revision: 1176924
URL: http://svn.apache.org/viewvc?rev=1176924&view=rev
Log:
TRINIDAD-2130 Skinning: support separate style sheets for secure + non-secure pages
We now generate separate style sheets for secure (https) and non-secure
(http) requests.
Note that to assist with this, we have added one new method to the (internal)
StyleContext interface:
/**
* @return true if the current request is secure (an https request), false otherwise
*/
public boolean isRequestSecure();
We have also added the following (public) utility method to ExternalContextUtils:
/**
* Returns the scheme of the current request, or "unknown" if
* the request scheme cannot be determined.
*
* @param ec the current external context
* @return A string containing the current request scheme, or "unknown".
*/
public static String getRequestScheme(ExternalContext ec)
Original patch implemented by Max Starets.
Reviewed/tweaked by me.
Reviewed by Jeanne Waldman.
Modified:
myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java
myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java?rev=1176924&r1=1176923&r2=1176924&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java Wed Sep 28 15:42:22 2011
@@ -317,6 +317,49 @@ public final class ExternalContextUtils
}
/**
+ * Returns the scheme of the current request, or "unknown" if
+ * the request scheme cannot be determined.
+ *
+ * @param ec the current external context
+ * @return A string containing the current request scheme, or "unknown".
+ */
+ public static String getRequestScheme(ExternalContext ec)
+ {
+ if (isPortlet(ec))
+ {
+ return _getPortletRequestScheme(ec);
+ }
+
+ return _getServletRequestScheme(ec);
+ }
+
+ private static String _getPortletRequestScheme(ExternalContext ec)
+ {
+ try
+ {
+ return (String) _runMethod(ec.getContext(), "getScheme");
+ }
+ catch (Exception e)
+ {
+ _LOG.severe(e);
+ }
+
+ return _SCHEME_UNKNOWN;
+ }
+
+ private static String _getServletRequestScheme(ExternalContext ec)
+ {
+ Object request = ec.getRequest();
+
+ if (request instanceof ServletRequest)
+ {
+ return ((ServletRequest)request).getScheme();
+ }
+
+ return _SCHEME_UNKNOWN;
+ }
+
+ /**
* Returns the character encoding or <code>null</code> if there isn't any
*
* @param ec the current external context
@@ -586,6 +629,10 @@ public final class ExternalContextUtils
private static final TrinidadLogger _LOG = TrinidadLogger
.createTrinidadLogger(ExternalContextUtils.class);
+ // getRequestScheme() return value in the event that we cannot
+ // determine the request scheme.
+ private static final String _SCHEME_UNKNOWN = "unknown";
+
// =-= 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;
Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java?rev=1176924&r1=1176923&r2=1176924&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java Wed Sep 28 15:42:22 2011
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.apache.myfaces.trinidad.context.AccessibilityProfile;
@@ -33,6 +34,7 @@ import org.apache.myfaces.trinidad.loggi
import org.apache.myfaces.trinidad.skin.Icon;
import org.apache.myfaces.trinidad.skin.Skin;
import org.apache.myfaces.trinidad.style.Styles;
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.HtmlRenderer;
import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.StyleSheetRenderer;
@@ -175,6 +177,24 @@ class StyleContextImpl implements StyleC
{
return CoreRenderKit.OUTPUT_MODE_PORTLET.equals(_arc.getOutputMode());
}
+
+ @Override
+ public boolean isRequestSecure()
+ {
+ if (_isRequestSecure == null)
+ {
+ String scheme = _getRequestScheme();
+ _isRequestSecure = "https".equals(scheme);
+ }
+ return _isRequestSecure;
+ }
+
+ static private String _getRequestScheme()
+ {
+ FacesContext context = FacesContext.getCurrentInstance();
+ ExternalContext external = context.getExternalContext();
+ return ExternalContextUtils.getRequestScheme(external);
+ }
/**
*
@@ -286,6 +306,8 @@ class StyleContextImpl implements StyleC
private StyleProvider _styleProvider;
private Styles _styles;
private Boolean _isDisableStyleCompression;
+ private Boolean _isRequestSecure;
+
static private final String _SKIN_ID_PARAM =
"org.apache.myfaces.trinidad.skin.id";
Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java?rev=1176924&r1=1176923&r2=1176924&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java Wed Sep 28 15:42:22 2011
@@ -54,4 +54,9 @@ public interface StyleContext
public boolean isPortletMode();
public boolean isDisableStyleCompression();
public boolean isDirty();
+
+ /**
+ * @return true if the current request is secure (an https request), false otherwise
+ */
+ public boolean isRequestSecure();
}
Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java?rev=1176924&r1=1176923&r2=1176924&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java Wed Sep 28 15:42:22 2011
@@ -268,6 +268,12 @@ public class FileSystemStyleCache implem
buffer.append(_PORTLET);
}
+
+ if (context.isRequestSecure())
+ {
+ buffer.append(_NAME_SEPARATOR);
+ buffer.append(_SECURE);
+ }
buffer.append(_CSS_EXTENSION);
@@ -1084,7 +1090,8 @@ public class FileSystemStyleCache implem
agent.getAgentOS(),
!context.isDisableStyleCompression(),
accProfile,
- context.isPortletMode());
+ context.isPortletMode(),
+ context.isRequestSecure());
}
@Override
@@ -1097,7 +1104,8 @@ public class FileSystemStyleCache implem
(_browser.ordinal() << 2) ^
(_platform << 8) ^
(_short ? 1 : 0) ^
- (_portlet ? 1:0);
+ ((_portlet ? 1:0) << 1) ^
+ ((_secureRequest ? 1: 0) << 3);
if (_locale != null) _hashCode ^= _locale.hashCode();
if (_accProfile != null) _hashCode ^= _accProfile.hashCode();
@@ -1124,7 +1132,8 @@ public class FileSystemStyleCache implem
(_portlet == key._portlet) &&
(_direction == key._direction) &&
(_browser == key._browser) &&
- (_platform == key._platform))
+ (_platform == key._platform) &&
+ (_secureRequest == key._secureRequest))
{
// now check the optional objects
if ((_version == null) || _version.equals(key._version))
@@ -1144,7 +1153,8 @@ public class FileSystemStyleCache implem
int platform,
boolean useShort,
AccessibilityProfile accessibilityProfile,
- boolean portlet
+ boolean portlet,
+ boolean secure
)
{
// Make sure direction is non-null
@@ -1162,6 +1172,7 @@ public class FileSystemStyleCache implem
_short = useShort;
_accProfile = accessibilityProfile;
_portlet = portlet;
+ _secureRequest = secure;
}
//is immutable, we should cache this, will make things faster in the long run
@@ -1176,6 +1187,7 @@ public class FileSystemStyleCache implem
private boolean _short; // Do we use short style classes?
private AccessibilityProfile _accProfile;
private boolean _portlet; //kind of a hack but tells whether this was created in portal mode
+ private boolean _secureRequest;
}
/**
@@ -1214,6 +1226,7 @@ public class FileSystemStyleCache implem
System.arraycopy(styleSheets, 0, _styleSheets, 0, styleSheets.length);
_short = true;
_portlet = context.isPortletMode();
+ _secureRequest = context.isRequestSecure();
}
@Override
@@ -1228,6 +1241,7 @@ public class FileSystemStyleCache implem
if ((_short != key._short) ||
(_portlet != key._portlet) ||
+ (_secureRequest != key._secureRequest) ||
(_styleSheets.length != key._styleSheets.length))
return false;
@@ -1254,7 +1268,8 @@ public class FileSystemStyleCache implem
{
_hashCode = Arrays.hashCode(_styleSheets) ^
(_short ? 1 : 0) ^
- (_portlet ? 1 : 0);
+ (_portlet ? 1 : 0) ^
+ ((_secureRequest ? 1: 0) << 3);
_noHash = false;
}
@@ -1268,6 +1283,7 @@ public class FileSystemStyleCache implem
private StyleSheetNode[] _styleSheets;
private boolean _portlet;
private boolean _short; // Do we use short style classes?
+ private boolean _secureRequest;
}
@@ -1585,6 +1601,7 @@ public class FileSystemStyleCache implem
private static final char _NAME_SEPARATOR = '-';
private static final String _COMPRESSED = "cmp";
private static final String _PORTLET = "prtl";
+ private static final String _SECURE = "s";
/** Extension for CSS files */
private static final String _CSS_EXTENSION = ".css";