X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=svjatoslav_commons.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fnetwork%2FLocaleConfiguration.java;h=7e5ee06c85571ae68a7e54af74170eb4bf87a005;hp=2bb15e2ce783f1e6839094950c5560c545b2230f;hb=9bf004ce4e9b5edff36c65fcc8cc0f303390d7fc;hpb=afaa928dd10304ee3e8e6bad3a377ced6a7b2f42 diff --git a/src/main/java/eu/svjatoslav/commons/network/LocaleConfiguration.java b/src/main/java/eu/svjatoslav/commons/network/LocaleConfiguration.java index 2bb15e2..7e5ee06 100755 --- a/src/main/java/eu/svjatoslav/commons/network/LocaleConfiguration.java +++ b/src/main/java/eu/svjatoslav/commons/network/LocaleConfiguration.java @@ -9,51 +9,49 @@ package eu.svjatoslav.commons.network; +import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.List; -import javax.servlet.http.HttpServletRequest; - public class LocaleConfiguration { - String defaultLocale; - - private final List allowedLocales = new ArrayList(); + final String defaultLocale; + private final List allowedLocales = new ArrayList<>(); - public LocaleConfiguration(final String defaultLocale, - final String... allowedLocales) { + public LocaleConfiguration(final String defaultLocale, + final String... allowedLocales) { - this.defaultLocale = defaultLocale; + this.defaultLocale = defaultLocale; - for (final String locale : allowedLocales) - getAllowedLocales().add(locale); - } + for (final String locale : allowedLocales) + getAllowedLocales().add(locale); + } - public String detectCurrentLocale(final HttpServletRequest request) { + public String detectCurrentLocale(final HttpServletRequest request) { - final String sessionLocaleString = (String) request.getSession() - .getAttribute("locale"); + final String sessionLocaleString = (String) request.getSession() + .getAttribute("locale"); - String result = defaultLocale; - if (isAllowedLocale(sessionLocaleString)) - result = sessionLocaleString; + String result = defaultLocale; + if (isAllowedLocale(sessionLocaleString)) + result = sessionLocaleString; - final String requestLocale = request.getParameter("locale"); + final String requestLocale = request.getParameter("locale"); - if (isAllowedLocale(requestLocale)) - result = requestLocale; + if (isAllowedLocale(requestLocale)) + result = requestLocale; - request.getSession().setAttribute("locale", result); + request.getSession().setAttribute("locale", result); - return result; - } + return result; + } - public List getAllowedLocales() { - return allowedLocales; - } + public List getAllowedLocales() { + return allowedLocales; + } - public boolean isAllowedLocale(final String locale) { - return allowedLocales.contains(locale); - } + public boolean isAllowedLocale(final String locale) { + return allowedLocales.contains(locale); + } }