sascha@48: package de.intevation.artifactdatabase; sascha@48: sascha@49: import java.util.Locale; sascha@49: sascha@48: import de.intevation.artifacts.CallMeta; sascha@48: import de.intevation.artifacts.PreferredLocale; sascha@48: sascha@48: /** sascha@48: * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) sascha@48: */ sascha@48: public class DefaultCallMeta sascha@48: implements CallMeta sascha@48: { sascha@48: protected PreferredLocale [] languages; sascha@48: sascha@48: public DefaultCallMeta() { sascha@48: } sascha@48: sascha@48: public DefaultCallMeta(PreferredLocale [] languages) { sascha@51: this.languages = languages; sascha@48: } sascha@48: sascha@48: public PreferredLocale [] getLanguages() { sascha@48: return languages; sascha@48: } sascha@49: sascha@49: public Locale getPreferredLocale(Locale [] locales) { sascha@49: if (locales == null || locales.length == 0) { sascha@49: return null; sascha@49: } sascha@49: sascha@50: Locale best = null; sascha@50: float quality = -Float.MAX_VALUE; sascha@50: sascha@50: for (int i = 0; i < locales.length; ++i) { sascha@50: Locale wish = locales[i]; sascha@50: String wishLanguage = wish.getLanguage(); sascha@50: sascha@50: for (int j = 0; j < languages.length; ++j) { sascha@50: PreferredLocale have = languages[j]; sascha@50: Locale haveLocale = have.getLocale(); sascha@50: if (haveLocale.getLanguage().equals(wishLanguage)) { sascha@50: float haveQuality = have.getQuality(); sascha@50: if (haveQuality > quality) { sascha@50: quality = haveQuality; sascha@50: best = wish; sascha@50: } sascha@50: break; // Languages should not contain sascha@50: // same locale twice. sascha@50: } sascha@50: } sascha@50: } sascha@50: sascha@50: return best == null sascha@50: ? locales[0] sascha@50: : best; sascha@49: } sascha@48: } sascha@48: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: