cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6640] Fixing a locale issue
Date Thu, 15 Oct 2015 16:36:33 GMT
Repository: cxf
Updated Branches:
  refs/heads/master f456dd41b -> a1d59ed7a


[CXF-6640] Fixing a locale issue


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a1d59ed7
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a1d59ed7
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a1d59ed7

Branch: refs/heads/master
Commit: a1d59ed7af2a7db38d885f52034d2c79b4da332a
Parents: f456dd4
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Oct 15 17:36:17 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Oct 15 17:36:17 2015 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/jaxrs/utils/HttpUtils.java   | 21 ++++++++++++++------
 .../cxf/jaxrs/impl/HttpHeadersImplTest.java     |  9 +++++----
 2 files changed, 20 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a1d59ed7/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
index 76c66e9..c6c8dc1 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
@@ -275,15 +275,24 @@ public final class HttpUtils {
         if (value == null) {
             return null;
         }
-        
-        String[] values = StringUtils.split(value, "-");
-        if (values.length == 0 || values.length > 2) {
+        String language = null;
+        String locale = null;
+        int index = value.indexOf('-');
+        if (index == 0 || index == value.length() - 1) {
             throw new IllegalArgumentException("Illegal locale value : " + value);
         }
-        if (values.length == 1) {
-            return new Locale(values[0]);
+        
+        if (index > 0) {
+            language = value.substring(0, index);
+            locale = value.substring(index + 1);
+        } else {
+            language = value;
+        }
+        
+        if (locale == null) {
+            return new Locale(language);
         } else {
-            return new Locale(values[0], values[1]);
+            return new Locale(language, locale);
         }
         
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/a1d59ed7/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
index c072021..c82af5d 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
@@ -462,15 +462,16 @@ public class HttpHeadersImplTest extends Assert {
         m.get(Message.PROTOCOL_HEADERS);
         MetadataMap<String, String> headers = 
             createHeader(HttpHeaders.ACCEPT_LANGUAGE, 
-                         "en;q=0.7, en-gb;q=0.8, da");
+                         "en;q=0.7, en-gb;q=0.8, da, zh-Hans-SG;q=0.9");
         EasyMock.expectLastCall().andReturn(headers);
         control.replay();
         HttpHeaders h = new HttpHeadersImpl(m);
         List<Locale> languages = h.getAcceptableLanguages();
-        assertEquals(3, languages.size());
+        assertEquals(4, languages.size());
         assertEquals(new Locale("da"), languages.get(0));
-        assertEquals(new Locale("en", "GB"), languages.get(1));
-        assertEquals(new Locale("en"), languages.get(2));
+        assertEquals(new Locale("zh", "Hans-SG"), languages.get(1));
+        assertEquals(new Locale("en", "GB"), languages.get(2));
+        assertEquals(new Locale("en"), languages.get(3));
     }
     
         


Mime
View raw message