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

The following examples show how to use java.util.Locale#filter() . 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
Source File: ResteasyContextLocaleResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
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 File: BaseLogin.java    From syncope with 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;

        @Override
        public Locale getObject() {
            return getSession().getLocale();
        }

        @Override
        public void setObject(final Locale object) {
            getSession().setLocale(object);
        }

        @Override
        public void detach() {
            // Empty.
        }
    });

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

    String acceptLanguage = ((ServletWebRequest) RequestCycle.get().getRequest()).
            getHeader(HttpHeaders.ACCEPT_LANGUAGE);
    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);
        }
    }

    getModel().setObject(filtered.isEmpty()
            ? Locale.ENGLISH
            : filtered.get(0));
}