Mercurial > dive4elements > framework
view artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultCallMeta.java @ 68:541814404822
Added interfaces for XML processing services. TODO: Implement them!
artifacts/trunk@593 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 22 Jan 2010 09:48:18 +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: