Author: jdonnerstag
Date: Fri Oct 23 19:58:02 2009
New Revision: 829194
URL: http://svn.apache.org/viewvc?rev=829194&view=rev
Log:
fixed Behavior for accepted locales should fit the HTTP Specification
Made MockHttpServletRequest.getLocales() to return all locales from
"Accept-Language" header
Issue: WICKET-2533
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/MockHttpServletRequest.java
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/MockHttpServletRequest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/MockHttpServletRequest.java?rev=829194&r1=829193&r2=829194&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/MockHttpServletRequest.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/MockHttpServletRequest.java
Fri Oct 23 19:58:02 2009
@@ -538,22 +538,20 @@
*/
public Locale getLocale()
{
- final String header = getHeader("Accept-Language");
- if (header == null)
- {
- return Locale.getDefault();
- }
-
- final String[] firstLocale = header.split(",");
- if (firstLocale.length < 1)
- {
- return Locale.getDefault();
- }
+ return getLocales().nextElement();
+ }
- final String[] bits = firstLocale[0].split("-");
+ /**
+ *
+ * @param value
+ * @return locale
+ */
+ private Locale getLocale(final String value)
+ {
+ final String[] bits = value.split("-");
if (bits.length < 1)
{
- return Locale.getDefault();
+ return null;
}
final String language = bits[0].toLowerCase();
@@ -575,8 +573,26 @@
*/
public Enumeration<Locale> getLocales()
{
- List<Locale> list = new ArrayList<Locale>(1);
- list.add(getLocale());
+ List<Locale> list = new ArrayList<Locale>();
+ final String header = getHeader("Accept-Language");
+ if (header != null)
+ {
+ final String[] locales = header.split(",");
+ for (String value : locales)
+ {
+ Locale locale = getLocale(value);
+ if (locale != null)
+ {
+ list.add(locale);
+ }
+ }
+ }
+
+ if (list.size() == 0)
+ {
+ list.add(Locale.getDefault());
+ }
+
return Collections.enumeration(list);
}