myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sobr...@apache.org
Subject svn commit: r696359 - in /myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal: renderkit/core/StyleContextImpl.java style/StyleContext.java style/cache/FileSystemStyleCache.java
Date Wed, 17 Sep 2008 16:18:45 GMT
Author: sobryan
Date: Wed Sep 17 09:18:44 2008
New Revision: 696359

URL: http://svn.apache.org/viewvc?rev=696359&view=rev
Log:
TRINIDAD-1271 - in portals stylesheet generated in the producer even when skin matches and
suppress is true

* Add an isPortletMode method to the StyleContext and StyleContextImpl which tells if the
current stylesheet is being rendered in the PortletMode or not. This allows us to encode our
stylesheet entries and stylesheet cache files with a special key saying they were rendered
in stylesheet mode.

* Enhance FileSystemStyleCache to keep track of whether a particular skin was generated in
a portlet or not. Current criteria is based off compression, direction, browser and version,
platform, locale, and accessibility profile. I would add portlet mode to this criteria so
that a simple.desktop skin generate by a portlet is cached differently then a simple.desktop
skin generated by a servlet.

* For saved stylesheets, any stylesheets which are cached on the server would be saved with
an "_prtl" prefix. This ensures that servlet generated stylesheets do not interfere with portlet
generated ones.

* I'm also going to add some performance enhancements to the stylesheet cache because, well,
I can. :) 

Modified:
    myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
    myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
    myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java

Modified: myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java?rev=696359&r1=696358&r2=696359&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
(original)
+++ myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
Wed Sep 17 09:18:44 2008
@@ -129,6 +129,11 @@
     return NullStyleProvider.getInstance();
   }
 
+  public boolean isPortletMode()
+  {
+    return CoreRenderKit.OUTPUT_MODE_PORTLET.equals(_arc.getOutputMode());
+  }
+
   // Implementation of StyleProvider which does nothing - used as a
   // placeholder when we can't get the real StyleProvider
   static private class NullStyleProvider implements StyleProvider

Modified: myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java?rev=696359&r1=696358&r2=696359&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
(original)
+++ myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
Wed Sep 17 09:18:44 2008
@@ -50,4 +50,5 @@
   public StyleProvider getStyleProvider();
   public StyleMap getStyleMap();
   public AccessibilityProfile getAccessibilityProfile();
+  public boolean isPortletMode();
 }

Modified: myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java?rev=696359&r1=696358&r2=696359&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
(original)
+++ myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
Wed Sep 17 09:18:44 2008
@@ -26,6 +26,7 @@
 import java.io.PrintWriter;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -40,6 +41,7 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
+import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.trinidad.context.AccessibilityProfile;
@@ -309,7 +311,7 @@
     StyleSheetDocument document
     )
   {
-    StringBuffer buffer = new StringBuffer();
+    StringBuilder buffer = new StringBuilder();
 
     String baseName = _baseName;
     if (baseName != null)
@@ -323,13 +325,24 @@
 
       buffer.append(contextName);
     }
-    if (_isCompressStyles(null))
+     
+    boolean compressedStyles = _isCompressStyles(null);
+    if (compressedStyles)
     {
       if (baseName != null || contextName != null)
         buffer.append(_NAME_SEPARATOR);
       buffer.append(_COMPRESSED);
     }
 
+
+    if (context.isPortletMode())
+    {
+      if (baseName != null || contextName != null || compressedStyles)
+        buffer.append(_NAME_SEPARATOR);
+      
+      buffer.append(_PORTLET);
+    }  
+
     buffer.append(_CSS_EXTENSION);
 
     return buffer.toString();
@@ -483,8 +496,8 @@
     )
   {
     // Next, get the fully resolved styles for this context. This will be
-    // those StyleNodes that match the locale, direction, browser, etc -- the
-    // info that is in the StyleContext.
+    // those StyleNodes that match the locale, direction, browser, portlet mode 
+    // etc -- the info that is in the StyleContext.
     StyleNode[] styles = _getStyleContextResolvedStyles(context, document);
     if (styles == null)
       return null;
@@ -1120,21 +1133,28 @@
        agent.getAgentVersion(),
        agent.getAgentOS(),
        true,
-       accProfile);
+       accProfile,
+       context.isPortletMode());
     }
 
     @Override
     public int hashCode()
     {
-      int shortHash = (_short ? 1 : 0);
-
-      return (_locale.hashCode()           ^
-               (_direction)                ^
-               (_browser  << 2)            ^
-               (_version.hashCode())       ^
-               (_platform << 8)            ^
-               shortHash                   ^
-               _accProfile.hashCode());
+      if(_noHash)
+      {
+        //don't worry about synchronizing this
+        _hashCode =    (_locale.hashCode()         ^
+                       (_direction)                ^
+                       (_browser  << 2)            ^
+                       (_version.hashCode())       ^
+                       (_platform << 8)            ^
+                       (_short ? 1 : 0)            ^
+                       (_accProfile.hashCode())    ^
+                       (_portlet ? 1:0));
+        
+        _noHash = false;
+      }
+      return _hashCode;
     }
 
     @Override
@@ -1143,26 +1163,24 @@
       if (this == o)
         return true;
 
-      if (o instanceof Key)
-      {
+      //Improved performance of this check
+      if ((o.hashCode() == hashCode()) &&  (o instanceof Key))
+      {        
         Key key = (Key)o;
-
         // Check the easy stuff first
-        if ((key._short != _short)           ||
-            (_direction != key._direction)   ||
-            (_browser != key._browser)       ||
-            (!_version.equals(key._version)) ||
-            (_platform != key._platform)     ||
-            !_locale.equals(key._locale)     ||
-            !_accProfile.equals(key._accProfile))
-        {
-          return false;
-        }
+        return ((_short == key._short)           &&
+                (_portlet == key._portlet)       &&
+                (_direction == key._direction)   &&
+                (_browser == key._browser)       &&
+                (_platform == key._platform)     &&
+                _version.equals(key._version)    &&
+                _locale.equals(key._locale)      &&
+                _accProfile.equals(key._accProfile));
       }
 
-      return true;
+      return false;
     }
-
+    
     private void _init(
       Locale locale,
       int direction,
@@ -1170,7 +1188,8 @@
       String version,
       int platform,
       boolean useShort,
-      AccessibilityProfile accessibilityProfile
+      AccessibilityProfile accessibilityProfile,
+      boolean portlet
       )
     {
       // Make sure direction is non-null
@@ -1187,8 +1206,13 @@
       _platform = platform;
       _short = useShort;
       _accProfile = accessibilityProfile;
+      _portlet     = portlet;
     }
-
+    
+    //is immutable, we should cache this, will make things faster in the long run
+    private boolean        _noHash = true;
+    private int            _hashCode;
+    
     private Locale         _locale;
     private int            _direction;
     private int            _browser;
@@ -1196,6 +1220,7 @@
     private int            _platform;
     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
   }
 
   // Cache entry class
@@ -1230,6 +1255,7 @@
       _styleSheets = new StyleSheetNode[styleSheets.length];
       System.arraycopy(styleSheets, 0, _styleSheets, 0, styleSheets.length);
       _short = true;
+      _portlet = context.isPortletMode();
     }
 
     @Override
@@ -1238,43 +1264,52 @@
       if (o == this)
         return true;
 
-      if (!(o instanceof DerivationKey))
-        return false;
-
-      DerivationKey key = (DerivationKey)o;
-
-      if ((_short != key._short) ||
-          (_styleSheets.length != key._styleSheets.length))
-        return false;
-
-      // Test each StyleSheetNode for equality.  We start
-      // at the end of the list, as the last style sheet
-      // is more likely to be different.  (The first entry
-      // is probably the common base style sheet.)
-      for (int i = _styleSheets.length - 1; i >= 0; i--)
+      if ((o.hashCode() == hashCode()) && (o instanceof DerivationKey))
       {
-        if (!_styleSheets[i].equals(key._styleSheets[i]))
+        DerivationKey key = (DerivationKey)o;
+        
+        if ((_short != key._short) || 
+            (_portlet != key._portlet) ||
+            (_styleSheets.length != key._styleSheets.length))
           return false;
+  
+        // Test each StyleSheetNode for equality.  We start
+        // at the end of the list, as the last style sheet
+        // is more likely to be different.  (The first entry
+        // is probably the common base style sheet.)
+        for (int i = _styleSheets.length - 1; i >= 0; i--)
+        {
+          if (!_styleSheets[i].equals(key._styleSheets[i]))
+            return false;
+        }
+        
+        return true;
       }
-
-      return true;
+      
+      return false;
     }
 
     @Override
     public int hashCode()
     {
-      int hashCode = 0;
-
-      for (int i = 0; i < _styleSheets.length; i++)
-        hashCode ^= _styleSheets[i].hashCode();
-
-      int shortHash = (_short ? 1 : 0);
-
-      return hashCode ^ shortHash;
+      if(_noHash)
+      {
+        _hashCode = Arrays.hashCode(_styleSheets) ^
+                    (_short ? 1 : 0)              ^
+                    (_portlet ? 1 : 0);
+        _noHash = false;
+      }
+      
+      return _hashCode;
     }
+    
+    //This object is immutable. So we can cache the hashcode to make it faster
+    private boolean _noHash = false;
+    private int     _hashCode;
 
     private StyleSheetNode[] _styleSheets;
-    private boolean          _short;   // Do we use short style classes?
+    private boolean _portlet;
+    private boolean _short;   // Do we use short style classes?
   }
 
   // A StyleMap implemenation which creates Style objects as needed
@@ -1415,6 +1450,7 @@
   // Separator for variants in file names
   private static final char _NAME_SEPARATOR = '-';
   private static final String _COMPRESSED = "cmp";
+  private static final String _PORTLET = "prtl";
 
   // Extension for CSS files
   private static final String _CSS_EXTENSION = ".css";



Mime
View raw message