javax.mvc.locale.LocaleResolverContext Java Examples
The following examples show how to use
javax.mvc.locale.LocaleResolverContext.
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: DefaultLocaleResolver.java From krazo with Apache License 2.0 | 6 votes |
@Override public Locale resolveLocale(LocaleResolverContext context) { // Prefer language from "Accept-Language" header Locale clientLocale = context.getAcceptableLanguages().stream() .filter(l -> !"*".equals(l.getLanguage())) .findFirst() .orElse(null); if (clientLocale != null) { return clientLocale; } // Fallback to system default locale return Locale.getDefault(); }
Example #2
Source File: DefaultLocaleResolver.java From ozark with Apache License 2.0 | 6 votes |
@Override public Locale resolveLocale(LocaleResolverContext context) { // Prefer language from "Accept-Language" header Locale clientLocale = context.getAcceptableLanguages().stream() .filter(l -> !"*".equals(l.getLanguage())) .findFirst() .orElse(null); if (clientLocale != null) { return clientLocale; } // Fallback to system default locale return Locale.getDefault(); }
Example #3
Source File: QueryLocaleResolver.java From krazo with Apache License 2.0 | 5 votes |
@Override public Locale resolveLocale(LocaleResolverContext context) { List<String> lang = context.getUriInfo().getQueryParameters().get("lang"); if (lang != null && !lang.isEmpty()) { return new Locale(lang.get(0)); } return null; }
Example #4
Source File: QueryLocaleResolver.java From krazo with Apache License 2.0 | 5 votes |
@Override public Locale resolveLocale(LocaleResolverContext context) { List<String> lang = context.getUriInfo().getQueryParameters().get("lang"); if (lang != null && !lang.isEmpty()) { return new Locale(lang.get(0)); } return null; }
Example #5
Source File: LocaleResolverChain.java From krazo with Apache License 2.0 | 5 votes |
public Locale resolve(ContainerRequestContext requestContext) { // prepare context instance LocaleResolverContext context = new LocaleResolverContextImpl(configuration, requestContext); List<LocaleResolver> resolvers = CdiUtils.getApplicationBeans(LocaleResolver.class); // candidates as sorted list List<LocaleResolver> candidates = StreamSupport.stream(resolvers.spliterator(), false) .sorted((resolver1, resolver2) -> { final Priority prio1 = getAnnotation(resolver1.getClass(), Priority.class); final Priority prio2 = getAnnotation(resolver2.getClass(), Priority.class); final int value1 = prio1 != null ? prio1.value() : 1000; final int value2 = prio2 != null ? prio2.value() : 1000; return value2 - value1; }) .collect(Collectors.toList()); // do the resolving for (LocaleResolver candidate : candidates) { Locale locale = candidate.resolveLocale(context); if (locale != null) { return locale; } } throw new IllegalStateException("Could not resolve locale with any of the " + candidates.size() + " resolver implementations"); }
Example #6
Source File: QueryLocaleResolver.java From ozark with Apache License 2.0 | 5 votes |
@Override public Locale resolveLocale(LocaleResolverContext context) { List<String> lang = context.getUriInfo().getQueryParameters().get("lang"); if (lang != null && !lang.isEmpty()) { return new Locale(lang.get(0)); } return null; }
Example #7
Source File: QueryLocaleResolver.java From ozark with Apache License 2.0 | 5 votes |
@Override public Locale resolveLocale(LocaleResolverContext context) { List<String> lang = context.getUriInfo().getQueryParameters().get("lang"); if (lang != null && !lang.isEmpty()) { return new Locale(lang.get(0)); } return null; }
Example #8
Source File: LocaleResolverChain.java From ozark with Apache License 2.0 | 5 votes |
public Locale resolve(ContainerRequestContext requestContext) { // prepare context instance LocaleResolverContext context = new LocaleResolverContextImpl(configuration, requestContext); List<LocaleResolver> resolvers = CdiUtils.getApplicationBeans(LocaleResolver.class); // candidates as sorted list List<LocaleResolver> candidates = StreamSupport.stream(resolvers.spliterator(), false) .sorted((resolver1, resolver2) -> { final Priority prio1 = getAnnotation(resolver1.getClass(), Priority.class); final Priority prio2 = getAnnotation(resolver2.getClass(), Priority.class); final int value1 = prio1 != null ? prio1.value() : 1000; final int value2 = prio2 != null ? prio2.value() : 1000; return value2 - value1; }) .collect(Collectors.toList()); // do the resolving for (LocaleResolver candidate : candidates) { Locale locale = candidate.resolveLocale(context); if (locale != null) { return locale; } } throw new IllegalStateException("Could not resolve locale with any of the " + candidates.size() + " resolver implementations"); }
Example #9
Source File: LocaleResolverImpl.java From portals-pluto with Apache License 2.0 | 5 votes |
@Override public Locale resolveLocale(LocaleResolverContext localeResolverContext) { List<Locale> acceptableLanguages = localeResolverContext.getAcceptableLanguages(); for (Locale acceptableLanguage : acceptableLanguages) { if (!Objects.equals(acceptableLanguage.getLanguage(), "*")) { return acceptableLanguage; } } return Locale.getDefault(); }