changeset 50:0b04fa8a19c6

Better implementation for fetching the preferred locale via meta of call context. artifacts/trunk@176 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 02 Oct 2009 10:02:15 +0000
parents 823850c63d95
children 3a668da76463
files Changelog artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultCallMeta.java
diffstat 2 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Changelog	Fri Oct 02 09:44:58 2009 +0000
+++ b/Changelog	Fri Oct 02 10:02:15 2009 +0000
@@ -1,3 +1,8 @@
+2009-10-02	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultCallMeta.java:
+	Better implementation for fetching the preferred locale.
+
 2009-10-02	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* artifacts/src/main/java/de/intevation/artifacts/CallMeta.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultCallMeta.java	Fri Oct 02 09:44:58 2009 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultCallMeta.java	Fri Oct 02 10:02:15 2009 +0000
@@ -28,7 +28,31 @@
             return null;
         }
 
-        return locales[0];
+        Locale best    = null;
+        float  quality = -Float.MAX_VALUE;
+
+        for (int i = 0; i < locales.length; ++i) {
+            Locale wish         = locales[i];
+            String wishLanguage = wish.getLanguage();
+
+            for (int j = 0; j < languages.length; ++j) {
+                PreferredLocale have        = languages[j];
+                Locale          haveLocale  = have.getLocale();
+                if (haveLocale.getLanguage().equals(wishLanguage)) {
+                    float haveQuality = have.getQuality();
+                    if (haveQuality > quality) {
+                        quality = haveQuality;
+                        best    = wish;
+                    }
+                    break; // Languages should not contain
+                           // same locale twice.
+                }
+            }
+        }
+
+        return best == null
+            ? locales[0]
+            : best;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org