Java Code Examples for java.util.Locale#filter()

The following examples show how to use java.util.Locale#filter() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public Locale resolve(LocaleResolverContext context) {
    Optional<List<LanguageRange>> localePriorities = getAcceptableLanguages();
    if (!localePriorities.isPresent()) {
        return context.getDefaultLocale();

    List<Locale> resolvedLocales = Locale.filter(localePriorities.get(), context.getSupportedLocales());
    if (resolvedLocales.size() > 0) {
        return resolvedLocales.get(0);

    return context.getDefaultLocale();
Example 2
Source Project: syncope   File:    License: Apache License 2.0 4 votes vote down vote up
LocaleDropDown(final String id) {
    super(id, getSupportedLocales());

    setChoiceRenderer(new LocaleRenderer());
    setModel(new IModel<Locale>() {

        private static final long serialVersionUID = -6985170095629312963L;

        public Locale getObject() {
            return getSession().getLocale();

        public void setObject(final Locale object) {

        public void detach() {
            // Empty.

    // set default language selection
    List<Locale> filtered = List.of();

    String acceptLanguage = ((ServletWebRequest) RequestCycle.get().getRequest()).
    if (StringUtils.isNotBlank(acceptLanguage)) {
        try {
            filtered = Locale.filter(Locale.LanguageRange.parse(acceptLanguage), getSupportedLocales());
        } catch (Exception e) {
            LOG.debug("Could not parse {} HTTP header value '{}'",
                    HttpHeaders.ACCEPT_LANGUAGE, acceptLanguage, e);

            ? Locale.ENGLISH
            : filtered.get(0));