Mercurial > dive4elements > framework
view artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultCallMeta.java @ 62:76abf0c64d3b
Added XML utils method to load XML file from file.
artifacts/trunk@438 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 16 Dec 2009 08:08:56 +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: