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/22 21:37:23 UTC
svn commit: r1174340 - in /myfaces/trinidad/trunk/trinidad-impl/src:
main/java/org/apache/myfaces/trinidadinternal/renderkit/core/
main/java/org/apache/myfaces/trinidadinternal/style/
main/java/org/apache/myfaces/trinidadinternal/style/cache/ test/java...
Author: andys
Date: Thu Sep 22 19:37:22 2011
New Revision: 1174340
URL: http://svn.apache.org/viewvc?rev=1174340&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();
Original patch implemented by Max Starets.
Reviewed/tweaked by me.
Reviewed by Jeanne Waldman.
Modified:
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MFacesContext.java
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java?rev=1174340&r1=1174339&r2=1174340&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java Thu Sep 22 19:37:22 2011
@@ -198,6 +198,17 @@ class StyleContextImpl implements StyleC
{
return CoreRenderKit.OUTPUT_MODE_PORTLET.equals(_arc.getOutputMode());
}
+
+ @Override
+ public boolean isRequestSecure()
+ {
+ if (_isRequestSecure == null)
+ {
+ String scheme = FacesContext.getCurrentInstance().getExternalContext().getRequestScheme();
+ _isRequestSecure = "https".equals(scheme);
+ }
+ return _isRequestSecure;
+ }
/**
*
@@ -333,6 +344,7 @@ class StyleContextImpl implements StyleC
private StyleProvider _styleProvider;
private Styles _styles;
private Boolean _isDisableStyleCompression;
+ private Boolean _isRequestSecure;
static private final String _SKIN_DIRTY_PARAM =
"org.apache.myfaces.trinidad.skin.dirty";
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java?rev=1174340&r1=1174339&r2=1174340&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java Thu Sep 22 19:37: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/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java?rev=1174340&r1=1174339&r2=1174340&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java Thu Sep 22 19:37:22 2011
@@ -274,6 +274,12 @@ public class FileSystemStyleCache implem
buffer.append(_PORTLET);
}
+
+ if (context.isRequestSecure())
+ {
+ buffer.append(_NAME_SEPARATOR);
+ buffer.append(_SECURE);
+ }
buffer.append(_CSS_EXTENSION);
@@ -1194,7 +1200,8 @@ public class FileSystemStyleCache implem
agent.getAgentOS(),
!context.isDisableStyleCompression(),
accProfile,
- context.isPortletMode());
+ context.isPortletMode(),
+ context.isRequestSecure());
}
@Override
@@ -1207,7 +1214,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();
@@ -1234,7 +1242,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))
@@ -1254,7 +1263,8 @@ public class FileSystemStyleCache implem
int platform,
boolean useShort,
AccessibilityProfile accessibilityProfile,
- boolean portlet
+ boolean portlet,
+ boolean secure
)
{
// Make sure direction is non-null
@@ -1272,6 +1282,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
@@ -1286,6 +1297,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;
}
/**
@@ -1327,6 +1339,7 @@ public class FileSystemStyleCache implem
System.arraycopy(styleSheets, 0, _styleSheets, 0, styleSheets.length);
_short = true;
_portlet = context.isPortletMode();
+ _secureRequest = context.isRequestSecure();
}
@Override
@@ -1341,6 +1354,7 @@ public class FileSystemStyleCache implem
if ((_short != key._short) ||
(_portlet != key._portlet) ||
+ (_secureRequest != key._secureRequest) ||
(_styleSheets.length != key._styleSheets.length))
return false;
@@ -1367,7 +1381,8 @@ public class FileSystemStyleCache implem
{
_hashCode = Arrays.hashCode(_styleSheets) ^
(_short ? 1 : 0) ^
- (_portlet ? 1 : 0);
+ (_portlet ? 1 : 0) ^
+ ((_secureRequest ? 1: 0) << 3);
_noHash = false;
}
@@ -1381,6 +1396,7 @@ public class FileSystemStyleCache implem
private StyleSheetNode[] _styleSheets;
private boolean _portlet;
private boolean _short; // Do we use short style classes?
+ private boolean _secureRequest;
}
/**
@@ -1566,6 +1582,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";
Modified: myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MFacesContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MFacesContext.java?rev=1174340&r1=1174339&r2=1174340&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MFacesContext.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MFacesContext.java Thu Sep 22 19:37:22 2011
@@ -362,6 +362,12 @@ public class MFacesContext extends MockF
// implementations as those expect a specific number of calls:
return _requestMap;
}
+
+ @Override
+ public String getRequestScheme()
+ {
+ return "http";
+ }
private final Object _contextObject;
private final Object _requestObject = new String("request object");