incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwald...@apache.org
Subject svn commit: r527329 - in /incubator/adffaces/trunk/trinidad/trinidad-impl/src: main/java/org/apache/myfaces/trinidadinternal/skin/ main/java/org/apache/myfaces/trinidadinternal/style/cache/ main/java/org/apache/myfaces/trinidadinternal/style/util/ main...
Date Tue, 10 Apr 2007 22:44:54 GMT
Author: jwaldman
Date: Tue Apr 10 15:44:52 2007
New Revision: 527329

URL: http://svn.apache.org/viewvc?view=rev&rev=527329
Log:
resolution for issue ADFFACES-439: use hashcode in generated css file instead of version #
use a StyleSheetDocument id which is based on the StyleSheetNodes's hashcode.
Add public method to StyleSheetDocument getDocumentId(StyleContext)
Add a testcase for the equals methods I added to the *Node classes.
Code cleanup to return Collection instead of Iterator and also the new 1.5 for loop.

Added:
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java
Modified:
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.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
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/NameUtils.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/IncludePropertyNode.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/IncludeStyleNode.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/PropertyNode.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/PropertyNodeParser.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocumentParser.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java?view=diff&rev=527329&r1=527328&r2=527329
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java Tue Apr 10 15:44:52 2007
@@ -24,6 +24,7 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
 import org.apache.myfaces.trinidadinternal.style.util.NameUtils;
 import org.apache.myfaces.trinidadinternal.style.util.StyleUtils;
@@ -120,16 +121,27 @@
     * .AFDefaultFont, af|breadCrumbs::font 
     * {font-family:Arial,Helvetica; font-size:small}
     * One property name/value pair is "font-family"/"Arial,Helvetica"
-    * @param name 
+    * If the name and value are both non-null and we are in a style rule,
+    * then a PropertyNode will be created and added to the _propertyNodeList.
+    * @param name  
     * @param value 
+    * 
     */
   public void property(String name, String value)
   {
 
     if (_inStyleRule && (_propertyNodeList != null))
     {
-      _propertyNodeList.add(new PropertyNode(name, value));
+      if (name == null || "".equals(name))
+      {
+        _LOG.severe("Error when parsing the skin css file. The property's name " +
+        "cannot be null or the empty string. The parser will ignore it. " +
+        "name is '" + name + "' and value is '"+ value + "'");
+      }
+      else
+        _propertyNodeList.add(new PropertyNode(name, value));
     }
+
   }
 
  /**
@@ -466,6 +478,8 @@
   private int[] _selectorPlatforms = null;
   private int[] _selectorAgents = null;
   private Map<String, String> _namespaceMap = new HashMap<String, String>();
+  private static final TrinidadLogger _LOG = 
+    TrinidadLogger.createTrinidadLogger(SkinCSSDocumentHandler.class);
   
 }  
    

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java?view=diff&rev=527329&r1=527328&r2=527329
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java Tue Apr 10 15:44:52 2007
@@ -31,12 +31,8 @@
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.HashSet;
 import java.util.Set;
 import java.util.TreeSet;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 

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=527329&r1=527328&r2=527329
==============================================================================
--- 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 Tue Apr 10 15:44:52 2007
@@ -285,6 +285,12 @@
 
       buffer.append(contextName);
     }
+    if (_isCompressStyles(null))
+    {
+      if (baseName != null || contextName != null)
+        buffer.append(_NAME_SEPARATOR);
+      buffer.append(_COMPRESSED);
+    }
 
     buffer.append(_CSS_EXTENSION);
 
@@ -660,17 +666,8 @@
     // 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 is a portlet skin.
-     String disableContentCompression =
-       FacesContext.getCurrentInstance().getExternalContext().
-       getInitParameter(StyleSheetRenderer.DISABLE_CONTENT_COMPRESSION);
-     // we do not compress if it is a portlet skin
-     Skin skin = RenderingContext.getCurrentInstance().getSkin();
-     boolean isPortletSkin =
-     CoreRenderKit.OUTPUT_MODE_PORTLET.equals(skin.getRenderKitId());
-
-     boolean compressStyles = (!"true".equals(disableContentCompression)) &&
-                                              !isPortletSkin;
-
+    Skin skin = RenderingContext.getCurrentInstance().getSkin();
+    boolean compressStyles = _isCompressStyles(skin);
 
     CSSGenerationUtils.writeCSS(context,
                                 skin.getStyleSheetName(),
@@ -687,6 +684,26 @@
     // Return the name of the new style sheet
     return name;
   }
+  
+  // 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 is a portlet skin.
+  private boolean _isCompressStyles(Skin skin)
+  {
+    if (skin == null)
+      skin = RenderingContext.getCurrentInstance().getSkin();
+      
+
+    String disableContentCompression =
+      FacesContext.getCurrentInstance().getExternalContext().
+      getInitParameter(StyleSheetRenderer.DISABLE_CONTENT_COMPRESSION);
+    // we do not compress if it is a portlet skin
+    boolean isPortletSkin =
+    CoreRenderKit.OUTPUT_MODE_PORTLET.equals(skin.getRenderKitId());
+
+    return (!"true".equals(disableContentCompression)) &&
+                                             !isPortletSkin;    
+  }
 
   // Returns the name of the output file to use for the
   // style sheet associated with the specified context
@@ -831,11 +848,10 @@
     while (styleSheets.hasNext())
     {
       StyleSheetNode styleSheet = styleSheets.next();
-      Iterator<StyleNode> styles = styleSheet.getStyles();
+      Iterable<StyleNode> styles = styleSheet.getStyles();
       assert (styles != null);
-      while (styles.hasNext())
+      for (StyleNode style : styles)
       {
-        StyleNode style = styles.next();
         String selector = style.getSelector();
 
         if (selector != null)
@@ -867,11 +883,10 @@
     while (styleSheets.hasNext())
     {
       StyleSheetNode styleSheet = styleSheets.next();
-      Iterator<StyleNode> styles = styleSheet.getStyles();
+      Iterable<StyleNode> styles = styleSheet.getStyles();
       assert (styles != null);
-      while (styles.hasNext())
+      for (StyleNode style : styles)
       {
-        StyleNode style = styles.next();
         String selector = style.getSelector();
 
         if (selector != null)
@@ -1262,10 +1277,9 @@
       style = new CSSStyle();
 
       // Add in the properties for the style
-      Iterator<PropertyNode> e = styleNode.getProperties();
-      while (e.hasNext())
+      Iterable<PropertyNode> propertyNodeList = styleNode.getProperties();
+      for (PropertyNode property : propertyNodeList)
       {
-        PropertyNode property = e.next();
         String name = property.getName();
         String value = property.getValue();
 
@@ -1319,6 +1333,7 @@
 
   // Separator for variants in file names
   private static final char _NAME_SEPARATOR = '-';
+  private static final String _COMPRESSED = "cmp";
 
   // Extension for CSS files
   private static final String _CSS_EXTENSION = ".css";

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=527329&r1=527328&r2=527329
==============================================================================
--- 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 Tue Apr 10 15:44:52 2007
@@ -31,9 +31,6 @@
 import java.util.Set;
 import java.util.Vector;
 
-import javax.faces.context.ExternalContext;
-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.xhtml.SkinSelectors;
@@ -289,12 +286,11 @@
         // of the properties as specified in the XSS document.  So,
         // we get the properties from the StyleNode object instead of
         // using the propertyString
-        Iterator<PropertyNode> properties = style.getProperties();
+        Iterable<PropertyNode> properties = style.getProperties();
         boolean first = true;
 
-        while (properties.hasNext())
+        for (PropertyNode property : properties)
         {
-          PropertyNode property = properties.next();
           String propName = property.getName();
           String propValue = property.getValue();
 
@@ -1098,9 +1094,9 @@
     //       Collections.synchronizedList(ArrayList) would probably be
     //       a better choice.
     Vector<PropertyNode> v = new Vector<PropertyNode>();
-    Iterator<PropertyNode> e = style.getProperties();
-    while (e.hasNext())
-      v.addElement(e.next());
+    Iterable<PropertyNode> propertyNodeList = style.getProperties();
+    for (PropertyNode propertyNode : propertyNodeList)
+      v.addElement(propertyNode);
 
     PropertyNode[] properties = new PropertyNode[v.size()];
     v.copyInto(properties);

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/NameUtils.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/NameUtils.java?view=diff&rev=527329&r1=527328&r2=527329
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/NameUtils.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/NameUtils.java Tue Apr 10 15:44:52 2007
@@ -293,8 +293,7 @@
    * 
    * @param context The context for which a name is generated.
    */
-  public static String getContextName(StyleContext context,
-      StyleSheetDocument document)
+  public static String getContextName(StyleContext context, StyleSheetDocument document)
   {
     // Copy the matching style sheets into an array
     Iterator<StyleSheetNode> e = document.getStyleSheets(context);
@@ -318,14 +317,12 @@
 
     StringBuffer buffer = new StringBuffer();
 
-    // Start with the document version
+    // Start with the document id
 
-    String documentVersion = _getDocumentVersion(document);
-    if (documentVersion != null)
+    String documentId = _getDocumentId(context, document);
+    if (documentId != null)
     {
-      // We use periods in version numbers, but want underscores in the path
-      documentVersion = documentVersion.replace('.', '_');
-      buffer.append(documentVersion);
+      buffer.append(documentId);
       needSeparator = true;
     }
 
@@ -451,11 +448,10 @@
     return name;
   }
 
-  private static String _getDocumentVersion(
-      StyleSheetDocument document
-      )
+  // get the StyleSheetDocument's id.
+  private static String _getDocumentId(StyleContext context, StyleSheetDocument document)
   {
-    return document.getDocumentVersion();
+    return document.getDocumentId(context);
   }
 
   // Get the version as a String
@@ -515,11 +511,9 @@
 
     for (int i = 0; i < styleSheets.length; i++)
     {
-      Iterator<Locale> e = styleSheets[i].getLocales();
-      while (e.hasNext())
+      Iterable<Locale> localeList = styleSheets[i].getLocales();
+      for (Locale tmpLocale : localeList)
       {
-        Locale tmpLocale = e.next();
-
         if (language.equals(tmpLocale.getLanguage()))
         {
           languageMatch = true;
@@ -586,7 +580,7 @@
     // have a browser match.
     for (int i = 0; i < styleSheets.length; i++)
     {
-      if (!_isIteratorEmpty(styleSheets[i].getBrowsers()))
+      if (!(styleSheets[i].getBrowsers().isEmpty()))
         return true;
     }
 
@@ -606,7 +600,7 @@
     // have a version match.
     for (int i = 0; i < styleSheets.length; i++)
     {
-      if (!_isIteratorEmpty(styleSheets[i].getVersions()))
+      if (!(styleSheets[i].getVersions().isEmpty()))
         return true;
     }
 
@@ -626,20 +620,11 @@
     // have a platform match.
     for (int i = 0; i < styleSheets.length; i++)
     {
-      if (!_isIteratorEmpty(styleSheets[i].getPlatforms()))
+      if (!(styleSheets[i].getPlatforms().isEmpty()))
         return true;
     }
 
     return false;
-  }
-
-  // Tests whether the enumeration is empty.
-  private static final boolean _isIteratorEmpty(Iterator<?> e)
-  {
-    if (e == null)
-      return true;
-
-    return !e.hasNext();
   }
 
   // Direction constants

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/IncludePropertyNode.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/IncludePropertyNode.java?view=diff&rev=527329&r1=527328&r2=527329
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/IncludePropertyNode.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/IncludePropertyNode.java Tue Apr 10 15:44:52 2007
@@ -19,8 +19,14 @@
 package org.apache.myfaces.trinidadinternal.style.xml.parse;
 
 /**
- * IncludePropertyNode is used to represent a single <includeProperty> element
+ * IncludePropertyNode is used to represent a single &lt;includeProperty%gt; element
  * in a parsed XML Style Sheet Language document.
+ * The includeProperty element is used to include a single property of one style 
+ * within another style. Thus, the includeProperty element is very similar to the 
+ * includeStyle element. The only difference is that includeStyle includes all properties 
+ * of the referenced style, whereas includeProperty includes only a single property.
+ * Currently, the includeProperty element is not yet ported to the skin's CSS syntax.
+ * It exists only in the XSS syntax.
  *
  * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/style/xml/parse/IncludePropertyNode.java#0 $) $Date: 10-nov-2005.18:58:07 $
  */
@@ -85,9 +91,51 @@
 
     return _localPropertyName;
   }
+  
+  @Override 
+  public boolean equals(Object obj)
+  {
+    if (this == obj)
+      return true;
+    if (!(obj instanceof IncludePropertyNode))
+      return false;
+     
+    // obj at this point must be an IncludePropertyNode
+    IncludePropertyNode test = (IncludePropertyNode)obj;
+    return
+      (_selector == test._selector || (_selector != null && _selector.equals(test._selector))) &&
+      (_name == test._name || (_name != null && _name.equals(test._name))) &&
+      (_propertyName == test._propertyName || 
+        (_propertyName != null && _propertyName.equals(test._propertyName))) &&
+      (_localPropertyName == test._localPropertyName || 
+        (_localPropertyName != null && _localPropertyName.equals(test._localPropertyName)));       
+  }
+  
+  @Override
+  public int hashCode()
+  {
+    int hash = 17;
+    hash = 37*hash + ((null == _name) ? 0 : _name.hashCode());
+    hash = 37*hash + ((null == _selector) ? 0 : _selector.hashCode());
+    hash = 37*hash + ((null == _propertyName) ? 0 : _propertyName.hashCode());
+    hash = 37*hash + ((null == _localPropertyName) ? 0 : _localPropertyName.hashCode());
+
+    return hash; 
+  }  
+  
+  
+  @Override
+  public String toString()
+  {
+    return 
+      "[name="   + _name   + ", " +
+      "selector=" + _selector + ", " +
+      "propertyName="  + _propertyName  + ", " +
+      "localPropertyName=" + _localPropertyName + "]";
+  }
 
-  private String _name;
-  private String _selector;
-  private String _propertyName;
-  private String _localPropertyName;
+  private final String _name;
+  private final String _selector;
+  private final String _propertyName;
+  private final String _localPropertyName;
 }

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/IncludeStyleNode.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/IncludeStyleNode.java?view=diff&rev=527329&r1=527328&r2=527329
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/IncludeStyleNode.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/IncludeStyleNode.java Tue Apr 10 15:44:52 2007
@@ -51,7 +51,39 @@
   {
     return _selector;
   }
+ 
+  @Override
+  public boolean equals(Object obj)
+  {
+    if (this == obj)
+      return true;
+    if (!(obj instanceof IncludeStyleNode))
+      return false;
+      
+    // obj at this point must be an IncludeStyleNode
+    IncludeStyleNode test = (IncludeStyleNode)obj;
+    return
+      (_selector == test._selector || (_selector != null && _selector.equals(test._selector))) &&
+      (_name == test._name || (_name != null && _name.equals(test._name)));
+  }
+  
+  @Override
+  public int hashCode()
+  {
+    int hash = 17;
+    hash = 37*hash + ((null == _name) ? 0 : _name.hashCode());
+    hash = 37*hash + ((null == _selector) ? 0 : _selector.hashCode());
+    return hash; 
+  }
+  
+  @Override
+  public String toString()
+  {
+    return 
+      "[name="   + _name   + ", " +
+      "selector=" + _selector + "]";
+  }
 
-  private String _name;
-  private String _selector;
+  private final String _name;
+  private final String _selector;
 }

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/PropertyNode.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/PropertyNode.java?view=diff&rev=527329&r1=527328&r2=527329
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/PropertyNode.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/PropertyNode.java Tue Apr 10 15:44:52 2007
@@ -1,12 +1,12 @@
 /*
  * Copyright  2000-2006 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,11 +23,19 @@
  */
 public class PropertyNode
 {
+
   /**
-   * Creates a PropertyNode with the specified name and value
+   * Creates a PropertyNode with the specified name and value.
+   * @param name name of the propertyNode. Examples are 'font-size', 'background-color'.
+   * @param value value of the propertyNode. Examples are '12px', 'red', '0xeaeaea'
+   * If name is null or the empty string, an IllegalArgumentException is thrown.
    */
   public PropertyNode(String name, String value)
   {
+
+    if (name == null || name == "")
+      throw new IllegalArgumentException("PropertyNode's name cannot be null or the empty string." +
+      "name is '" + name + "' and value is '"+ value + "'");
     _name = name;
     _value = value;
   }
@@ -47,7 +55,40 @@
   {
     return _value;
   }
+  
+  @Override
+  public boolean equals(Object obj)
+  {
+    if (this == obj)
+      return true;
+    if (!(obj instanceof PropertyNode))
+      return false;
+
+    // obj at this point must be an PropertyNode
+    PropertyNode test = (PropertyNode)obj;
+
+    return
+      (_value == test._value || (_value != null && _value.equals(test._value))) &&
+      (_name == test._name || (_name != null && _name.equals(test._name)));
+  }
 
-  private String _name;
-  private String _value;
+  @Override
+  public int hashCode()
+  {
+    int hash = 17;
+    hash = 37*hash + ((null == _name) ? 0 : _name.hashCode());
+    hash = 37*hash + ((null == _value) ? 0 : _value.hashCode());
+    return hash;
+  }
+
+  @Override
+  public String toString()
+  {
+    return 
+      "[name="   + _name   + ", " +
+      "value=" + _value + "]";
+  }
+  
+  private final String _name;
+  private final String _value;
 }

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/PropertyNodeParser.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/PropertyNodeParser.java?view=diff&rev=527329&r1=527328&r2=527329
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/PropertyNodeParser.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/PropertyNodeParser.java Tue Apr 10 15:44:52 2007
@@ -18,9 +18,6 @@
  */
 package org.apache.myfaces.trinidadinternal.style.xml.parse;
 
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXParseException;
 

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java?view=diff&rev=527329&r1=527328&r2=527329
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java Tue Apr 10 15:44:52 2007
@@ -20,8 +20,8 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -68,54 +68,80 @@
     boolean                resetProperties
     )
   {
+    // Initialize _name, _selector, _resetProperties
+    // ---------------------------------------------
     _name = name;
     _selector = selector;
-
     _resetProperties = resetProperties;
 
+    // Initialize _properties
+    // ------------------------------
     if (properties != null)
-    {
-      _properties = new PropertyNode[properties.length];
-      System.arraycopy(properties, 0, _properties, 0, properties.length);
-    }
+      _properties = Collections.unmodifiableList(Arrays.asList(properties));
+    else
+      _properties = Collections.emptyList();
 
+
+    // Initialize _includedStyles
+    // ------------------------------
     if (includedStyles != null)
-    {
-      _includedStyles = new IncludeStyleNode[includedStyles.length];
-      System.arraycopy(includedStyles, 0,
-                       _includedStyles, 0,
-                       _includedStyles.length);
-    }
+      _includedStyles = Collections.unmodifiableList(Arrays.asList(includedStyles));
+    else
+      _includedStyles = Collections.emptyList();
+
 
+    // Initialize _includedProperties
+    // ------------------------------
     if (includedProperties != null)
-    {
-      _includedProperties = new IncludePropertyNode[includedProperties.length];
-      System.arraycopy(includedProperties, 0,
-                       _includedProperties, 0,
-                       _includedProperties.length);
-    }
-    
-    _inhibitAll = false;
+      _includedProperties = Collections.unmodifiableList(Arrays.asList(includedProperties));
+    else
+      _includedProperties = Collections.emptyList();
+      
+      
+    // Initialize _inhibitAll and _inhibitedProperties
+    // -----------------------------------------------    
+    boolean inhibitAll = false;
+    // Convert inhibitedProperties Set to an unmodifiableList
+
     if(inhibitedProperties != null)
     {
-      _inhibitedProperties = new ArrayList<String>(inhibitedProperties.size());
+      List<String> inhibitedPropertiesList = new ArrayList<String>(inhibitedProperties.size());
       for(String property : inhibitedProperties)
       {
         if(_INHIBIT_ALL_VALUE.equalsIgnoreCase(property))
         { // Case insensitivity for "all" value
-          _inhibitAll = true;
+        
+          // we don't want to break when we find inhibitAll because all the inhibitedProperties
+          // are needed
+          // e.g., 
+          /* this should end up with  .foo {padding: 8px} */
+          // 
+          // This should first inhibit all inherited styles. Then everything else
+          // should be included.
+          // .foo {
+          //   -tr-inhibit: all;
+          //   padding: 8px;
+          //This should inhibit the background-color that is inherited and/or included,
+          //like in .AFLightAccentBackground:alias
+          //The order of this does not matter.
+          //   -tr-inhibit: background-color;
+          //   -tr-rule-ref: selector(".AFLightAccentBackground:alias");
+          // }
+          inhibitAll = true;
         }
         else
         {
-          _inhibitedProperties.add(property);
+          inhibitedPropertiesList.add(property);
         }
       }
-      
-      if(_inhibitedProperties != null)
-      {
-        _inhibitedProperties = Collections.unmodifiableList(_inhibitedProperties);
-      }
+
+      _inhibitedProperties = Collections.unmodifiableList(inhibitedPropertiesList);
+
     }
+    else
+      _inhibitedProperties = Collections.emptyList();
+    _inhibitAll = inhibitAll;
+
   }
 
   /**
@@ -139,11 +165,11 @@
    */
   public boolean isEmpty()
   {
-    if (_properties != null && _properties.length > 0)
+    if (!_properties.isEmpty())
       return false;
-    if (_includedStyles != null && _includedStyles.length > 0)
+    if (!_includedStyles.isEmpty())
       return false;
-    if (_includedProperties != null && _includedProperties.length > 0)
+    if (!_includedProperties.isEmpty())
       return false;
     return true;
   }
@@ -151,66 +177,48 @@
   /**
    * Implementation of StyleNode.getProperties().
    */
-  public Iterator<PropertyNode> getProperties()
-  {
-  if (_properties == null) 
+  public Collection<PropertyNode> getProperties()
   {
-    List<PropertyNode> list = Collections.emptyList();
-    return list.iterator();
-  }
-  else
-    return (Arrays.asList(_properties)).iterator();
+    return _properties;
   }
 
   /**
-   * Returns an Iterator of IncludeStyleNodes.
+   * Return a Collection of IncludeStyleNode objects for the StyleNode. 
+   * This method will return a Collections.emptyList this StyleNode does
+   * not have any IncludeStyleNode.
+   * 
+   * @return a Collection of the IncludeStyleNode Objects, a Collections.emptyList 
+   *         if there are no IncludeStyleNode Objects in this StyleNode.
    */
-  public Iterator<IncludeStyleNode> getIncludedStyles()
+  public Collection<IncludeStyleNode> getIncludedStyles()
   {
-    if (_includedStyles == null) 
-    {
-      List<IncludeStyleNode> list = Collections.emptyList();
-      return list.iterator();
-    }
-    else
-    {
-      return (Arrays.asList(_includedStyles)).iterator();
-    }
+    return _includedStyles;
   }
 
   /**
-   * Returns an Iterator of IncludePropertyNodes.
+   * Return a Collection of IncludePropertyNode objects for the StyleNode. 
+   * This method will return a Collections.emptyList this StyleNode does
+   * not have any IncludePropertyNodes.
+   * 
+   * @return a Collection of the IncludePropertyNode Objects, a Collections.emptyList 
+   *         if there are no IncludePropertyNode Objects in this StyleNode.
    */
-  public Iterator<IncludePropertyNode> getIncludedProperties()
+  public Collection<IncludePropertyNode> getIncludedProperties()
   {
-    if(_includedProperties == null) 
-    {
-      List<IncludePropertyNode> list = Collections.emptyList();
-      return list.iterator();
-    }
-    else
-      return (Arrays.asList(_includedProperties)).iterator();
+    return _includedProperties;
   }
   
   /**
    * Gets the properties specified by this node's parent that should be
-   * ignored. This method will return an empty iterator if 
+   * ignored. This method will return a Collections.emptyList if 
    * {@link #isInhibitingAll()} returns <code>true</code>
    * 
-   * @return an iterator over the properties that should be ignored, an 
-   *         empty iterator if all properties should be.
+   * @return a Collection of the properties that should be ignored, an 
+   *         Collection.emptyList if all properties should be.
    */
-  public Iterator<String> getInhibitedProperties()
+  public Collection<String> getInhibitedProperties()
   {
-    if(_inhibitedProperties == null) 
-    {
-      List<String> list = Collections.emptyList();
-      return list.iterator();
-    }
-    else
-    {
-      return _inhibitedProperties.iterator();
-    }
+    return _inhibitedProperties;
   }
   
   /**
@@ -223,7 +231,59 @@
   {
     return _inhibitAll;
   }
+  
+  @Override  
+  public boolean equals(Object obj)
+  {
+    if (this == obj)
+      return true;
+    if (!(obj instanceof StyleNode))
+      return false;
+      
+    // obj at this point must be a StyleNode
+    StyleNode test = (StyleNode)obj;
+    // look for equality in the order of what is most likely to be different and what
+    // is easiest to check for.
+    return
+      (_name == test._name || (_name != null && _name.equals(test._name))) &&
+      (_selector == test._selector || (_selector != null && _selector.equals(test._selector))) &&
+      (_resetProperties == test._resetProperties) &&
+      (_inhibitAll == test._inhibitAll) &&
+      (_inhibitedProperties.equals(test._inhibitedProperties)) &&
+      (_includedStyles.equals(test._includedStyles)) &&
+      (_includedProperties.equals(test._includedProperties)) &&
+      (_properties.equals(test._properties));
+  }
+  
+  @Override
+  public int hashCode()
+  {
+    int hash = 17;
+    hash = 37*hash + ((null == _name) ? 0 : _name.hashCode());
+    hash = 37*hash + ((null == _selector) ? 0 : _selector.hashCode());
+    hash = 37*hash + (_resetProperties ? 0 : 1);
+    hash = 37*hash + (_inhibitAll ? 0 : 1);
+    hash = 37*hash + _inhibitedProperties.hashCode();
+    hash = 37*hash + _includedStyles.hashCode();
+    hash = 37*hash + _includedProperties.hashCode();
+    hash = 37*hash + _properties.hashCode();
+    
+    return hash;
+  }
 
+  @Override
+  public String toString()
+  {
+    return getClass().getName() + "[" +
+      "name="   + _name   + ", " +
+      "selector=" + _selector + ", " +
+      "properties="  + _properties.toString()  + ", " +
+      "includeStyles="  + _includedStyles.toString()  + ", " +
+      "includeProperties="  + _includedProperties.toString()  + ", " + 
+      "inhibitedProperties="  + _inhibitedProperties.toString()  + ", " + 
+      "resetProperties="  + _resetProperties  + ", " +
+      "inhibitAll=" + _inhibitAll + "]";
+  }
 
   // Just leaving this package-private, since only
   // StyleSheetDocument really needs to know about this.
@@ -234,20 +294,20 @@
     return _resetProperties;
   }
 
-
-  private String                 _name;
-  private String                 _selector;
-  private PropertyNode[]         _properties;          // The property nodes
-  private IncludeStyleNode[]     _includedStyles;      // Included styles
-  private IncludePropertyNode[]  _includedProperties;  // Included properties
-  private List<String>           _inhibitedProperties; // Inhibited properties
+  private final String                     _name;
+  private final String                     _selector;
+  private final List<PropertyNode>         _properties;          // The property nodes
+  private final List<IncludeStyleNode>     _includedStyles;      // Included styles
+  private final List<IncludePropertyNode>  _includedProperties;  // Included properties
+  private final List<String>               _inhibitedProperties; // Inhibited properties
   
   // These flags checks whether the style should inherit properties
   // from equivalent styles defined in earlier style sheets.
   // This is xss-formatted skin files when resetProperties="true".
-  private boolean                _resetProperties;
+  private final boolean                _resetProperties;
   // This is css-formatted skin files when -tr-inhibit: all.
-  private boolean                _inhibitAll;
+  private final boolean                _inhibitAll;
 
   private static final String _INHIBIT_ALL_VALUE = "all";
+
 }

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java?view=diff&rev=527329&r1=527328&r2=527329
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java Tue Apr 10 15:44:52 2007
@@ -33,6 +33,7 @@
 
 import org.apache.myfaces.trinidadinternal.util.nls.LocaleUtils;
 import java.util.Comparator;
+
 import org.apache.myfaces.trinidad.util.IntegerUtils;
 
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
@@ -108,6 +109,28 @@
   }
 
   /**
+   * Returns the StyleSheetDocument's id.
+   * StyleSheetDocument contains one or more StyleSheetNodes. 
+   * StyleSheetNodes contain StyleNodes & locale, browser, direction, etc.
+   * We compute the hashcode of the StyleSheetDocument's styleSheetNodes(StyleContext) and
+   * return that as a document id. One use of this id is to use it in the Skin's generated
+   * CSS filename so the filename will change if the Skin's StyleSheetNodes change.
+   * @param sContext The current StyleContext which is used to get the stylesheets that match,
+   * and then we create an id based on those stylesheets
+   * @return String The document Id as a String.
+   */
+  public String getDocumentId(StyleContext sContext)
+  {
+    int hashCode = 17;
+    Iterator<StyleSheetNode> styleSheetNodes = getStyleSheets(sContext);
+    while (styleSheetNodes.hasNext())
+    {
+      hashCode = hashCode*37 +  styleSheetNodes.next().hashCode();      
+    }
+    return String.valueOf(Math.abs(hashCode));
+  }
+
+  /**
    * Returns the version identifier for this style sheet document.
    */
   public String getDocumentVersion()
@@ -155,10 +178,11 @@
   public Iterator<StyleSheetNode> getStyleSheets(StyleContext context)
   {
     // =-=ags Should this include the UserStyleSheet?
-    if(_getStyleSheets(context,false)==null)
+     StyleSheetNode[] styleSheets = _getStyleSheets(context,false);
+    if(styleSheets == null)
       return (Arrays.asList(new StyleSheetNode[0])).iterator();
     else
-      return (Arrays.asList(_getStyleSheets(context, false))).iterator();
+      return (Arrays.asList(styleSheets)).iterator();
   }
 
   /**
@@ -200,60 +224,58 @@
     for (int i = 0; i < styleSheets.length; i++)
     {
       StyleSheetNode styleSheet = styleSheets[i];
-      Iterator<StyleNode> e = styleSheet.getStyles();
-      if (e != null)
+      Iterable<StyleNode> styleNodeList = styleSheet.getStyles();
+
+      for (StyleNode node : styleNodeList)
       {
-        while (e.hasNext())
+        String id = null;
+        boolean isNamed = false;
+
+        if (node.getName() != null)
+        {
+          id = node.getName();
+          isNamed = true;
+        }
+        else
+        {
+          id = node.getSelector();
+        }
+
+        StyleNode resolvedNode = _resolveStyle(context,
+                                               styleSheets,
+                                               resolvedStyles,
+                                               resolvedNamedStyles,
+                                               null,
+                                               null,
+                                               id,
+                                               isNamed);
+
+        // If we got a node, add it in to our list
+        if (resolvedNode != null)
         {
-          StyleNode node = e.next();
-          String id = null;
-          boolean isNamed = false;
 
-          if (node.getName() != null)
+          // cache already resolved styles so we don't
+          // resolve them again. This saves time.
+
+          String namedStyle = resolvedNode.getName();
+          String selectorStyle = resolvedNode.getSelector();
+          if (namedStyle != null)
           {
-            id = node.getName();
-            isNamed = true;
+            resolvedNamedStyles.put(namedStyle, resolvedNode);
           }
-          else
+          else if (selectorStyle != null)
           {
-            id = node.getSelector();
+            resolvedStyles.put(selectorStyle, resolvedNode);
           }
 
-          StyleNode resolvedNode = _resolveStyle(context,
-                                                 styleSheets,
-                                                 resolvedStyles,
-                                                 resolvedNamedStyles,
-                                                 null,
-                                                 null,
-                                                 id,
-                                                 isNamed);
-
-          // If we got a node, add it in to our list
-          if (resolvedNode != null)
-          {
 
-            // cache already resolved styles so we don't
-            // resolve them again. This saves time.
+          // add it to our list
 
-            String namedStyle = resolvedNode.getName();
-            String selectorStyle = resolvedNode.getSelector();
-            if (namedStyle != null)
-            {
-              resolvedNamedStyles.put(namedStyle, resolvedNode);
-            }
-            else if (selectorStyle != null)
-            {
-              resolvedStyles.put(selectorStyle, resolvedNode);
-            }
-
-
-            // add it to our list
-
-            if (!_containsStyle(styles, resolvedNode))
-              styles.add(resolvedNode);
-          }
+          if (!_containsStyle(styles, resolvedNode))
+            styles.add(resolvedNode);
         }
       }
+
     }
 
     return styles.iterator();
@@ -283,7 +305,7 @@
     return _getStyle(context, name, true);
   }
 
-  // Returns array of matching style sheets
+  // Returns array of matching style sheets sorted by specificity
   private StyleSheetNode[] _getStyleSheets(
     StyleContext context,
     boolean      includeUserStyleSheet
@@ -470,129 +492,117 @@
     // included styles along the way.
     for (int i = 0; i < styleSheets.length; i++)
     {
-      Iterator<StyleNode> nodes = styleSheets[i].getStyles();
-      if (nodes != null)
+      Iterable<StyleNode> nodes = styleSheets[i].getStyles();
+
+      for (StyleNode node : nodes)
       {
-        while (nodes.hasNext())
-        {
-          StyleNode node = nodes.next();
 
-          if ((isNamed && name.equals(node.getName())) ||
-               (!isNamed && selector.equals(node.getSelector())))
+        if ((isNamed && name.equals(node.getName())) ||
+             (!isNamed && selector.equals(node.getSelector())))
+        {
+          // We've got a match!  We need to do the following:
+          // 0. Check to see whether we need to reset our properties.
+          // 1. Resolve any included styles, and shove those properties
+          //    into our StyleEntry.
+          // 2. Resolve any included properties, and shove those properties
+          //    into our StyleEntry.
+          // 3. Remove all properties that were inhibited.
+          // 4. Shove all properties from the matching StyleNode into our
+          //    StyleEntry, overwriting included values
+          // -= Simon Lessard =-
+          // FIXME: That sequence looks buggy. If more than 1 matching node 
+          //        is found, then the included properties of the second will
+          //        have priority over the properties found at step 5 on the
+          //        first node, which is most likely incorrect.
+          //
+          //        A possible fix would be to put entries from the 5 steps 
+          //        into 5 different lists then resolve all priorities at the 
+          //        end.
+          
+          // 0. Reset properties?
+          if (node.__getResetProperties() || node.isInhibitingAll())
+            entry.resetProperties();
+
+          // 1. Resolve included styles
+          Iterable<IncludeStyleNode> includedStyles = node.getIncludedStyles();
+          for (IncludeStyleNode includeStyle : includedStyles)
           {
-            // We've got a match!  We need to do the following:
-            // 0. Check to see whether we need to reset our properties.
-            // 1. Resolve any included styles, and shove those properties
-            //    into our StyleEntry.
-            // 2. Resolve any included properties, and shove those properties
-            //    into our StyleEntry.
-            // 3. Remove all properties that were inhibited.
-            // 4. Shove all properties from the matching StyleNode into our
-            //    StyleEntry, overwriting included values
-            // -= Simon Lessard =-
-            // FIXME: That sequence looks buggy. If more than 1 matching node 
-            //        is found, then the included properties of the second will
-            //        have priority over the properties found at step 5 on the
-            //        first node, which is most likely incorrect.
-            //
-            //        A possible fix would be to put entries from the 5 steps 
-            //        into 5 different lists then resolve all priorities at the 
-            //        end.
-            
-            // 0. Reset properties?
-            if (node.__getResetProperties() || node.isInhibitingAll())
-              entry.resetProperties();
-
-            // 1. Resolve included styles
-            Iterator<IncludeStyleNode> includedStyles = node.getIncludedStyles();
-            if (includedStyles != null)
-            {
-              while (includedStyles.hasNext())
-              {
-                IncludeStyleNode includeStyle = includedStyles.next();
-                String includeID = null;
-                boolean includeIsNamed = false;
-
-                if (includeStyle.getName() != null)
-                {
-                  includeID = includeStyle.getName();
-                  includeIsNamed = true;
-                }
-                else
-                {
-                  includeID = includeStyle.getSelector();
-                }
-
-                StyleNode resolvedNode = _resolveStyle(context,
-                                                       styleSheets,
-                                                       resolvedStyles,
-                                                       resolvedNamedStyles,
-                                                       includesStack,
-                                                       namedIncludesStack,
-                                                       includeID,
-                                                       includeIsNamed);
+              String includeID = null;
+              boolean includeIsNamed = false;
 
-                if (resolvedNode != null)
-                  _addIncludedProperties(entry, resolvedNode);
+              if (includeStyle.getName() != null)
+              {
+                includeID = includeStyle.getName();
+                includeIsNamed = true;
               }
-            }
-
-            // 2. Resolve included properties
-            Iterator<IncludePropertyNode> includedProperties = 
-              node.getIncludedProperties();
-            if (includedProperties != null)
-            {
-              while (includedProperties.hasNext())
+              else
               {
-                IncludePropertyNode includeProperty = includedProperties.next();
-                String includeID = null;
-                boolean includeIsNamed = false;
-
-                if (includeProperty.getName() != null)
-                {
-                  includeID = includeProperty.getName();
-                  includeIsNamed = true;
-                }
-                else
-                {
-                  includeID = includeProperty.getSelector();
-                }
-
-                StyleNode resolvedNode = _resolveStyle(context,
-                                                       styleSheets,
-                                                       resolvedStyles,
-                                                       resolvedNamedStyles,
-                                                       includesStack,
-                                                       namedIncludesStack,
-                                                       includeID,
-                                                       includeIsNamed);
-
-                if (resolvedNode != null)
-                {
-                  _addIncludedProperty(entry,
-                                       resolvedNode,
-                                       includeProperty.getPropertyName(),
-                                       includeProperty.getLocalPropertyName());
-                }
+                includeID = includeStyle.getSelector();
               }
-            }
 
-            // 3. Check inhibited properties
-            Iterator<String> inhibitedProperties = node.getInhibitedProperties();
-            while (inhibitedProperties.hasNext())
+              StyleNode resolvedNode = _resolveStyle(context,
+                                                     styleSheets,
+                                                     resolvedStyles,
+                                                     resolvedNamedStyles,
+                                                     includesStack,
+                                                     namedIncludesStack,
+                                                     includeID,
+                                                     includeIsNamed);
+
+              if (resolvedNode != null)
+                _addIncludedProperties(entry, resolvedNode);
+          }
+
+
+          // 2. Resolve included properties
+          Iterable<IncludePropertyNode> includedProperties = node.getIncludedProperties();
+          for (IncludePropertyNode includeProperty : includedProperties)
+          {
+            String includeID = null;
+            boolean includeIsNamed = false;
+
+            if (includeProperty.getName() != null)
+            {
+              includeID = includeProperty.getName();
+              includeIsNamed = true;
+            }
+            else
             {
-              entry.removeProperty(inhibitedProperties.next());
+              includeID = includeProperty.getSelector();
             }
-            
 
-            // 4. Add non-included properties
-            Iterator<PropertyNode> properties = node.getProperties();
-            if (properties != null)
+            StyleNode resolvedNode = _resolveStyle(context,
+                                                   styleSheets,
+                                                   resolvedStyles,
+                                                   resolvedNamedStyles,
+                                                   includesStack,
+                                                   namedIncludesStack,
+                                                   includeID,
+                                                   includeIsNamed);
+
+            if (resolvedNode != null)
             {
-              while (properties.hasNext())
-                entry.addProperty(properties.next());
+              _addIncludedProperty(entry,
+                                   resolvedNode,
+                                   includeProperty.getPropertyName(),
+                                   includeProperty.getLocalPropertyName());
             }
           }
+
+          // 3. Check inhibited properties
+          Iterable<String> inhibitedProperties = node.getInhibitedProperties();
+          for (String inhibitedPropertyName : inhibitedProperties)
+          {
+            entry.removeProperty(inhibitedPropertyName);
+          }
+          
+
+          // 4. Add non-included properties
+          Iterable<PropertyNode> properties = node.getProperties();
+          for (PropertyNode propertyNode : properties)
+          {
+            entry.addProperty(propertyNode);
+          }
         }
       }
     }
@@ -621,11 +631,10 @@
     if (node == null)
       return;
 
-    Iterator<PropertyNode> properties = node.getProperties();
-    if (properties != null)
+    Iterable<PropertyNode> properties = node.getProperties();
+    for (PropertyNode propertyNode : properties)
     {
-      while (properties.hasNext())
-        entry.addIncludedProperty(properties.next());
+      entry.addIncludedProperty(propertyNode);
     }
   }
 
@@ -640,24 +649,21 @@
     if (node == null)
       return;
 
-    Iterator<PropertyNode> properties = node.getProperties();
-    if (properties != null)
+    Iterable<PropertyNode> properties = node.getProperties();
+    for (PropertyNode property : properties)
     {
-      while (properties.hasNext())
+      if (propertyName.equals(property.getName()))
       {
-        PropertyNode property = properties.next();
-        if (propertyName.equals(property.getName()))
+        if (!propertyName.equals(localPropertyName))
         {
-          if (!propertyName.equals(localPropertyName))
-          {
-            property = new PropertyNode(localPropertyName,
-                                        property.getValue());
-          }
-
-          entry.addIncludedProperty(property);
+          property = new PropertyNode(localPropertyName,
+                                      property.getValue());
         }
+
+        entry.addIncludedProperty(property);
       }
     }
+
   }
 
   // Returns a count of the non-null items in the Vector
@@ -724,15 +730,11 @@
   // Returns the value of the property with the specified name
   private String _getPropertyValue(StyleNode style, String propertyName)
   {
-    Iterator<PropertyNode> properties = style.getProperties();
-    if (properties != null)
+    Iterable<PropertyNode> properties = style.getProperties();
+    for (PropertyNode property : properties)
     {
-      while (properties.hasNext())
-      {
-        PropertyNode property = properties.next();
-        if (propertyName.equals(property.getName()))
-          return property.getValue();
-      }
+      if (propertyName.equals(property.getName()))
+        return property.getValue();      
     }
 
     return null;
@@ -1430,8 +1432,8 @@
   }
 
   private StyleSheetNode[] _styleSheets;
-  private String           _documentVersion;
-  private long             _documentTimestamp;
+  private final String     _documentVersion;
+  private final long       _documentTimestamp;
 
   static final String _FONT_SIZE_NAME = "font-size";
 

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocumentParser.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocumentParser.java?view=diff&rev=527329&r1=527328&r2=527329
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocumentParser.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocumentParser.java Tue Apr 10 15:44:52 2007
@@ -24,8 +24,6 @@
 import java.net.URL;
 import java.net.URLConnection;
 
-import java.util.Map;
-import java.util.Hashtable;
 import java.util.Vector;
 import java.util.Iterator;
 import java.util.ArrayList;

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java?view=diff&rev=527329&r1=527328&r2=527329
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java Tue Apr 10 15:44:52 2007
@@ -19,12 +19,15 @@
 package org.apache.myfaces.trinidadinternal.style.xml.parse;
 
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 
 
+import java.util.Set;
+
 import org.apache.myfaces.trinidadinternal.util.nls.LocaleUtils;
 
 import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
@@ -34,7 +37,8 @@
 
 
 /**
- * Private implementation of StyleSheetNode.
+ * Private implementation of StyleSheetNode. A StyleSheetNode has StyleNodes for particular
+ * browsers, direction, versions, platforms and mode.
  *
  * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/style/xml/parse/StyleSheetNode.java#0 $) $Date: 10-nov-2005.18:58:46 $
  */
@@ -54,39 +58,57 @@
     int mode
     )
   {
+    // StyleNodes order might matter so this is a List
     if (styles != null)
+      _styles = Collections.unmodifiableList(Arrays.asList(styles));
+    else
+      _styles = Collections.emptyList();
+
+    // locales, browsers, versions, platforms order does not matter, so these are Sets.
+    if (locales != null)
     {
-      _styles = new StyleNode[styles.length];
-      System.arraycopy(styles, 0, _styles, 0, styles.length);
+      Set localesSet = _copyLocaleArrayToSet(locales);
+      _locales = Collections.unmodifiableSet(localesSet);
     }
+    else
+      _locales = Collections.emptySet();
 
-    if (locales != null)
+    if (browsers != null)
     {
-      _locales = new Locale[locales.length];
-      System.arraycopy(locales, 0, _locales, 0, locales.length);
+      Set browsersSet = _copyIntArrayToSet(browsers);
+      _browsers = Collections.unmodifiableSet(browsersSet);
     }
+    else
+      _browsers = Collections.emptySet();
 
-    _browsers = _copyIntArray(browsers);
-    _direction = direction;
-    _versions = _copyIntArray(versions);
-    _platforms = _copyIntArray(platforms);
+
+    if (versions != null)
+    {
+      Set versionsSet = _copyIntArrayToSet(versions);
+      _versions = Collections.unmodifiableSet(versionsSet);
+    }
+    else
+      _versions = Collections.emptySet();
+    
+    if (platforms != null)
+    {
+      Set platformsSet = _copyIntArrayToSet(platforms);
+      _platforms = Collections.unmodifiableSet(platformsSet); 
+    }
+    else
+      _platforms = Collections.emptySet();
+      
     _mode = mode;
+    _direction = direction;
+    _hashCode = _getHashCode();
   }
 
   /**
    * Implementation of StyleSheetNode.getStyles().
    */
-  public Iterator<StyleNode> getStyles()
+  public Collection<StyleNode> getStyles()
   {
-    if(_styles!=null)
-    {
-      return (Arrays.asList(_styles)).iterator();
-    }
-    else
-    {
-      List<StyleNode> list = Collections.emptyList();
-      return list.iterator();
-    }
+    return _styles;
   }
 
   /**
@@ -105,41 +127,33 @@
   /**
    * Implementation of StyleSheetNode.getLocales().
    */
-  public Iterator<Locale> getLocales()
+  public Collection<Locale> getLocales()
   {
-    if (_locales == null) 
-    {
-      List<Locale> list = Collections.emptyList();
-      return list.iterator();
-    }
-    else
-    {
-      return (Arrays.asList(_locales)).iterator();
-    }
+    return _locales;
   }
 
   /**
-   * Implementation of StyleSheetNode.getBrowsers().
+   * Implementation of StyleSheetNode.getBrowsers(). 
    */
-  public Iterator<Integer> getBrowsers()
+  public Collection<Integer> getBrowsers()
   {
-    return Collections.list(new IntegerArrayEnumeration(_browsers)).iterator();
+    return _browsers;
   }
 
   /**
    * Implementation of StyleSheetNode.getVersions().
    */
-  public Iterator<Integer> getVersions()
+  public Collection<Integer> getVersions()
   {
-    return Collections.list(new IntegerArrayEnumeration(_versions)).iterator();
+    return _versions;
   }
 
   /**
    * Implementation of StyleSheetNode.getPlatforms().
    */
-  public Iterator<Integer> getPlatforms()
+  public Collection<Integer> getPlatforms()
   {
-    return Collections.list(new IntegerArrayEnumeration(_platforms)).iterator();
+    return _platforms;
   }
 
 
@@ -192,22 +206,68 @@
     return (localeMatch | browserMatch | versionMatch | osMatch);
   }
 
+  @Override  
+  public boolean equals(Object obj)
+  {
+    if (this == obj)
+      return true;
+    if (!(obj instanceof StyleSheetNode))
+      return false;
+      
+    // obj at this point must be a StyleSheetNode
+    StyleSheetNode test = (StyleSheetNode)obj;
+    // look for equality in the order of what is most likely to be different and what
+    // is easiest to check for.  
+    return
+      (_mode == test._mode) &&
+      (_direction == test._direction) &&
+      (_locales.equals(test._locales)) &&
+      (_browsers.equals(test._browsers)) &&
+      (_platforms.equals(test._platforms)) &&
+      (_versions.equals(test._versions)) &&
+      (_styles.equals(test._styles));
+
+  }
+  
+  @Override
+  public int hashCode()
+  {
+    // return the cached hashCode that is computed in the constructor
+    return _hashCode;
+  }
+  
   @Override
   public String toString()
   {
     return getClass().getName() + "[" +
-      "locales="   + _getLocalesString()   + ", " +
+      "locales="   + _locales.toString()   + ", " +
       "direction=" + _getDirectionString() + ", " +
-      "browsers="  + _getBrowsersString()  + ", " +
-      "versions="  + _getVersionsString()  + ", " +
-      "platforms=" + _getPlatformsString() + "]";
+      "browsers="  + _browsers.toString()  + ", " +
+      "versions="  + _versions.toString()  + ", " +
+      "platforms=" + _platforms.toString()  + ", " +
+      "styles="    + _styles.toString() + "]";
   }
+  
+  // Compute the hashCode and return it.  
+  private int _getHashCode()
+  {
+    int hash = 17;
+    hash = 37*hash + _mode;
+    hash = 37*hash + _direction;
+    hash = 37*hash + _locales.hashCode();
+    hash = 37*hash + _browsers.hashCode();
+    hash = 37*hash + _platforms.hashCode();
+    hash = 37*hash + _versions.hashCode();
+    hash = 37*hash + _styles.hashCode();
+    
+    return hash;
+  }  
 
   // Compares the specified locale against the supported variants
   private int _compareLocale(Locale locale)
   {
     // If we don't have any locales specified, anything matches
-    if (_locales == null)
+    if (_locales.isEmpty())
       return _LOCALE_UNKNOWN_MATCH;
 
     // On the other hand, if the client-locale is not specified,
@@ -217,10 +277,8 @@
 
     int match = 0;
 
-    for (int i = 0; i < _locales.length; i++)
+    for (Locale tmpLocale : _locales)
     {
-      Locale tmpLocale = _locales[i];
-
       if (tmpLocale.getLanguage().equals(locale.getLanguage()))
       {
         if (tmpLocale.getCountry().equals(locale.getCountry()))
@@ -268,15 +326,14 @@
   private int _compareBrowser(int browser)
   {
     // If we don't have a browser specified, we match anything
-    if (_browsers == null)
+    if (_browsers.isEmpty())
       return _BROWSER_UNKNOWN_MATCH;
 
     // On the other hand, if we do have a browser specified, but
     // the client browser is not known, we don't have a match
     if (browser == TrinidadAgent.APPLICATION_UNKNOWN)
       return 0;
-
-    if (_containsInt(browser, _browsers))
+    if (_browsers.contains(Integer.valueOf(browser)))
       return _BROWSER_EXACT_MATCH;
 
     return 0;
@@ -285,10 +342,10 @@
   // Compares the specified version against the supported variants
   private int _compareVersion(int version)
   {
-    if (_versions == null)
+    if (_versions.isEmpty())
       return _VERSION_UNKNOWN_MATCH;
 
-    if (_containsInt(version, _versions))
+    if (_versions.contains(Integer.valueOf(version)))
       return _VERSION_EXACT_MATCH;
 
     return 0;
@@ -298,46 +355,23 @@
   private int _compareOS(int os)
   {
     // If we don't have a platform specified, we match anything
-    if (_platforms == null)
+    if (_platforms.isEmpty())
       return _OS_UNKNOWN_MATCH;
 
     // On the other hand, if we do have a platform specified, but
     // the client platform is unknown, we don't have a match.
     if (os == TrinidadAgent.OS_UNKNOWN)
       return 0;
-
-    if (_containsInt(os, _platforms))
+      
+    if (_platforms.contains(Integer.valueOf(os)))
       return _OS_EXACT_MATCH;
 
-    if (_isUnixPlatform(os) && (_containsInt(__OS_UNIX, _platforms)))
+    if (_isUnixPlatform(os) && (_platforms.contains(Integer.valueOf(__OS_UNIX))))
       return _OS_PARTIAL_MATCH;
 
     return 0;
   }
 
-  // Get a String representing the locales
-  private String _getLocalesString()
-  {
-    if (_locales == null)
-      return _EMPTY_STRING;
-
-    StringBuffer buffer = new StringBuffer();
-    buffer.append("\"");
-
-    for (int i = 0; i < _locales.length; i++)
-    {
-      buffer.append(_locales[i].toString());
-
-      if (i < (_locales.length - 1))
-        buffer.append(" ");
-    }
-
-    buffer.append("\"");
-
-    return buffer.toString();
-
-  }
-
   // Get a String representing the direction
   private String _getDirectionString()
   {
@@ -346,75 +380,6 @@
     return NameUtils.getDirectionName(_direction);
   }
 
-  // Get a String representing the browsers
-  private String _getBrowsersString()
-  {
-    if (_browsers == null)
-      return _EMPTY_STRING;
-
-    StringBuffer buffer = new StringBuffer();
-    buffer.append("\"");
-
-    for (int i = 0; i < _browsers.length; i++)
-    {
-      String name = NameUtils.getBrowserName(_browsers[i]);
-      buffer.append(name);
-
-      if (i < (_browsers.length - 1))
-        buffer.append(" ");
-    }
-
-    buffer.append("\"");
-
-    return buffer.toString();
-  }
-
-  // Get a String representing the versions
-  private String _getVersionsString()
-  {
-    if (_versions == null)
-      return _EMPTY_STRING;
-
-    StringBuffer buffer = new StringBuffer();
-    buffer.append("\"");
-
-    for (int i = 0; i < _versions.length; i++)
-    {
-      String name = Integer.toString(_versions[i]);
-      buffer.append(name);
-
-      if (i < (_versions.length - 1))
-        buffer.append(" ");
-    }
-
-    buffer.append("\"");
-
-    return buffer.toString();
-  }
-
-  // Get a String representing the platforms
-  private String _getPlatformsString()
-  {
-    if (_platforms == null)
-      return _EMPTY_STRING;
-
-    StringBuffer buffer = new StringBuffer();
-    buffer.append("\"");
-
-    for (int i = 0; i < _platforms.length; i++)
-    {
-      String name = NameUtils.getPlatformName(_platforms[i]);
-      buffer.append(name);
-
-      if (i < (_platforms.length - 1))
-        buffer.append(" ");
-    }
-
-    buffer.append("\"");
-
-    return buffer.toString();
-  }
-
   // Tests whether the int n is contained within the int array
   private static boolean _containsInt(int n, int[] array)
   {
@@ -429,18 +394,36 @@
 
     return false;
   }
+  
+  // Returns a copy of the int array into a Set<Integer>
+  private static Set<Integer> _copyIntArrayToSet(int[] array)
+  {
+   int arrayCount = (array != null)
+                      ? array.length
+                      : 0;
+
+   Set<Integer> set = new HashSet<Integer>(arrayCount);
 
-  // Returns a copy of the int array
-  private static int[] _copyIntArray(int[] array)
+   for (int i=0; i < arrayCount ; i++)
+     set.add(array[i]);
+
+   return set;
+  } 
+  
+  // Returns a copy of the Locale array into a Set<Locale>
+  private static Set<Locale> _copyLocaleArrayToSet(Locale[] array)
   {
-    if (array == null)
-      return null;
+   int arrayCount = (array != null)
+                      ? array.length
+                      : 0;
 
-    int[] copy = new int[array.length];
-    System.arraycopy(array, 0, copy, 0, array.length);
+   Set<Locale> set = new HashSet<Locale>(arrayCount);
 
-    return copy;
-  }
+   for (int i=0; i < arrayCount ; i++)
+     set.add(array[i]);
+
+   return set;
+  }   
 
   // Tests whether the specified Agent.OS value is a Unix platform
   private static boolean _isUnixPlatform(int os)
@@ -448,13 +431,15 @@
     return (_containsInt(os, _UNIX_PLATFORMS));
   }
 
-  private StyleNode[] _styles;         // The styles contained within this node
-  private Locale[]    _locales;        // The locale variants
-  private int         _direction;      // The reading direction
-  private int[]       _browsers;       // The browser variants
-  private int[]       _versions;       // The version variants
-  private int[]       _platforms;      // The platform variants
-  private int         _mode;           // The mode  
+  private final List<StyleNode> _styles;     // The styles contained within this node
+  // Order does not matter for locales, browsers, versions, platforms
+  private final Set<Locale>     _locales;    // The locale variants
+  private final int             _direction;  // The reading direction
+  private final Set<Integer>    _browsers;   // The browsers
+  private final Set<Integer>    _versions;   // The version variants
+  private final Set<Integer>    _platforms;  // The platform variants
+  private final int             _mode;       // The mode  
+  private final int             _hashCode;   // The cached hashCode
 
   // Constants for locale matches - 0x000f0000 bits
   private static final int _LOCALE_EXACT_MATCH      = 0x00040000;
@@ -469,7 +454,6 @@
   private static final int _MODE_UNKNOWN_MATCH      = 0x00100000;
   
   
-
   // Constants for browser matches - 0x00000f00 bits
   private static final int _BROWSER_EXACT_MATCH     = 0x00000200;
   private static final int _BROWSER_UNKNOWN_MATCH   = 0x00000100;
@@ -499,5 +483,5 @@
   // creating the int[] platforms array that gets passed in to StyleSheetNode.
   // Agent.OS constants start from 0.  We use Integer.MAX_VALUE to avoid
   // collisions
-          static final int    __OS_UNIX = Integer.MAX_VALUE;
+  static final int __OS_UNIX = Integer.MAX_VALUE;
 }

Added: incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java?view=auto&rev=527329
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java Tue Apr 10 15:44:52 2007
@@ -0,0 +1,297 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.myfaces.trinidadinternal.style.xml.parse;
+
+import junit.framework.TestCase;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.Vector;
+
+/**
+ * Test the hashCode and equals methods on the StyleSheetNode object and the objects
+ * that make up the StyleSheetNode. The hashcode of the StyleSheetNode object is used
+ * to create a StyleSheetDocument id.
+ */
+public class StyleSheetNodeEqualsTest extends TestCase
+{
+  public StyleSheetNodeEqualsTest(String name)
+  {
+    super(name);
+  }
+
+  /**
+   * test the IncludePropertyNode hashCode and equals
+   */
+  public void testIncludePropertyNodeEquals() throws Exception
+  {
+    IncludePropertyNode node = 
+      new IncludePropertyNode(null, "AFDefaultColor", "background-color", "color");
+    IncludePropertyNode anotherNode = 
+      new IncludePropertyNode(null, "AFDefaultColor", "background-color", "color");
+    IncludePropertyNode unequalNode = 
+      new IncludePropertyNode(null, "AFDefaultColor", "background-color", "border-color");
+
+    assertEquals(node.hashCode() == anotherNode.hashCode(), true);   
+    assertEquals(node.equals(anotherNode), true);
+    assertEquals(anotherNode.equals(node), true);
+    assertEquals(node.equals(unequalNode), false);
+    assertEquals(node.equals("Hello"), false);
+  }
+
+  /**
+   * test the IncludeStyleNode hashCode and equals
+   */
+  public void testIncludeStyleNodeEquals() throws Exception
+  {
+    IncludeStyleNode node = 
+      new IncludeStyleNode("name", null);
+    IncludeStyleNode anotherNode = 
+      new IncludeStyleNode("name", null);      
+    IncludeStyleNode unequalNode = 
+      new IncludeStyleNode(null, "anotherSelector");      
+    
+    assertEquals(node.hashCode() == anotherNode.hashCode(), true);   
+    assertEquals(node.equals(anotherNode), true);
+    assertEquals(anotherNode.equals(node), true);
+    assertEquals(node.equals(unequalNode), false);
+    assertEquals(node.equals("Hello"), false);
+
+  }  
+  
+  /**
+   * test the StyleNode hashCode and equals
+   */
+  public void testStyleNodeEquals() throws Exception
+  {
+
+    StyleNode afDefaultFontNode = getAfDefaultFontStyleNode();
+                    
+    StyleNode afDefaultFontNodeReset = getAfDefaultFontResetStyleNode();                    
+                    
+    StyleNode afOutputLabelNode = getOutputLabelStyleNode();
+     
+    StyleNode anotherOutputLabelNode = getAnotherOutputLabelStyleNode();
+     
+    assertEquals(anotherOutputLabelNode.hashCode() == afOutputLabelNode.hashCode(), true);   
+     
+    assertEquals(anotherOutputLabelNode.equals(afOutputLabelNode), true);
+    assertEquals(afOutputLabelNode.equals(anotherOutputLabelNode), true);
+     
+    assertEquals(afDefaultFontNode.equals(anotherOutputLabelNode), false);
+     
+    assertEquals(afDefaultFontNode.equals(afDefaultFontNodeReset), false);
+    assertEquals(afDefaultFontNodeReset.equals(afDefaultFontNode), false);
+    assertEquals(afDefaultFontNodeReset.equals("Hello"), false);
+
+  }
+  
+  public void testStyleSheetNodeEquals() throws Exception
+  {
+    StyleNode[] styleSheetOneNodes = {getAfDefaultFontStyleNode(), 
+                                      getAfDefaultFontResetStyleNode(),
+                                      getOutputLabelStyleNode(),
+                                      getAnotherOutputLabelStyleNode()};
+    StyleNode[] anotherStyleSheetOneNodes = 
+                                      {getAfDefaultFontStyleNode(), 
+                                      getAfDefaultFontResetStyleNode(),
+                                      getOutputLabelStyleNode(),
+                                      getAnotherOutputLabelStyleNode()};
+
+    // create locales arrays
+    Locale[] localesArray = getLocalesArray();
+    Locale[] anotherLocalesArray = getAnotherLocalesArray();
+    Locale[] diffOrderLocalesArray = getDiffOrderLocalesArray();
+     
+    // create a browsers array
+    int[] browsers = {1, 2};
+    int[] anotherBrowsers = {1, 2};
+    int[] anotherBrowsersDiffOrder = {2, 1};
+    
+    int[] versions = {6};
+    int[] anotherVersions = {6};
+
+    int[] platforms = {2, 3, 4};
+    int[] anotherPlatforms = {2, 3, 4};
+    int[] differentOrderPlatforms = {2, 4, 3};
+
+    
+    // The constructor takes these arguments:
+    // StyleNode[] styles,
+    // Locale[] locales,
+    // int direction,
+    // int[] browsers,
+    // int[] versions,
+    // int[] platforms,
+    // int mode
+    
+    StyleSheetNode styleSheetNode = 
+      new StyleSheetNode(styleSheetOneNodes, 
+                         localesArray, 
+                         0, 
+                         browsers, 
+                         versions, 
+                         platforms, 
+                         0);
+    StyleSheetNode anotherStyleSheetNode = 
+      new StyleSheetNode(anotherStyleSheetOneNodes, 
+                         anotherLocalesArray,
+                         0, 
+                         anotherBrowsersDiffOrder, 
+                         anotherVersions,
+                         anotherPlatforms, 
+                         0);
+    StyleSheetNode sameDiffOrderStyleSheetNode = 
+      new StyleSheetNode(anotherStyleSheetOneNodes, 
+                         diffOrderLocalesArray,
+                         0, 
+                         anotherBrowsersDiffOrder, 
+                         anotherVersions,
+                         anotherPlatforms, 
+                         0);                         
+      
+    // these should be equal
+    assertEquals(styleSheetNode.hashCode() == anotherStyleSheetNode.hashCode(), true);   
+    assertEquals(anotherStyleSheetNode.equals(styleSheetNode), true);
+    assertEquals(styleSheetNode.equals(anotherStyleSheetNode), true); 
+    assertEquals(sameDiffOrderStyleSheetNode.equals(anotherStyleSheetNode), true); 
+    assertEquals(styleSheetNode.equals(sameDiffOrderStyleSheetNode), true);
+    
+    // these should be false
+    assertEquals(styleSheetNode.equals(null), false);
+    assertEquals(styleSheetNode.equals(localesArray), false);
+    
+    /* Test styleSheetNode's toString */
+    /*
+    System.out.println(sameLocaleDiffOrderStyleSheetNode.toString());
+    */
+    
+  }
+  
+  // returns a StyleNode for "AFDefaultFont" name, null selector, resetProperties = false  
+  private StyleNode getAfDefaultFontStyleNode()
+  {
+    PropertyNode fontSize = new PropertyNode("font-size", "10pt");
+    PropertyNode fontWeight = new PropertyNode("font-weight", "normal");    
+    PropertyNode[] defaultFontPropertyNodes = { fontSize, fontWeight };
+
+    IncludeStyleNode[] defaultFontIncludeStyles = 
+      { new IncludeStyleNode("AFDefaultFontFamily", null) };
+      
+    IncludePropertyNode[] defaultFontIncludeProperty = 
+      { new IncludePropertyNode("AFVeryDarkBackground", null, "background-color", "color") };
+
+    return
+      new StyleNode("AFDefaultFont", null, defaultFontPropertyNodes, 
+                    defaultFontIncludeStyles, defaultFontIncludeProperty, null, false);
+    
+  }
+  
+  // returns a StyleNode for "AFDefaultFont" name, null selector, resetProperties = true
+  private StyleNode getAfDefaultFontResetStyleNode()
+  {
+    PropertyNode fontSize = new PropertyNode("font-size", "10pt");
+    PropertyNode fontWeight = new PropertyNode("font-weight", "normal");    
+    PropertyNode[] defaultFontPropertyNodes = { fontSize, fontWeight };
+
+    IncludeStyleNode[] defaultFontIncludeStyles = 
+      { new IncludeStyleNode("AFDefaultFontFamily", null) };
+      
+    IncludePropertyNode[] defaultFontIncludeProperty = 
+      { new IncludePropertyNode("AFVeryDarkBackground", null, "background-color", "color") };
+
+    return
+      new StyleNode("AFDefaultFont", null, defaultFontPropertyNodes, 
+                    defaultFontIncludeStyles, defaultFontIncludeProperty, null, true);
+    
+  }  
+  
+  // returns a StyleNode for "af|outputLabel:error" selector
+  private StyleNode getOutputLabelStyleNode()
+  {
+    // build up another StyleNode
+    IncludeStyleNode[] labelIncludeStyles = {new IncludeStyleNode("AFLabel", null)};
+    PropertyNode[] labelPropertyNodes = {new PropertyNode("color", "red")};
+    
+    Set<String> labelInhibitedProperties = new HashSet<String>();
+    labelInhibitedProperties.add("font-size");
+    labelInhibitedProperties.add("background-color");
+
+      
+    return
+        new StyleNode(null, "af|outputLabel:error", labelPropertyNodes, labelIncludeStyles, 
+                      null, labelInhibitedProperties, false);
+  }
+  
+  // returns a StyleNode that matches the outputLabelStyleNode
+  // the inhibited properties are added in a different order, that's all.
+  private StyleNode getAnotherOutputLabelStyleNode()
+  {
+    IncludeStyleNode[] anotherIncludeStyles = {new IncludeStyleNode("AFLabel", null)};
+    PropertyNode[] anotherPropertyNodes = {new PropertyNode("color", "red")};
+    Set<String> anotherInhibitedProperties = new HashSet<String>();
+    anotherInhibitedProperties.add("background-color");
+    anotherInhibitedProperties.add("font-size");
+    
+    return  new StyleNode(null, "af|outputLabel:error", anotherPropertyNodes, anotherIncludeStyles, 
+                          null, anotherInhibitedProperties, false);
+  }
+  
+  
+  private Set<Locale> getLocalesSet()
+  {
+    Set<Locale> set = new HashSet<Locale>();
+    set.add(new Locale("zh", "TW"));
+    set.add(new Locale("zh", "CN"));
+    return set; 
+  }  
+  
+  private Set<Locale> getDiffOrderLocalesSet()
+  {
+    Set<Locale> set = new HashSet<Locale>();
+    set.add(new Locale("zh", "CN"));
+    set.add(new Locale("zh", "TW"));
+
+    return set;  
+  }
+  
+  // same as above
+  private Locale[] getLocalesArray()
+  {
+    return new Locale[] {new Locale("tw", "TW"), new Locale("zh", "CN")};  
+  }  
+  
+  private Locale[] getAnotherLocalesArray()
+  {
+    return new Locale[] {new Locale("tw", "TW"), new Locale("zh", "CN")};  
+  }  
+  
+  // same as above, different order
+  private Locale[] getDiffOrderLocalesArray()
+  {
+    return new Locale[] {new Locale("zh", "CN"), new Locale("tw", "TW")};  
+  }
+  
+}
+



Mime
View raw message