You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jw...@apache.org on 2009/04/08 23:29:01 UTC

svn commit: r763404 - in /myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal: agent/ renderkit/core/ renderkit/core/xhtml/ ui/laf/base/

Author: jwaldman
Date: Wed Apr  8 21:29:00 2009
New Revision: 763404

URL: http://svn.apache.org/viewvc?rev=763404&view=rev
Log:
Add an agent capability for style_only. This means that only the style attribute is supported. Not the class attribute.
Add a check in StyleSheetRenderer.java to see if external stylesheets are supported by the agent. If they are not, then
suppress writing out the link to the css file.

Modified:
    myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
    myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
    myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java
    myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/BaseLafRenderer.java

Modified: myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java?rev=763404&r1=763403&r2=763404&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java (original)
+++ myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java Wed Apr  8 21:29:00 2009
@@ -205,10 +205,18 @@
   //
   // Values for CAP_STYLE_ATTRIBUTES
   //
+  // no styling is supported
   static public Object STYLES_NONE               =
           CapabilityValue.getCapabilityValue (CAP_STYLE_ATTRIBUTES, "none");
+  // only the 'style' attribute is supported. The 'class' attribute is not 
+  // supported.
+  static public Object STYLES_STYLE_ONLY              =
+          CapabilityValue.getCapabilityValue (CAP_STYLE_ATTRIBUTES, "style_only");
+  // internal styles only; this includes the style attribute, or the class attribute
+  // as long as the style selectors are in the page with the <style> tag.
   static public Object STYLES_INTERNAL           =
           CapabilityValue.getCapabilityValue (CAP_STYLE_ATTRIBUTES, "internal");
+  // external css files are supported.
   static public Object STYLES_EXTERNAL           =
           CapabilityValue.getCapabilityValue (CAP_STYLE_ATTRIBUTES, "external");
 

Modified: myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java?rev=763404&r1=763403&r2=763404&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java (original)
+++ myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java Wed Apr  8 21:29:00 2009
@@ -823,6 +823,9 @@
                             TrinidadAgent.SCRIPTING_SPEED_CAP_NONE);
     _EMAIL_CAPABILITIES.put(TrinidadAgent.CAP_EDITING,
                             Boolean.FALSE);
+    // email clients cannot handle external css files, but they can
+    // handle the 'class' attribute, as long as the css definitions are
+    // in the html documents
     _EMAIL_CAPABILITIES.put(TrinidadAgent.CAP_STYLE_ATTRIBUTES,
                             TrinidadAgent.STYLES_INTERNAL);
     _EMAIL_CAPABILITIES.put(TrinidadAgent.CAP_PARTIAL_RENDERING,

Modified: myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java?rev=763404&r1=763403&r2=763404&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java (original)
+++ myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java Wed Apr  8 21:29:00 2009
@@ -36,6 +36,7 @@
 import org.apache.myfaces.trinidad.style.Selector;
 import org.apache.myfaces.trinidad.style.Style;
 import org.apache.myfaces.trinidad.style.Styles;
+import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
 import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderingContext;
 import org.apache.myfaces.trinidadinternal.style.StyleContext;
 import org.apache.myfaces.trinidadinternal.style.StyleProvider;
@@ -96,10 +97,10 @@
     {
       List<String> uris = provider.getStyleSheetURIs(sContext);
 
-      // Check if we want to write out the css into the page or not. In portlet mode the 
+      // Check if we want to write out the css into the page or not. In portlet mode the
       // producer tries to share the consumer's stylesheet if it matches exactly.
       boolean suppressStylesheet = _isSuppressStylesheet(context, arc);
-            
+
       if (!suppressStylesheet)
       {
         if (uris != null && !uris.isEmpty())
@@ -182,7 +183,7 @@
 
 
         ResponseWriter writer = context.getResponseWriter();
-        // Check if we want to write out the css into the page or not. In portlet mode the 
+        // Check if we want to write out the css into the page or not. In portlet mode the
         // producer tries to share the consumer's stylesheet if it matches exactly.
         // jmw
         Styles styles = arc.getStyles();
@@ -195,10 +196,10 @@
                               ".AFDefaultFont:alias", // nothing, since currently it's in the wrong format to be a named sele ctor
                               ".AFDefaultFont",// nothing, since currently it's in the wrong format to be a named sele ctor
                               "AFDefaultFont"};// name
-          
+
         System.out.println("getSelectorStyleMap NEW. Gets all the selectors, then find the one you want");
         Map<Selector, Style> selectorStyleMap = styles.getSelectorStyleMap();
-        
+
         for (int i=0; i< selectors.length; i++)
         {
           String selector = selectors[i];
@@ -208,19 +209,19 @@
           else
             System.out.println("no styles for " + selector);
         }
-        
-        
+
+
         String[] simpleSelectorsToInline = {"af|document",
                                             "af|panelHeader",
-                                            "af|showDetailHeader", 
+                                            "af|showDetailHeader",
                                             "af|inputText",
-                                            "af|selectOneChoice", 
-                                            "af|panelLabelAndMessage", 
-                                            "af|image", 
-                                            "af|table", 
-                                            "af|column", 
+                                            "af|selectOneChoice",
+                                            "af|panelLabelAndMessage",
+                                            "af|image",
+                                            "af|table",
+                                            "af|column",
                                             "af|goLink"};
-        
+
         // now try to get the getSelectorsForSimpleSelector to see if we can get the selectors with a certain key like af|inputText
         writer.startElement("style", null);
         for (int i=0; i< simpleSelectorsToInline.length; i++)
@@ -241,22 +242,29 @@
           }
         }
         writer.endElement("style");
-      
+
 
       }
     }
 
 
   // In the portlet environment, the consumer might like the producers to share its stylesheet
-  // for performance reasons. To indicate this the producer sends a 
+  // for performance reasons. To indicate this the producer sends a
   // suppress stylesheet parameter on the request map.
+  // Also, if the Agent Capability cannot handle external css files, this will
+  // return true.
   // returns true if the stylesheet should be suppressed and not written out in the page.
   private boolean _isSuppressStylesheet(FacesContext context, RenderingContext arc)
   {
+    // first see if the agent's capability does not support external css files.
+    if (!_supportsExternalStylesheet(arc))
+      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 = arc.getOutputMode();
     if (XhtmlConstants.OUTPUT_MODE_PORTLET.equals(outputMode))
-    {  
+    {
       Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
       boolean suppressStylesheet = "true".equals(requestMap.get(_SUPPRESS_STYLESHEET_ID_PARAM));
       if (suppressStylesheet)
@@ -270,6 +278,18 @@
     return false;
   }
 
+  // Get the Capability from the agent and return true if the
+  // TrinidadAgent.CAP_STYLE_ATTRIBUTES == STYLES_EXTERNAL.
+  // Defaults to true in case no capability is set.
+  static private boolean _supportsExternalStylesheet(RenderingContext arc)
+  {
+    Object styleCapability = arc.getAgent().getCapabilities().get(
+            TrinidadAgent.CAP_STYLE_ATTRIBUTES);
+
+    return (styleCapability == null ||
+            TrinidadAgent.STYLES_EXTERNAL == styleCapability);
+  }
+
   static private final String _SUPPRESS_STYLESHEET_ID_PARAM =
     "org.apache.myfaces.trinidad.skin.suppressStylesheet";
 

Modified: myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/BaseLafRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/BaseLafRenderer.java?rev=763404&r1=763403&r2=763404&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/BaseLafRenderer.java (original)
+++ myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/BaseLafRenderer.java Wed Apr  8 21:29:00 2009
@@ -976,8 +976,12 @@
           UIXRenderingContext context
           )
   {
-    return (getAgentCapability(context, TrinidadAgent.CAP_STYLE_ATTRIBUTES) ==
-            TrinidadAgent.STYLES_EXTERNAL );
+    // STYLES_INTERNAL means that internal styles are supported, like the
+    // <style> element. This means that class attributes may be supported.
+    return ((getAgentCapability(context, TrinidadAgent.CAP_STYLE_ATTRIBUTES) ==
+            TrinidadAgent.STYLES_EXTERNAL) || 
+           (getAgentCapability(context, TrinidadAgent.CAP_STYLE_ATTRIBUTES) ==
+                TrinidadAgent.STYLES_INTERNAL));
   }