You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by so...@apache.org on 2013/05/22 06:24:53 UTC

svn commit: r1485059 - in /myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal: context/external/ renderkit/core/ renderkit/core/xhtml/ share/config/ skin/

Author: sobryan
Date: Wed May 22 04:24:53 2013
New Revision: 1485059

URL: http://svn.apache.org/r1485059
Log:
TRINIDAD-2392: Ability to control skin and compression programatically

Modified:
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ModifiableAbstractAttributeMap.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
    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/renderkit/core/xhtml/StyleSheetRenderer.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/config/Configuration.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ModifiableAbstractAttributeMap.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ModifiableAbstractAttributeMap.java?rev=1485059&r1=1485058&r2=1485059&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ModifiableAbstractAttributeMap.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ModifiableAbstractAttributeMap.java Wed May 22 04:24:53 2013
@@ -31,7 +31,7 @@ import java.util.Map;
  * @version $Revision$ $Date$
  */
 
-abstract class ModifiableAbstractAttributeMap<K, V> extends AbstractAttributeMap<K, V>
+public abstract class ModifiableAbstractAttributeMap<K, V> extends AbstractAttributeMap<K, V>
 {
   @Override
   public void clear()

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java?rev=1485059&r1=1485058&r2=1485059&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java Wed May 22 04:24:53 2013
@@ -66,6 +66,9 @@ public class CoreRenderingContext extend
    * be ignored.
    */
   static public final String EMPTY_STYLE_CLASS = "";
+  
+  static public final String SKIN_ID_PARAM = "org.apache.myfaces.trinidad.skin.id";
+  static public final String SKIN_STYLESHEET_ID_PARAM = "org.apache.myfaces.trinidad.skin.stylesheet.id";
 
   public CoreRenderingContext()
   {
@@ -481,7 +484,7 @@ public class CoreRenderingContext extend
       return _requestMapSkin;
     _checkedRequestMapSkin = true;
 
-    if (CoreRenderKit.OUTPUT_MODE_PORTLET.equals(getOutputMode()) || isDesignTime())
+    if (isRequestedSkinSupported() || isDesignTime())
     {
       FacesContext context = getFacesContext();
       Object requestedSkinId = getRequestMapSkinId(context);
@@ -546,7 +549,7 @@ public class CoreRenderingContext extend
     Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
 
     // Get the requested Skin Id from the request Map
-    Object requestedSkinId = requestMap.get(_SKIN_ID_PARAM);
+    Object requestedSkinId = requestMap.get(SKIN_ID_PARAM);
     return requestedSkinId;
   }
 
@@ -561,7 +564,7 @@ public class CoreRenderingContext extend
     FacesContext context,
     Skin         requestedSkin)
   {
-    if (CoreRenderKit.OUTPUT_MODE_PORTLET.equals(getOutputMode()))
+    if (isRequestedSkinSupported())
     {
       // check the stylesheetids for a match.
       if (_styleSheetDocumentIdMatch == null)
@@ -571,7 +574,7 @@ public class CoreRenderingContext extend
         if (requestedSkin != null)
         {
           Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
-          Object requestMapStyleSheetId = requestMap.get(_SKIN_STYLESHEET_ID_PARAM);
+          Object requestMapStyleSheetId = requestMap.get(SKIN_STYLESHEET_ID_PARAM);
 
           if (requestMapStyleSheetId != null)
           {
@@ -610,6 +613,11 @@ public class CoreRenderingContext extend
     return false;
   }
 
+  public boolean isRequestedSkinSupported()
+  {
+    return CoreRenderKit.OUTPUT_MODE_PORTLET.equals(getOutputMode());
+  }
+
   /**
    * Set the local variable _skin to be the Skin from the
    * SkinFactory that best matches
@@ -837,11 +845,6 @@ public class CoreRenderingContext extend
   private final RequestContext _requestContext;
   private final boolean        _isDesignTime;
 
-  static private final String _SKIN_ID_PARAM =
-    "org.apache.myfaces.trinidad.skin.id";
-  static private final String _SKIN_STYLESHEET_ID_PARAM =
-    "org.apache.myfaces.trinidad.skin.stylesheet.id";
-
   // Maps describing the capabilities of our output modes
   // -= Simon Lessard =-
   // FIXME: Cannot use CapabilityKey in the generic definition because

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=1485059&r1=1485058&r2=1485059&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 Wed May 22 04:24:53 2013
@@ -18,8 +18,6 @@
  */
 package org.apache.myfaces.trinidadinternal.renderkit.core;
 
-import java.beans.Beans;
-
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentMap;
@@ -31,7 +29,6 @@ import javax.faces.context.FacesContext;
 import org.apache.myfaces.trinidad.context.AccessibilityProfile;
 import org.apache.myfaces.trinidad.context.LocaleContext;
 import org.apache.myfaces.trinidad.context.RenderingContext;
-import org.apache.myfaces.trinidad.context.RequestContext;
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidad.skin.Icon;
 import org.apache.myfaces.trinidad.skin.Skin;
@@ -221,9 +218,36 @@ class StyleContextImpl implements StyleC
    */
   public boolean isDisableStyleCompression()
   {
+    FacesContext context = FacesContext.getCurrentInstance();
+    ExternalContext ec   = context.getExternalContext();
+    
+    //There may be times we want to force the content compression flag by setting
+    //an attribute on the request map.  If this attribute is present, then it will override
+    //any 'automatic' settings we may have for portlet usecases or init parameters in the 
+    //web.xml.  As such, we check the request map for the existence of this parameter and,
+    //if it is present, we return the value, otherwise we go on to checking the init params
+    //and dealing with the portlet usecase.
+    String compress = (String)ec.getRequestMap().get(Configuration.DISABLE_CONTENT_COMPRESSION);
+    if(null != compress)
+    {
+      if("true".equals(compress))
+      {
+        return true;
+      }
+      else if ("false".equals(compress))
+      {
+        return false;
+      }
+      
+      //A value was set, but we don't understand it.  Log a message and go through the
+      //default logic
+      _LOG.warning("Invalid value on request for "+ Configuration.DISABLE_CONTENT_COMPRESSION +": "+compress+".  Going with default value.");
+    }
+    
+    //If we reach this point, we do not have a forced compression parameter on the request.
+    //Now try to determine what the correct setting may be.
     if (_isDisableStyleCompression == null)
     {
-      FacesContext context = FacesContext.getCurrentInstance();
       String disableContentCompression =
         context.getExternalContext().
         getInitParameter(Configuration.DISABLE_CONTENT_COMPRESSION);

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java?rev=1485059&r1=1485058&r2=1485059&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java Wed May 22 04:24:53 2013
@@ -44,6 +44,8 @@ import org.apache.myfaces.trinidadintern
  */
 public class StyleSheetRenderer extends XhtmlRenderer
 {
+  static public final String SUPPRESS_STYLESHEET_ID_PARAM =
+    "org.apache.myfaces.trinidad.skin.suppressStylesheet";
   public StyleSheetRenderer()
   {
     this(CoreStyleSheet.TYPE);
@@ -165,18 +167,21 @@ public class StyleSheetRenderer extends 
     if (!_supportsExternalStylesheet(rc))
       return true;
 
-    // next check if in portlet mode, and if the suppress stylesheet parameter
-    // is set, and it's valid to suppress the stylesheet.
-    String outputMode = rc.getOutputMode();
-    if (XhtmlConstants.OUTPUT_MODE_PORTLET.equals(outputMode))
+    //This assumption was always made in this code.  We just need to move it up because
+    //the decision for whether this applies or not is not solely based on Rendering Mode.
+    CoreRenderingContext crc = (CoreRenderingContext)rc;
+    
+    //If requested skin is supported, there may be an attribute on the request scope to suppress the
+    //stylesheet.
+    if(crc.isRequestedSkinSupported())
     {
       Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
-      boolean suppressStylesheet = "true".equals(requestMap.get(_SUPPRESS_STYLESHEET_ID_PARAM));
+      boolean suppressStylesheet = "true".equals(requestMap.get(SUPPRESS_STYLESHEET_ID_PARAM));
       if (suppressStylesheet)
       {
         // the portlet producer requests that we suppress the stylesheet if the producer's skin
         // and the consumer's skin match exactly.
-        return ((CoreRenderingContext) rc).isRequestMapStyleSheetIdAndSkinEqual(
+        return crc.isRequestMapStyleSheetIdAndSkinEqual(
                                               context, rc.getSkin());
       }
     }
@@ -195,8 +200,4 @@ public class StyleSheetRenderer extends 
     return (styleCapability == null ||
             TrinidadAgent.STYLES_EXTERNAL == styleCapability);
   }
-
-  static private final String _SUPPRESS_STYLESHEET_ID_PARAM =
-    "org.apache.myfaces.trinidad.skin.suppressStylesheet";
-
 }

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/config/Configuration.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/config/Configuration.java?rev=1485059&r1=1485058&r2=1485059&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/config/Configuration.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/config/Configuration.java Wed May 22 04:24:53 2013
@@ -40,7 +40,16 @@ abstract public class Configuration
    * optimizations are enabled by default.  In general,
    * users should not need to disable these optimizations.  However,
    * users who want to build custom skins for Trinidad will find this
-   * setting essential.  Use Boolean.TRUE to disable compression.
+   * setting essential.
+   * 
+   * This setting is "false" by default but may be
+   * specified by adding an init parameter to the web.xml.  A value of
+   * "true" indicates that the content compression for stylesheets will
+   * be disabled.  Additionally an application may set a property with
+   * this flag on the request as a request attribute.  This setting will
+   * override the setting in the web.xml and allow content to be turned
+   * on or off on a per-request basis.  In this case, a String containing
+   * either "true" or "false" is expected, just like in the web.xml case.
    */
   static public final String DISABLE_CONTENT_COMPRESSION =
     "org.apache.myfaces.trinidad.DISABLE_CONTENT_COMPRESSION";

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java?rev=1485059&r1=1485058&r2=1485059&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java Wed May 22 04:24:53 2013
@@ -51,6 +51,7 @@ import org.apache.myfaces.trinidad.skin.
 import org.apache.myfaces.trinidad.skin.SkinAddition;
 import org.apache.myfaces.trinidad.skin.SkinVersion;
 import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderingContext;
+import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.StyleSheetRenderer;
 import org.apache.myfaces.trinidadinternal.share.config.Configuration;
 import org.apache.myfaces.trinidadinternal.skin.icon.ReferenceIcon;
 import org.apache.myfaces.trinidadinternal.style.StyleContext;
@@ -320,7 +321,7 @@ abstract public class SkinImpl extends S
      )
    {
      FacesContext context = FacesContext.getCurrentInstance();
-     if (!_isDisableContentCompressionParameterTrue(context, arc))
+     if (!_isContentCompressionDisabled(context, arc))
      {
         StyleContext sContext = ((CoreRenderingContext)arc).getStyleContext();
         StyleProvider sProvider = sContext.getStyleProvider();  
@@ -954,14 +955,22 @@ abstract public class SkinImpl extends S
   
   // returns true if the web.xml explicitly has DISABLE_CONTENT_COMPRESSION set to true.
   // else return false.
-  private boolean _isDisableContentCompressionParameterTrue(FacesContext context, RenderingContext arc)
+  private boolean _isContentCompressionDisabled(FacesContext context, RenderingContext arc)
   {
     // TODO: this section needs to be MOVED up, perhaps to API,
     // as the StyleContextIMPL.java has exactly the same code;
     // this will be fixed with the advent of "TRINIDAD-1662".
+    ExternalContext ec = context.getExternalContext();
+
+    // first check to see if the DISABLE_CONTENT_COMPRESSION flag is
+    // set on the request.
+    String disableContentCompression = (String)ec.getRequestMap().get(Configuration.DISABLE_CONTENT_COMPRESSION);
     
-    String disableContentCompression = context.getExternalContext().
-      getInitParameter(Configuration.DISABLE_CONTENT_COMPRESSION);
+    if(null == disableContentCompression || !("true".equals(disableContentCompression) || "false".equals(disableContentCompression)))
+    {
+      //Either nothing is set on the request or we have an invalid value that is NOT true or false.  This means we go with the ini setting.
+      disableContentCompression = ec.getInitParameter(Configuration.DISABLE_CONTENT_COMPRESSION);
+    }
 
     boolean disableContentCompressionBoolean; 
 
@@ -1228,4 +1237,7 @@ abstract public class SkinImpl extends S
   private boolean _dirty;
   
   private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(SkinImpl.class);
+  
+  private static final String _FORCE_DISABLE_CONTENT_COMPRESSION_PARAM="org.apache.myfaces.trinidad.skin.disableStyleCompression";
+
 }