Mercurial > dive4elements > framework
view artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultCallMeta.java @ 70:ce488c1d3fc4
Serve services over artifact database.
artifacts/trunk@597 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 22 Jan 2010 11:08:40 +0000 |
parents | 3a668da76463 |
children | 48d1a9a082c2 |
line wrap: on
line source
package de.intevation.artifactdatabase; import java.util.Locale; import de.intevation.artifacts.CallMeta; import de.intevation.artifacts.PreferredLocale; /** * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) */ public class DefaultCallMeta implements CallMeta { protected PreferredLocale [] languages; public DefaultCallMeta() { } public DefaultCallMeta(PreferredLocale [] languages) { this.languages = languages; } public PreferredLocale [] getLanguages() { return languages; } public Locale getPreferredLocale(Locale [] locales) { if (locales == null || locales.length == 0) { return null; } 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: