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 2012/01/12 17:35:55 UTC
svn commit: r1230628 - in /myfaces/trinidad/branches/1.2.12.6.2-branch:
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/web...
Author: mcooper
Date: Thu Jan 12 16:35:54 2012
New Revision: 1230628
URL: http://svn.apache.org/viewvc?rev=1230628&view=rev
Log:
TRINIDAD-1041
Thanks to Anand Nath for the patch.
Added:
myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/localedemo/
myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/localedemo/localedemo.css
Modified:
myfaces/trinidad/branches/1.2.12.6.2-branch/src/site/xdoc/devguide/skinning.xml
myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-skins.xml
myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/demos/panelPageSkinDemo.jspx
myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java
myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java
myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java
myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java
myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java
Modified: myfaces/trinidad/branches/1.2.12.6.2-branch/src/site/xdoc/devguide/skinning.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.6.2-branch/src/site/xdoc/devguide/skinning.xml?rev=1230628&r1=1230627&r2=1230628&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.6.2-branch/src/site/xdoc/devguide/skinning.xml (original)
+++ myfaces/trinidad/branches/1.2.12.6.2-branch/src/site/xdoc/devguide/skinning.xml Thu Jan 12 16:35:54 2012
@@ -897,14 +897,19 @@ public class SkinTranslationMapDemo
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>:rtl</strong> - > pseudo-class to create a style or icon definition when the browser
+ <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
the right-to-left reading direction, then you want your image to be flipped. To do this,
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>
Modified: myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-skins.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-skins.xml?rev=1230628&r1=1230627&r2=1230628&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-skins.xml (original)
+++ myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-skins.xml Thu Jan 12 16:35:54 2012
@@ -124,4 +124,11 @@
<style-sheet-name>skins/accdemo/accdemo.css</style-sheet-name>
</skin>
-</skins>
+ <!-- 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/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/demos/panelPageSkinDemo.jspx
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/demos/panelPageSkinDemo.jspx?rev=1230628&r1=1230627&r2=1230628&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/demos/panelPageSkinDemo.jspx (original)
+++ myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/demos/panelPageSkinDemo.jspx Thu Jan 12 16:35:54 2012
@@ -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"/>
Added: myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/localedemo/localedemo.css
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/localedemo/localedemo.css?rev=1230628&view=auto
==============================================================================
--- myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/localedemo/localedemo.css (added)
+++ myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/localedemo/localedemo.css Thu Jan 12 16:35:54 2012
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+@locale en, de {
+ af|commandButton {
+ color: red;
+ }
+}
+
+@locale ro-RO {
+ af|commandButton {
+ color: blue;
+ }
+}
\ No newline at end of file
Modified: myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java?rev=1230628&r1=1230627&r2=1230628&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java (original)
+++ myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java Thu Jan 12 16:35:54 2012
@@ -21,10 +21,12 @@ package org.apache.myfaces.trinidadinter
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
@@ -113,6 +115,7 @@ public class SkinCSSDocumentHandler
CompleteSelectorNode node =
_createCompleteSelectorNode(selector,
_propertyNodeList,
+ _locales,
_selectorAgents,
_selectorPlatforms,
_getSelectorAccProperties());
@@ -190,6 +193,10 @@ public class SkinCSSDocumentHandler
{
_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);
@@ -205,8 +212,8 @@ public class SkinCSSDocumentHandler
*/
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 delimited 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);
@@ -229,6 +236,8 @@ public class SkinCSSDocumentHandler
_selectorAgents = 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());
@@ -243,6 +252,7 @@ public class SkinCSSDocumentHandler
private CompleteSelectorNode _createCompleteSelectorNode(
String selector,
List<PropertyNode> propertyNodeList,
+ Set<Locale> locales,
Map<Integer, AgentProperties> selectorAgentsProperties,
int[] selectorPlatforms,
Set<String> selectorAccProperties)
@@ -269,6 +279,7 @@ public class SkinCSSDocumentHandler
new CompleteSelectorNode(
selector,
propertyNodeList,
+ locales,
direction,
selectorAgentsProperties,
selectorPlatforms,
@@ -296,6 +307,7 @@ public class SkinCSSDocumentHandler
int direction = completeSelectorNode.getDirection();
Map<Integer, AgentProperties> agentsProperties = completeSelectorNode.getAgentsProperties();
int[] platforms = completeSelectorNode.getPlatforms();
+ Set<Locale> locales = completeSelectorNode.getLocales();
Set<String> accProperties = completeSelectorNode.getAccessibilityProperties();
// loop through the skinStyleSheetNodeList to find a match
@@ -307,7 +319,7 @@ public class SkinCSSDocumentHandler
for (int i = skinStyleSheetNodes.size() - 1; i >= 0 && !match; --i)
{
SkinStyleSheetNode ssNode = skinStyleSheetNodes.get(i);
- match = ssNode.matches(direction, agentsProperties, platforms, accProperties);
+ match = ssNode.matches(direction, agentsProperties, platforms, locales, accProperties);
if (match)
ssNode.add(completeSelectorNode.getSkinSelectorPropertiesNode());
}
@@ -316,7 +328,7 @@ public class SkinCSSDocumentHandler
{
// no matching stylesheet node found, so create a new one
SkinStyleSheetNode ssNode =
- new SkinStyleSheetNode(namespaceMap, direction, agentsProperties, platforms, accProperties);
+ new SkinStyleSheetNode(namespaceMap, direction, locales, agentsProperties, platforms, accProperties);
ssNode.add(completeSelectorNode.getSkinSelectorPropertiesNode());
skinStyleSheetNodes.add(ssNode);
}
@@ -327,7 +339,7 @@ public class SkinCSSDocumentHandler
/**
* 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(
@@ -362,6 +374,16 @@ public class SkinCSSDocumentHandler
_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
@@ -663,6 +685,7 @@ public class SkinCSSDocumentHandler
public CompleteSelectorNode(
String selectorName,
List<PropertyNode> propertyNodes,
+ Set<Locale> locales,
int direction,
Map<Integer, AgentProperties> agentsProperties,
int[] platforms,
@@ -673,12 +696,14 @@ public class SkinCSSDocumentHandler
_direction = direction;
// copy the agents and platforms because these get nulled out
// at the end of the @rule parsing.
- _agentsProperties = agentsProperties != null ?
+ _agentsProperties = (agentsProperties != null) ?
new HashMap<Integer, AgentProperties>(agentsProperties) :
new HashMap<Integer, AgentProperties>();
_platforms = _copyIntArray(platforms);
-
+ _locales = ((locales != null) ? new HashSet<Locale>(locales)
+ : Collections.<Locale>emptySet());
+
if (accProperties != null)
{
// Copy acc properties just to be safe. Note that we don't
@@ -711,6 +736,11 @@ public class SkinCSSDocumentHandler
return _platforms;
}
+ public Set<Locale> getLocales()
+ {
+ return _locales;
+ }
+
public Set<String> getAccessibilityProperties()
{
return _accProperties;
@@ -732,11 +762,13 @@ public class SkinCSSDocumentHandler
private int _direction; // the reading direction
private Map<Integer, AgentProperties> _agentsProperties;
private int[] _platforms;
+ private Set<Locale> _locales;
private Set<String> _accProperties;
}
private static String _AT_AGENT = "@agent";
private static String _AT_PLATFORM = "@platform";
+ private static final String _AT_LOCALE = "@locale";
private static String _AT_ACC_PROFILE = "@accessibility-profile";
// below are properties that we set and reset
@@ -755,7 +787,10 @@ public class SkinCSSDocumentHandler
// we store a map of agents and their properties. Agent properties
// are additional critera applied to selection (version, touchScreen).
private Map<Integer, AgentProperties> _selectorAgents = 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/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java?rev=1230628&r1=1230627&r2=1230628&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java (original)
+++ myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java Thu Jan 12 16:35:54 2012
@@ -21,6 +21,7 @@ package org.apache.myfaces.trinidadinter
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 @@ class SkinStyleSheetNode
List<SkinSelectorPropertiesNode> skinSelectorNodeList,
Map<String, String> namespaceMap,
int direction,
+ Set<Locale> locales,
Map<Integer, AgentProperties> agentsProperties,
Set<String> accProperties)
{
_skinSelectorNodeList = skinSelectorNodeList;
_namespaceMap = namespaceMap;
+ _locales = locales;
_direction = direction;
_agentsProperties = agentsProperties;
_accProperties = accProperties;
@@ -54,12 +57,14 @@ class SkinStyleSheetNode
SkinStyleSheetNode(
Map<String, String> namespaceMap,
int direction,
+ Set<Locale> locales,
Map<Integer, AgentProperties> agentsProperties,
int[] platforms,
Set<String> accProperties)
{
_namespaceMap = namespaceMap;
_direction = direction;
+ _locales = locales;
_agentsProperties = agentsProperties;
_platforms = platforms;
_accProperties = accProperties;
@@ -117,10 +122,16 @@ class SkinStyleSheetNode
return _accProperties;
}
+ public Set<Locale> getLocales()
+ {
+ return _locales;
+ }
+
public boolean matches(
int direction,
Map<Integer, AgentProperties> agentsProperties,
int[] platforms,
+ Set<Locale> locales,
Set<String> accProperties)
{
if (direction == _direction)
@@ -132,10 +143,13 @@ class SkinStyleSheetNode
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;
+ }
}
}
}
@@ -166,5 +180,6 @@ class SkinStyleSheetNode
private int _direction; // reading direction
private Map<Integer, AgentProperties> _agentsProperties;
private int[] _platforms;
+ private Set<Locale> _locales;
private Set<String> _accProperties;
}
Modified: myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java?rev=1230628&r1=1230627&r2=1230628&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java (original)
+++ myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java Thu Jan 12 16:35:54 2012
@@ -273,7 +273,7 @@ class SkinStyleSheetParserUtils
StyleSheetNode ssNode =
new StyleSheetNode(styleNodeArray,
iconNodeList,
- null,/*locales, not yet supported*/
+ skinSSNode.getLocales(),
skinSSNode.getDirection(),
skinSSNode.getAgentsProperties(),
skinSSNode.getPlatforms(),
Modified: myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java?rev=1230628&r1=1230627&r2=1230628&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java (original)
+++ myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java Thu Jan 12 16:35:54 2012
@@ -56,7 +56,7 @@ public class StyleSheetNode
public StyleSheetNode(
StyleNode[] styles,
Collection<IconNode> icons,
- Locale[] locales,
+ Set<Locale> locales,
int direction,
Map<Integer, AgentProperties> agentsProperties,
int[] platforms,
@@ -78,8 +78,7 @@ public class StyleSheetNode
// 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/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java?rev=1230628&r1=1230627&r2=1230628&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java (original)
+++ myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java Thu Jan 12 16:35:54 2012
@@ -39,6 +39,7 @@ import org.apache.myfaces.trinidadintern
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;
@@ -155,23 +156,6 @@ public class StyleSheetNodeParser extend
}
}
- // 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)
{
@@ -180,20 +164,16 @@ public class StyleSheetNodeParser extend
// -= 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);
}
}
@@ -323,7 +303,7 @@ public class StyleSheetNodeParser extend
// -= 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 int[] _browsers;
Modified: myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java?rev=1230628&r1=1230627&r2=1230628&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java (original)
+++ myfaces/trinidad/branches/1.2.12.6.2-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java Thu Jan 12 16:35:54 2012
@@ -130,10 +130,9 @@ public class StyleSheetNodeEqualsTest ex
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
Map<Integer, AgentProperties> browsers = new HashMap<Integer, AgentProperties>();
browsers.put(1, new AgentProperties(new HashSet<Version>(Arrays.asList(new Version("5"), new Version("6"))), Collections.<String>emptySet()));
@@ -167,7 +166,7 @@ public class StyleSheetNodeEqualsTest ex
StyleSheetNode styleSheetNode =
new StyleSheetNode(styleSheetOneNodes,
iconNodes,
- localesArray,
+ localeSet,
0,
browsers,
platforms,
@@ -176,7 +175,7 @@ public class StyleSheetNodeEqualsTest ex
StyleSheetNode anotherStyleSheetNode =
new StyleSheetNode(anotherStyleSheetOneNodes,
anotherIconNodes,
- anotherLocalesArray,
+ localeSet,
0,
anotherBrowsersDiffOrder,
anotherPlatforms,
@@ -185,7 +184,7 @@ public class StyleSheetNodeEqualsTest ex
StyleSheetNode sameDiffOrderStyleSheetNode =
new StyleSheetNode(anotherStyleSheetOneNodes,
anotherIconNodes,
- diffOrderLocalesArray,
+ diffOrderLocalesSet,
0,
anotherBrowsersDiffOrder,
differentOrderPlatforms,
@@ -209,7 +208,7 @@ public class StyleSheetNodeEqualsTest ex
// these should be false
assertEquals(styleSheetNode.equals(null), false);
- assertEquals(styleSheetNode.equals(localesArray), false);
+ assertEquals(styleSheetNode.equals(localeSet), false);
/* Test styleSheetNode's toString */
/*
@@ -305,23 +304,6 @@ public class StyleSheetNodeEqualsTest ex
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")};
- }
-
private List<IconNode> _getIconNodes()
{
List<IconNode> iconNodes = new ArrayList<IconNode>(2);