You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jw...@apache.org on 2010/01/06 02:21:37 UTC

svn commit: r896295 - in /myfaces/trinidad/trunk: src/site/xdoc/devguide/ trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/ trinidad-examples/trinidad-demo/src/main/webapp/demos/ trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/ trin...

Author: jwaldman
Date: Wed Jan  6 01:21:37 2010
New Revision: 896295

URL: http://svn.apache.org/viewvc?rev=896295&view=rev
Log:
TRINIDAD-1041 Support locale-specific styles
submitted patch for Marius Petoi
This also includes 
removes duplicate @agent in purpleSkin.css
adds a text explaining locale skin in panelPageSkinDemo.jspx
fixed error in old @agent doc in skinning.xml

Modified:
    myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml
    myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-skins.xml
    myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/panelPageSkinDemo.jspx
    myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java
    myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java

Modified: myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml?rev=896295&r1=896294&r2=896295&view=diff
==============================================================================
--- myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml (original)
+++ myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml Wed Jan  6 01:21:37 2010
@@ -829,7 +829,21 @@
         </li>
         <li>
         <strong>@agent</strong> {/skin definitions go here/} - > 
-        Possible values are: netscape, ie, mozilla, gecko, webkit (maps to safari), ice, email. 
+        Possible values are:
+        <ul>
+          <li>netscape</li>
+          <li>ie</li>
+          <li>mozilla</li>
+          <li>gecko</li>
+          <li>webkit (maps to safari)</li>
+          <li>ice</li>
+          <li>email</li>
+          <li>blackberry</li>
+          <li>nokia_s60</li>
+          <li>genericpda</li>
+          <li>konqueror</li>
+          <li>opera</li>
+        </ul>
         This is to define styles only for a particular agent.
         <source>
         @agent ie
@@ -875,6 +889,11 @@
         This is to define styles only for a particular accessibility profile.  See the <a href="configuration.html#accessibility-profile">Configuring Apache Trinidad</a> chapter for information on setting the accessibility profile.
         </li>
         <li>
+        <strong>@locale</strong> {/skin definitions go here/} - >
+        A certain locale must be specified, either only the language or both the language and the country.
+        This is to define styles only for a particular language and country.
+        </li>
+        <li>
         <strong>:rtl</strong> - >  pseudo-class to create a style or icon definition when the browser 
         is in a right-to-left language. The best example is that of images that are not symmetric.
         If you set a skin selector that uses a asymmetrical image, when you set your browser to
@@ -882,7 +901,7 @@
         you use the :rtl pseudo-class at the end of your selector and point it to a flipped-looking image.
         </li>
         <li>
-        :lang or @locale  - >  Not yet implemented in Trinidad.         
+        :lang - >  Not yet implemented in Trinidad.         
         </li>          
         </ul>
           
@@ -906,16 +925,27 @@
         }
 
         /* for ie 5 and 6, we also need some margins.*/
-        @agent ie (version: 5) and (version: 6)
+        @agent ie and (version: 5), ie and (version: 6)
         {
           af|someComponent {margin: 5px;}
         }
         
         /* for Firefox 3 (gecko 1.9) use a smaller margin.*/
-        @agent gecko (version: 1.9)
+        @agent gecko and (version: 1.9)
         {
           af|someComponent {margin: 4px;}
         }
+
+        @locale en, de {
+           af|commandButton {
+              color: red;
+           }
+         }
+         @locale ro-RO {
+           af|commandButton {
+             color: blue;
+           }
+         }
         
         /* The following selectors are for all platforms and all browsers */
         

Modified: myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-skins.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-skins.xml?rev=896295&r1=896294&r2=896295&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-skins.xml (original)
+++ myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-skins.xml Wed Jan  6 01:21:37 2010
@@ -101,4 +101,12 @@
       <style-sheet-name>skins/accdemo/accdemo.css</style-sheet-name>
     </skin>
 
+    <!-- A skin which demonstrates locale features,
+         eg. @locale -->
+    <skin>
+      <id>localedemo.desktop</id>
+      <family>localeDemo</family>
+      <render-kit-id>org.apache.myfaces.trinidad.desktop</render-kit-id>
+      <style-sheet-name>skins/localedemo/localedemo.css</style-sheet-name>
+    </skin>
 </skins>

Modified: myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/panelPageSkinDemo.jspx
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/panelPageSkinDemo.jspx?rev=896295&r1=896294&r2=896295&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/panelPageSkinDemo.jspx (original)
+++ myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/panelPageSkinDemo.jspx Wed Jan  6 01:21:37 2010
@@ -86,6 +86,7 @@
                   <tr:selectItem label="purpleBigFont" value="purpleBigFont"/>
                   <tr:selectItem label="beach" value="beach"/>
                   <tr:selectItem label="suede" value="suede"/>
+                  <tr:selectItem label="locale" value="localeDemo"/>
                 </tr:selectOneChoice>
                 <tr:commandButton text="Go"/>
                 <tr:goLink id="goLinkId" text="EmailablePageMode" 
@@ -156,7 +157,7 @@
                     </tr:showDetailItem>
                     <tr:showDetailItem text="Tab 2" disclosed="true">
                       <tr:panelHeader text="PanelTabbed details">
-                        <tr:outputText value="Everything in Camping  is on sale!  Enjoy huge savings on our most popular tents                     and sleeping bags. We even have dried food and mattresses"
+                        <tr:outputText value="In Locale Skin, commandButton text is red in en and de locales and blue in ro-RO. Test it out!"
                                        styleClass="mainContentText"/>
                         <tr:panelGroupLayout layout="horizontal">
                           <tr:goButton text="Sorry, Disabled" disabled="true"/>

Modified: myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css?rev=896295&r1=896294&r2=896295&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css (original)
+++ myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css Wed Jan  6 01:21:37 2010
@@ -920,6 +920,10 @@
   af|selectBooleanCheckbox::label {color: aqua}
 }
 
+@agent gecko and (min-version:1.9.*) {
+  af|selectBooleanCheckbox::label {color: Orange;}
+}
+
 @agent gecko and (min-version:0.8.1.*)  and (max-version:0.9.1.*), gecko and (version:5), ie and (min-version:5.*) and (max-version:8), gecko and (version: 2.9.1.*){
   af|selectBooleanCheckbox::label {color: fuschia}
 }

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java?rev=896295&r1=896294&r2=896295&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java Wed Jan  6 01:21:37 2010
@@ -19,13 +19,17 @@
 package org.apache.myfaces.trinidadinternal.skin;
 
 import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.ArrayList;
+import java.util.Locale;
 import java.util.Set;
+import java.util.HashSet;
+import java.util.HashMap;
+import java.util.LinkedList;
 
 import org.apache.myfaces.trinidad.context.Version;
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
@@ -110,6 +114,7 @@
        CompleteSelectorNode node =
          _createCompleteSelectorNode(selector,
                                      _propertyNodeList,
+                                     _locales,
                                      _agentAtRuleMatcher,
                                      _selectorPlatforms,
                                      _getSelectorAccProperties());
@@ -187,6 +192,10 @@
       {
         _parseCustomAtRule(_AT_PLATFORM, atRule);
       }
+      else if (atRule.startsWith(_AT_LOCALE))
+      {
+        _parseCustomAtRule(_AT_LOCALE, atRule);
+      }
       else if (atRule.startsWith(_AT_ACC_PROFILE))
       {
         _parseCustomAtRule(_AT_ACC_PROFILE, atRule);
@@ -202,8 +211,8 @@
    */
   private void _parseCustomAtRule(String type, String atRule)
   {
-    // get the @agent agents, they are deliminated by commas
-    // parse out the content
+    // get the @agent agents, @platform platforms or the @locale locales 
+    // they are deliminated by commas parse out the content
     // save the atRule type, so the document handler code can get to it.
     // run this through parser again
     String content = _getAtRuleContent(atRule);
@@ -226,6 +235,8 @@
       _agentAtRuleMatcher = null;
     else if (_AT_PLATFORM.equals(type))
       _selectorPlatforms = null;
+    else if (_AT_LOCALE.equals(type))
+      _locales = null;
     else if (_AT_ACC_PROFILE.equals(type))
     {
       assert(!_selectorAccPropertiesStack.isEmpty());
@@ -240,6 +251,7 @@
   private CompleteSelectorNode _createCompleteSelectorNode(
     String                     selector,
     List<PropertyNode>         propertyNodeList,
+    Set<Locale>                locales,
     AgentAtRuleMatcher         agentMatcher,
     int[]                      selectorPlatforms,
     Set<String>                selectorAccProperties)
@@ -266,6 +278,7 @@
       new CompleteSelectorNode(
         selector,
         propertyNodeList,
+        locales,
         direction,
         agentMatcher,
         selectorPlatforms,
@@ -293,6 +306,7 @@
       int direction = completeSelectorNode.getDirection();
       AgentAtRuleMatcher agentMatcher = completeSelectorNode.getAgentMatcher();
       int[] platforms = completeSelectorNode.getPlatforms();
+      Set<Locale> locales = completeSelectorNode.getLocales();
       Set<String> accProperties = completeSelectorNode.getAccessibilityProperties();
 
       // loop through the skinStyleSheetNodeList to find a match
@@ -304,7 +318,7 @@
       for (int i = skinStyleSheetNodes.size() - 1; i >= 0 && !match; --i)
       {
         SkinStyleSheetNode ssNode = skinStyleSheetNodes.get(i);
-        match = ssNode.matches(direction, agentMatcher, platforms, accProperties);
+        match = ssNode.matches(direction, agentMatcher, platforms, locales, accProperties);
         if (match)
           ssNode.add(completeSelectorNode.getSkinSelectorPropertiesNode());
       }
@@ -313,7 +327,7 @@
       {
         // no matching stylesheet node found, so create a new one
         SkinStyleSheetNode ssNode =
-         new SkinStyleSheetNode(namespaceMap, direction, agentMatcher, platforms, accProperties);
+         new SkinStyleSheetNode(namespaceMap, direction, locales, agentMatcher, platforms, accProperties);
         ssNode.add(completeSelectorNode.getSkinSelectorPropertiesNode());
         skinStyleSheetNodes.add(ssNode);
       }
@@ -324,7 +338,7 @@
   /**
    * Initialized at rule target types.
    * 
-   * @param type type of the at rule. _AT_AGENT, _AT_PLATFORM, or _AT_ACC_PROFILE
+   * @param type type of the at rule. _AT_AGENT, _AT_PLATFORM, _AT_ACC_PROFILE or _AT_LOCALE
    * @param atRule - the atRule string
    */
   private void _initAtRuleTargetTypes(
@@ -359,6 +373,15 @@
         
         _selectorPlatforms = _getIntArray(list);
       }
+      else if (_AT_LOCALE.equals(type))
+      {
+        _locales = new HashSet<Locale>();
+        for (int i = 0; i < typeArray.length; i++)
+        {
+          Locale locale = LocaleUtils.getLocaleForIANAString(typeArray[i].replace('_', '-').trim());
+          _locales.add(locale);
+        }
+      }
       else if (_AT_ACC_PROFILE.equals(type))
       {
         // The number of profile properties is always going to be
@@ -501,6 +524,7 @@
     public CompleteSelectorNode(
       String                     selectorName,
       List<PropertyNode>         propertyNodes,
+      Set<Locale>                locales,            
       int                        direction,
       AgentAtRuleMatcher         agentMatcher,
       int[]                      platforms,
@@ -514,6 +538,8 @@
       // at the end of the @rule parsing.
       _agentMatcher = agentMatcher;
       _platforms = _copyIntArray(platforms);
+      _locales = ((locales != null) ? new HashSet<Locale>(locales)
+            :Collections.<Locale>emptySet());
       
       if (accProperties != null)
       {
@@ -551,6 +577,11 @@
       return _platforms;
     }
 
+    public Set<Locale> getLocales()
+    {
+      return _locales;
+    }
+
     public Set<String> getAccessibilityProperties()
     {
       return _accProperties;
@@ -572,12 +603,14 @@
     private final int _direction;  // the reading direction
     private final AgentAtRuleMatcher _agentMatcher;
     private final int[] _platforms;
+    private final Set<Locale> _locales; 
     private final Set<String> _accProperties;
   }
 
-  private static String _AT_AGENT = "@agent";
-  private static String _AT_PLATFORM = "@platform";
-  private static String _AT_ACC_PROFILE = "@accessibility-profile";
+  private static final String _AT_AGENT = "@agent";
+  private static final String _AT_PLATFORM = "@platform";
+  private static final String _AT_LOCALE = "@locale";
+  private static final String _AT_ACC_PROFILE = "@accessibility-profile";
 
   // below are properties that we set and reset
   // as the methods of this documentHandler get called.
@@ -594,6 +627,9 @@
   // matches the current Agent against the allowed agents
   private AgentAtRuleMatcher _agentAtRuleMatcher = null;
 
+  // the locales of the selectors parsed in this document.
+  private Set<Locale> _locales = null;
+
   // Stack of accessibility property sets.  While java.util.Stack has the
   // push/pop API that we want, we don't need the synchronization, so we
   // just use a LinkedList instead and pretend its a stack.

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java?rev=896295&r1=896294&r2=896295&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java Wed Jan  6 01:21:37 2010
@@ -21,6 +21,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
@@ -41,11 +42,13 @@
     List<SkinSelectorPropertiesNode> skinSelectorNodeList,
     Map<String, String>              namespaceMap,
     int                              direction,
+    Set<Locale>                      locales,
     AgentAtRuleMatcher               agentMatcher,
     Set<String>                      accProperties)
   {
     _skinSelectorNodeList = skinSelectorNodeList;
     _namespaceMap = namespaceMap;
+    _locales = locales;
     _direction = direction;
     _agentMatcher = agentMatcher;
     _platforms     = null;
@@ -55,12 +58,14 @@
   SkinStyleSheetNode(
     Map<String, String>        namespaceMap,
     int                        direction,
+    Set<Locale>                locales,
     AgentAtRuleMatcher         agentMatcher,
     int[]                      platforms,
     Set<String>                accProperties)
   {
     _namespaceMap = namespaceMap;
     _direction = direction;
+    _locales = locales;
     _agentMatcher = agentMatcher;
     _platforms = platforms;
     _accProperties = accProperties;
@@ -113,6 +118,11 @@
     return _platforms;
   }
 
+  public Set<Locale> getLocales()
+  {
+    return _locales;
+  }
+
   public Set<String> getAcessibilityProperties()
   {
     return _accProperties;
@@ -122,6 +132,7 @@
     int                        direction,
     AgentAtRuleMatcher         agentMatcher,
     int[]                      platforms,
+    Set<Locale>                locales,
     Set<String>                accProperties)
   {
     if (direction == _direction)
@@ -133,10 +144,13 @@
         boolean platformsMatch = _intArraysEqual(platforms, _platforms);
         if (platformsMatch)
         {
-          boolean accMatch = _setsEqual(accProperties, _accProperties);
-
-          if (accMatch)
-            return true;
+          boolean localeMatch = _setsEqual(locales, _locales);
+          if (localeMatch)
+          {
+            boolean accMatch = _setsEqual(accProperties, _accProperties);
+            if (accMatch)
+             return true;
+          }
         }
       }
     }
@@ -167,5 +181,6 @@
   private final int _direction; // reading direction
   private final AgentAtRuleMatcher _agentMatcher;
   private final int[] _platforms;
+  private final Set<Locale> _locales;
   private final Set<String> _accProperties;
 }

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java?rev=896295&r1=896294&r2=896295&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java Wed Jan  6 01:21:37 2010
@@ -266,7 +266,7 @@
           new StyleSheetNode(styleNodeArray,
                              iconNodeList,
                              trSkinPropertyNodeList,
-                             null,/*locales, not yet supported*/
+                             skinSSNode.getLocales(),
                              skinSSNode.getDirection(),
                              skinSSNode.getAgentMatcher(),
                              skinSSNode.getPlatforms(),

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java?rev=896295&r1=896294&r2=896295&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java Wed Jan  6 01:21:37 2010
@@ -57,7 +57,7 @@
     StyleNode[] styles,
     Collection<IconNode> icons,
     Collection<SkinPropertyNode> skinProperties,
-    Locale[] locales,
+    Set<Locale> locales,
     int direction,
     AgentAtRuleMatcher agentMatcher,
     int[] platforms,
@@ -86,8 +86,7 @@
     // locales, browsers, versions, platforms order does not matter, so these are Sets.
     if (locales != null)
     {
-      Set<Locale> localesSet = _copyLocaleArrayToSet(locales);
-      _locales = Collections.unmodifiableSet(localesSet);
+      _locales = Collections.unmodifiableSet(locales);
     }
     else
       _locales = Collections.emptySet();

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java?rev=896295&r1=896294&r2=896295&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java Wed Jan  6 01:21:37 2010
@@ -41,6 +41,7 @@
 import org.apache.myfaces.trinidadinternal.style.StyleConstants;
 import org.apache.myfaces.trinidadinternal.style.util.NameUtils;
 import org.apache.myfaces.trinidadinternal.style.xml.XMLConstants;
+import org.apache.myfaces.trinidadinternal.util.nls.LocaleUtils;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXParseException;
 
@@ -142,23 +143,6 @@
     }
   }
 
-  // Converts a string to a locale
-  private Locale _getLocale(String str)
-  {
-    // Language only
-    int length = str.length();
-    if (length == 2)
-      return new Locale(str, "");
-
-    // Locale and country
-    if ((length == 5) && (str.charAt(2) == '_'))
-      return new Locale(str.substring(0, 2), str.substring(3, 5));
-
-    // We don't handle variants at the moment...
-
-    return null;
-  }
-
   // Initialize locales
   private void _initLocales(String localeAttr)
   {
@@ -167,20 +151,16 @@
 
     // -= Simon Lessard =-
     // TODO: Check if synchronization is really needed.
-    Vector<Locale> locales = new Vector<Locale>();
+    _locales = Collections.synchronizedSet(new HashSet<Locale>());
     Iterator<String> tokens = _getTokens(localeAttr);
     while (tokens.hasNext())
     {
-      Locale locale = _getLocale(tokens.next());
+      String localeString = tokens.next();
+      // TODO: check if the replace of _ with - is really necessary. Also see RequestContextImpl.getFormattingLocale()
+      Locale locale = LocaleUtils.getLocaleForIANAString(localeString.replace('_', '-').trim());
 
       if (locale != null)
-        locales.addElement(locale);
-    }
-
-    if (locales != null)
-    {
-      _locales = new Locale[locales.size()];
-      locales.copyInto(_locales);
+        _locales.add(locale);
     }
   }
 
@@ -309,7 +289,7 @@
   // -= Simon Lessard =-
   // TODO: Check if synchronization is really needed.
   private Vector<StyleNode> _styles;
-  private Locale[]          _locales;
+  private Set<Locale>       _locales;
   private int               _direction;
   private int               _mode;
   private List<TrinidadAgent.Application> _browsers;

Modified: myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java?rev=896295&r1=896294&r2=896295&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java Wed Jan  6 01:21:37 2010
@@ -129,9 +129,8 @@
     List<IconNode> anotherIconNodes = _getIconNodes();
 
     // create locales arrays
-    Locale[] localesArray = getLocalesArray();
-    Locale[] anotherLocalesArray = getAnotherLocalesArray();
-    Locale[] diffOrderLocalesArray = getDiffOrderLocalesArray();
+    Set<Locale> localeSet = getLocalesSet();
+    Set<Locale> diffOrderLocalesSet = getDiffOrderLocalesSet();
      
     // create a browsers map
     String browserSelector = "netscape and (version:5), netscape and (version:6), ie and (version:7), ie and (version:8)";
@@ -159,7 +158,7 @@
       new StyleSheetNode(styleSheetOneNodes,
                          iconNodes,
                          null,
-                         localesArray,
+                         localeSet,
                          0,
                          new AgentAtRuleMatcher(browserSelector),
                          platforms,
@@ -169,7 +168,7 @@
       new StyleSheetNode(anotherStyleSheetOneNodes,
                          anotherIconNodes,
                          null,
-                         anotherLocalesArray,
+                         localeSet,
                          0,
                          new AgentAtRuleMatcher(anotherBrowserSelector),
                          anotherPlatforms,
@@ -179,7 +178,7 @@
       new StyleSheetNode(anotherStyleSheetOneNodes,
                          anotherIconNodes,
                          null,
-                         diffOrderLocalesArray,
+                         diffOrderLocalesSet,
                          0,
                          new AgentAtRuleMatcher(anotherBrowserDiffOrder),
                          differentOrderPlatforms,
@@ -203,7 +202,7 @@
 
     // these should be false
     assertEquals(styleSheetNode.equals(null), false);
-    assertEquals(styleSheetNode.equals(localesArray), false);
+    assertEquals(styleSheetNode.equals(localeSet), false);
     
     /* Test styleSheetNode's toString */
     /*