incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwald...@apache.org
Subject svn commit: r503944 - in /incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal: renderkit/core/ style/ style/cache/ style/util/
Date Tue, 06 Feb 2007 01:03:46 GMT
Author: jwaldman
Date: Mon Feb  5 17:03:45 2007
New Revision: 503944

URL: http://svn.apache.org/viewvc?view=rev&rev=503944
Log:
For issue http://issues.apache.org/jira/browse/ADFFACES-370
Need to avoid IE's number of CSS selectors limitation
In this checkin, I write out compressed or uncompressed, but not both unless it is a styleclass
that doesn't have '|' in it.
I added getSkin to StyleContext.

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java?view=diff&rev=503944&r1=503943&r2=503944
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
Mon Feb  5 17:03:45 2007
@@ -80,6 +80,11 @@
     return ((CoreRenderingContext) _arc).getTrinidadAgent();
   }
 
+  public Skin getSkin()
+  {
+    return ((CoreRenderingContext) _arc).getSkin();
+  }
+
   public boolean checkStylesModified()
   {
     // =-=AEW Expose a configuration option if this

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java?view=diff&rev=503944&r1=503943&r2=503944
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
Mon Feb  5 17:03:45 2007
@@ -20,6 +20,7 @@
 
 import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
 import org.apache.myfaces.trinidad.context.LocaleContext;
+import org.apache.myfaces.trinidad.skin.Skin;
 
 /**
  * The StyleContext interface is used to provide information
@@ -40,6 +41,7 @@
    * Returns the end user's Agent.
    */
   public TrinidadAgent getAgent();
+  public Skin getSkin();
 
   public String getGeneratedFilesPath();
   public boolean checkStylesModified();

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java?view=diff&rev=503944&r1=503943&r2=503944
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
Mon Feb  5 17:03:45 2007
@@ -38,6 +38,8 @@
 import java.util.Set;
 import java.util.Vector;
 
+import javax.faces.context.FacesContext;
+
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
 import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderingContext;
@@ -47,6 +49,8 @@
 import org.apache.myfaces.trinidadinternal.share.io.InputStreamProvider;
 import org.apache.myfaces.trinidadinternal.share.io.NameResolver;
 import org.apache.myfaces.trinidad.context.LocaleContext;
+import org.apache.myfaces.trinidad.context.RenderingContext;
+import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.StyleSheetRenderer;
 import org.apache.myfaces.trinidadinternal.share.xml.JaxpXMLProvider;
 import org.apache.myfaces.trinidadinternal.share.xml.XMLProvider;
 import org.apache.myfaces.trinidadinternal.style.CSSStyle;
@@ -700,9 +704,22 @@
       return null;
 
     // Write out the style sheet
+    // First figure out whether or not we need to compress the style classes.
+    // We don't compress the style classes if the content compression flag is disabled or
+    // if the skin's styleClassMap does not match our shortStyleClassMap.
+    
+    Map skinsStyleClassMap = context.getSkin().getStyleClassMap(
+                                RenderingContext.getCurrentInstance());
+    String disableContentCompression = 
+      FacesContext.getCurrentInstance().getExternalContext().
+      getInitParameter(StyleSheetRenderer.DISABLE_CONTENT_COMPRESSION);
+    boolean compressStyles = (skinsStyleClassMap == shortStyleClassMap) && 
+                             !"true".equals(disableContentCompression);
+
     CSSGenerationUtils.writeCSS(context,
                                 styles,
                                 out,
+                                compressStyles,
                                 shortStyleClassMap,
                                 namespacePrefixes,
                                 _STYLE_KEY_MAP

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java?view=diff&rev=503944&r1=503943&r2=503944
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java
Mon Feb  5 17:03:45 2007
@@ -32,6 +32,7 @@
 import java.util.Vector;
 
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SkinSelectors;
 import org.apache.myfaces.trinidadinternal.style.StyleContext;
 import org.apache.myfaces.trinidadinternal.style.xml.parse.PropertyNode;
@@ -50,11 +51,13 @@
 
 
   /**
-   * Converts the specified set of StyleNodes to CSS.
+    * Converts the specified set of StyleNodes to CSS. We output either full styleclass names
or 
+    * compressed styleclass names.
    *
    * @param context The current StyleContext
    * @param styles The style nodes to convert
    * @param out The PrintWriter to write to
+   * @param compressStyles This tells us whether or not we want to output the short names.
    * @param shortStyleClassMap A Map which maps style
    *   class names to short names.
    * @param namespacePrefixArray an array with the namespace prefixes of our
@@ -66,6 +69,7 @@
     StyleContext        context,
     StyleNode[]         styles,
     PrintWriter         out,
+    boolean             compressStyles,
     Map<String, String> shortStyleClassMap,
     String[]            namespacePrefixArray,
     Map<String, String> afSelectorMap
@@ -103,6 +107,9 @@
     // during this pass, since we need these strings during the second
     // pass to find matching StyleNodes.
     String[] propertyStrings = new String[styles.length];
+     // Keep track of the number of selectors written out. The reason? IE has a 4095 limit,

+     // and we want to warn when we get to that limit.
+     int numberSelectorsWritten = 0;
 
     for (int i = 0; i < styles.length; i++)
     {
@@ -188,11 +195,22 @@
                                                        selector,
                                                        false);
 
-          // write out the full selector
-          String validFullNameSelector =
-            _getValidFullNameSelector(mappedSelector, namespacePrefixArray);
-          if (validFullNameSelector != null)
-            out.print(validFullNameSelector);
+          String validFullNameSelector = null;
+
+          if (!compressStyles || (mappedSelector.indexOf('|') == -1))
+          {
+            // write out the full selector if we aren't compressing styles or
+            // it doesn't have a '|' in the name which means it may be a user's public styleclass
+            // and we don't want to compress those.
+            validFullNameSelector =
+              _getValidFullNameSelector(mappedSelector, namespacePrefixArray);
+             
+            if (validFullNameSelector != null)
+            {
+              out.print(validFullNameSelector);
+              numberSelectorsWritten++;
+            }
+          }
 
 
           // shorten all the css-2 style class selectors (those that start with 
@@ -204,29 +222,47 @@
           // e.g., selector of af|foo.Bar will shorten the '.Bar' piece 
           // af|foo.xz
           // e.g., .Foo:hover -> .x0:hover
-          String shortenedSelector = _getShortSelector(mappedSelector,
-                                                       shortStyleClassMap);
+          if (compressStyles)
+          {
+            String shortenedSelector = _getShortSelector(mappedSelector,
+                                                        shortStyleClassMap);
 
-          // run it through a shortener one more time to shorten any
-          // of the af component selectors.
-          // e.g., 'af|menuPath' is shortened to '.x11'
-          String shortSelector =
-            _getMappedNSSelector(shortStyleClassMap,
-                                 namespacePrefixArray,
-                                 shortenedSelector,
-                                 true);
-
-          // if the transformed full name is different than the shortSelector
-          // then write out the shortSelector, too.
-          if (shortSelector != null)
-          {          
-            String validShortSelector =
-              _getValidFullNameSelector(shortSelector, namespacePrefixArray);
-            if (!validFullNameSelector.equals(validShortSelector))
-            {
-              out.print(",");
-              out.print(validShortSelector);
-  
+            // run it through a shortener one more time to shorten any
+            // of the af component selectors.
+            // e.g., 'af|menuPath' is shortened to '.x11'
+            String shortSelector =
+              _getMappedNSSelector(shortStyleClassMap,
+                                   namespacePrefixArray,
+                                   shortenedSelector,
+                                   true);
+
+            // if the transformed full name is different than the shortSelector
+            // then write out the shortSelector, too.
+            if (shortSelector != null)
+            {          
+              String validShortSelector =
+                _getValidFullNameSelector(shortSelector, namespacePrefixArray);
+                    
+              // if we wrote out a full style, check to see if we need to write out the short,
too.
+              // if it is something different, write out the short, too.
+              if (validFullNameSelector != null)
+              {
+                //Since validFullNameSelector is not null, we know we wrote out a full style
+                // we write out a short style too in this case if it is different
+                // example: .PublicStyleClass is written out fully even in compressed mode,
but
+                // it is different in compressed mode, so we write that out, too.
+                if (!validFullNameSelector.equals(validShortSelector))
+                {
+                  out.print(',');
+                  out.print(validShortSelector);
+                  numberSelectorsWritten++;
+                }
+              }
+              else
+              {
+                out.print(validShortSelector);
+                numberSelectorsWritten++;
+              }
             }
           }
 
@@ -272,6 +308,21 @@
         out.println("}");
       }
     }
+    out.println("/* The number of CSS selectors in this file is " + numberSelectorsWritten
+ " */");
+    if (numberSelectorsWritten > 4095 && 
+      (TrinidadAgent.APPLICATION_IEXPLORER == context.getAgent().getAgentApplication()))
+    {
+      
+      out.println("/* ERROR: The number of CSS selectors is more than IE's limit of 4095.
" +
+      "The selectors after that will be ignored. */");
+      if (_LOG.isWarning())
+      {
+        _LOG.warning("The css file has hit IE's limit of 4095 CSS selectors. It has " +
+        numberSelectorsWritten + " selectors. " +
+        "The selectors after that will be ignored. ");
+      }
+    }
+
   }
 
   /**



Mime
View raw message