You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mc...@apache.org on 2008/04/02 19:27:54 UTC

svn commit: r643981 [2/2] - in /myfaces/trinidad/trunk_1.2.x: src/site/xdoc/ src/site/xdoc/devguide/ trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/ trinidad-api/src/main/resources/ trinidad-api/src/test/java/org/apache/myfaces/trinidad...

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java?rev=643981&r1=643980&r2=643981&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java (original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java Wed Apr  2 10:27:50 2008
@@ -29,12 +29,17 @@
 
 import java.util.Set;
 
+import java.util.StringTokenizer;
+
+import org.apache.myfaces.trinidad.context.AccessibilityProfile;
+
 import org.apache.myfaces.trinidadinternal.util.nls.LocaleUtils;
 
 import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
 
 import org.apache.myfaces.trinidadinternal.style.util.ModeUtils;
 import org.apache.myfaces.trinidadinternal.style.util.NameUtils;
+import org.apache.myfaces.trinidadinternal.style.xml.XMLConstants;
 
 
 /**
@@ -59,7 +64,8 @@
     int[] browsers,
     int[] versions,
     int[] platforms,
-    int mode
+    int mode,
+    Set<String> accessibilityProperties
     )
   {
     // StyleNodes order might matter so this is a List
@@ -106,6 +112,14 @@
     }
     else
       _platforms = Collections.emptySet();
+
+    if (accessibilityProperties != null)
+    {
+      Set<String> accPropsSet = _copyAccessibilityProperties(accessibilityProperties);
+      _accProps = Collections.unmodifiableSet(accPropsSet);
+    }
+    else
+      _accProps = Collections.emptySet();
       
     _mode = mode;
     _direction = direction;
@@ -173,6 +187,14 @@
     return _platforms;
   }
 
+  /**
+   * Returns the accessibility properties for this StyleSheetNode.
+   */
+  public Collection<String> getAccessibilityProperties()
+  {
+    return _accProps;
+  }
+
 
   /**
    * Tests whether this StyleSheet matches the specified variants.
@@ -186,7 +208,8 @@
     Locale locale, 
     int direction, 
     TrinidadAgent agent, 
-    int mode)
+    int mode,
+    AccessibilityProfile accessibilityProfile)
   {
     int localeMatch = _compareLocale(locale);
     if (localeMatch == 0)
@@ -220,7 +243,11 @@
     if (osMatch == 0)
       return 0;
 
-    return (localeMatch | browserMatch | versionMatch | osMatch);
+    int accessibilityMatch = _compareAccessibility(accessibilityProfile);
+    if (accessibilityMatch == 0)
+      return 0;
+
+    return (localeMatch | browserMatch | versionMatch | osMatch | accessibilityMatch);
   }
 
   @Override  
@@ -268,7 +295,9 @@
       "versions="  + _versions.toString()  + ", " +
       "platforms=" + _platforms.toString() + ", " +
       "styles="    + _styles.toString()    + ", " +
-      "icons="     + _icons.toString()     + "]";
+      "icons="     + _icons.toString()     + ", " +
+      "accessibility-profile=" + _accProps.toString() + "]";
+
   }
 
   /**
@@ -305,6 +334,7 @@
     hash = 37*hash + _platforms.hashCode();
     hash = 37*hash + _versions.hashCode();
     hash = 37*hash + _styles.hashCode();
+    hash = 37*hash + _accProps.hashCode();
     
     return hash;
   }  
@@ -418,6 +448,73 @@
     return 0;
   }
 
+  // Compares accessibilty profile against supported variants.
+  private int _compareAccessibility(AccessibilityProfile accProfile)
+  {
+    // If we don't have any accessibility properties, we match anything.
+    if (_accProps.isEmpty())
+      return _ACC_UNKNOWN_MATCH;
+
+    // If we match any property, the style sheet is a match
+    for (String accProp : _accProps)
+    {
+      if (_isCompoundAccessibilityProperty(accProp))
+      {
+        if (_matchCompoundAccessibilityProperty(accProp, accProfile))
+          return _ACC_EXACT_MATCH;
+      }
+      else if (_matchAccessibilityProperty(accProp, accProfile))
+        return _ACC_EXACT_MATCH;
+    }
+
+    return 0;
+  }
+
+  // Tests whether the specified property is a compound accessibility property.
+  private boolean _isCompoundAccessibilityProperty(String propertyName)
+  {
+    // Compund acc properties use "&" to separate the individual properties
+    return (propertyName.contains("&"));
+  }
+  
+  // Tests whether the we have a match for a compound accessibility property.
+  private boolean _matchCompoundAccessibilityProperty(
+    String               propertyName,
+    AccessibilityProfile accProfile
+    )
+  {
+    StringTokenizer tokens = new StringTokenizer(propertyName, "&");
+
+    while (tokens.hasMoreTokens())
+    {
+      // If any piece of the compound property fails to match, the
+      // compound property fails to match
+      if (!_matchAccessibilityProperty(tokens.nextToken(), accProfile))
+        return false;
+    }
+    
+    // Everything matched - the compound property matches.
+    return true;
+  }
+
+  // Tests whether we have a match for a particular accessibility
+  // property.
+  private boolean _matchAccessibilityProperty(
+    String               propertyName,
+    AccessibilityProfile accProfile
+    )
+  {
+    if (XMLConstants.ACC_HIGH_CONTRAST.equals(propertyName))
+      return accProfile.isHighContrast();
+    if (XMLConstants.ACC_LARGE_FONTS.equals(propertyName))
+      return accProfile.isLargeFonts();
+
+    // Should never reach here (did we add a new property?)    
+    assert(false);
+    
+    return false;
+  }
+
   // Get a String representing the direction
   private String _getDirectionString()
   {
@@ -471,6 +568,12 @@
    return set;
   }   
 
+  // Copies accessibility properties from an array into a set.
+  private static Set<String> _copyAccessibilityProperties(Set<String> accProps)
+  {
+    return new HashSet<String>(accProps);
+  }
+
   // Tests whether the specified Agent.OS value is a Unix platform
   private static boolean _isUnixPlatform(int os)
   {
@@ -486,20 +589,25 @@
   private final Set<Integer>    _versions;   // The version variants
   private final Set<Integer>    _platforms;  // The platform variants
   private final int             _mode;       // The mode  
+  private final Set<String>     _accProps;   // Accessibility profile properties
   private final int             _id;         // The cached style sheet id
 
-  // Constants for locale matches - 0x000f0000 bits
+  // Constants for accessibility matches - 0x0f000000 bits
+  private static final int _ACC_EXACT_MATCH         = 0x02000000;
+  private static final int _ACC_UNKNOWN_MATCH       = 0x01000000;
+
+  // Constants for mode matches - 0x00f00000 bits  
+  private static final int _MODE_EXACT_MATCH        = 0x00200000;
+  private static final int _MODE_UNKNOWN_MATCH      = 0x00100000;
+
+  // Constants for locale matches - 0x000f0000 bits  
   private static final int _LOCALE_EXACT_MATCH      = 0x00040000;
   private static final int _LOCALE_PARTIAL_MATCH    = 0x00020000;
   private static final int _LOCALE_UNKNOWN_MATCH    = 0x00010000;
 
-  // Constants for locale matches - 0x0000f000 bits
+  // Constants for direction matches - 0x0000f000 bits
   private static final int _DIRECTION_EXACT_MATCH   = 0x00002000;
   private static final int _DIRECTION_UNKNOWN_MATCH = 0x00001000;
-  
-  private static final int _MODE_EXACT_MATCH        = 0x00200000;
-  private static final int _MODE_UNKNOWN_MATCH      = 0x00100000;
-  
   
   // Constants for browser matches - 0x00000f00 bits
   private static final int _BROWSER_EXACT_MATCH     = 0x00000200;

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java?rev=643981&r1=643980&r2=643981&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java (original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java Wed Apr  2 10:27:50 2008
@@ -19,10 +19,13 @@
 package org.apache.myfaces.trinidadinternal.style.xml.parse;
 
 import java.util.Arrays;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Locale;
+import java.util.Set;
 import java.util.Vector;
 
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
 import org.apache.myfaces.trinidadinternal.share.xml.BaseNodeParser;
 import org.apache.myfaces.trinidadinternal.share.xml.NodeParser;
@@ -58,6 +61,7 @@
     _initBrowsers(attrs.getValue(BROWSERS_ATTR));
     _initVersions(attrs.getValue(VERSIONS_ATTR));
     _initPlatforms(attrs.getValue(PLATFORMS_ATTR));
+    _initAccessibilityProperties(attrs.getValue(ACC_PROFILE_ATTR));
   }
 
   /**
@@ -85,7 +89,8 @@
         _browsers,
         _versions,
         _platforms,
-        _mode
+        _mode,
+        _accProperties
         );
   }
 
@@ -245,6 +250,34 @@
     _platforms = _getIntegers(v);
   }
 
+  // Initialize accessibility profile properties
+  private void _initAccessibilityProperties(String accProfileAttr)
+  {
+    Iterator<String> tokens = _getTokens(accProfileAttr);
+    if (tokens == null)
+      return;
+
+    // The number of accessibility properties is always small - typically
+    // just 1.  Use a small initial capacity.
+    Set<String> props = new HashSet<String>(11);
+
+    while (tokens.hasNext())
+    {
+      String token = tokens.next();
+              
+      if (NameUtils.isAccessibilityPropertyName(token))
+      {
+        props.add(token);
+      }
+      else
+      {
+        _LOG.warning("INVALID_ACC_PROFILE", new Object[]{token});
+      }
+    }
+    
+    _accProperties = props;
+  }
+
   // Copies Integers from a Vector into an int array
   private int[] _getIntegers(Vector<Integer> v)
   {
@@ -279,4 +312,8 @@
   private int[]             _browsers;
   private int[]             _versions;
   private int[]             _platforms;
+  private Set<String>       _accProperties;
+
+  static private final TrinidadLogger _LOG = 
+    TrinidadLogger.createTrinidadLogger(StyleSheetNodeParser.class);
 }

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts?rev=643981&r1=643980&r2=643981&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts (original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts Wed Apr  2 10:27:50 2008
@@ -624,6 +624,8 @@
 <resource key="REQUIRED_TRINIDADFILTER_NOT_INSTALLED">The TrinidadFilter has not been installed.  Apache Trinidad requires this filter for proper execution.</resource>
 
 <resource key="INVALID_ENUM_IN_CONFIG">The value ''{0}'' is not a legal value for &lt;''{1}''&gt;</resource>
+
+<resource key="INVALID_ACC_PROFILE">The value ''{0}'' is not a valid accessibility-profile property</resource>
 
  <!-- MERGECAPABILITIES_ONLY_USED_WITH_AGENTS_CREATED_BY_THIS_CLASS -->
  <resource key="MERGECAPABILITIES_ONLY_USED_WITH_AGENTS_CREATED_BY_THIS_CLASS">mergeCapabilities() may only be used with Agents created by this class.</resource>

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MRequestContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MRequestContext.java?rev=643981&r1=643980&r2=643981&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MRequestContext.java (original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MRequestContext.java Wed Apr  2 10:27:50 2008
@@ -31,6 +31,7 @@
 
 import org.apache.myfaces.trinidad.change.ChangeManager;
 import org.apache.myfaces.trinidad.config.RegionManager;
+import org.apache.myfaces.trinidad.context.AccessibilityProfile;
 import org.apache.myfaces.trinidad.context.RequestContext;
 import org.apache.myfaces.trinidad.context.Agent;
 import org.apache.myfaces.trinidad.context.PageResolver;
@@ -160,6 +161,17 @@
   }
 
   @Override
+  public AccessibilityProfile getAccessibilityProfile()
+  {
+    return _accProfile;
+  }
+
+  public void setAccessibilityProfile(AccessibilityProfile accProfile)
+  {
+    _accProfile = accProfile;
+  }
+
+  @Override
   public ClientValidation getClientValidation()
   {
     return _clientValidation;
@@ -324,6 +336,7 @@
 
   private String _skin;
   private Accessibility _accMode;
+  private AccessibilityProfile _accProfile;
   private ClientValidation _clientValidation = ClientValidation.ALERT;
   private Agent _agent;
   private boolean _rtl = false;

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java?rev=643981&r1=643980&r2=643981&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java (original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java Wed Apr  2 10:27:50 2008
@@ -145,6 +145,10 @@
     int[] anotherPlatforms = {2, 3, 4};
     int[] differentOrderPlatforms = {2, 4, 3};
 
+    Set<String> accProps = new HashSet<String>(Arrays.asList("high-contrast", "large-fonts"));
+    Set<String> anotherAccProps = new HashSet<String>(Arrays.asList("high-contrast", "large-fonts"));
+    Set<String> differentOrderAccProps = new HashSet<String>(Arrays.asList("large-fonts", "high-contrast"));
+
     
     // The constructor takes these arguments:
     // StyleNode[] styles,
@@ -163,7 +167,8 @@
                          browsers, 
                          versions, 
                          platforms, 
-                         0);
+                         0,
+                         accProps);
     StyleSheetNode anotherStyleSheetNode = 
       new StyleSheetNode(anotherStyleSheetOneNodes,
                          anotherIconNodes,
@@ -172,7 +177,8 @@
                          anotherBrowsersDiffOrder, 
                          anotherVersions,
                          anotherPlatforms, 
-                         0);
+                         0,
+                         anotherAccProps);
     StyleSheetNode sameDiffOrderStyleSheetNode = 
       new StyleSheetNode(anotherStyleSheetOneNodes,
                          anotherIconNodes,
@@ -181,7 +187,8 @@
                          anotherBrowsersDiffOrder, 
                          anotherVersions,
                          anotherPlatforms, 
-                         0);                         
+                         0,
+                         differentOrderAccProps);
       
     // these should be equal
     assertEquals(styleSheetNode.getStyleSheetId() == anotherStyleSheetNode.getStyleSheetId(), true);