projects
/
svjatoslav_commons.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Make terminator details immutable and public.
[svjatoslav_commons.git]
/
src
/
main
/
java
/
eu
/
svjatoslav
/
commons
/
network
/
LocaleConfiguration.java
diff --git
a/src/main/java/eu/svjatoslav/commons/network/LocaleConfiguration.java
b/src/main/java/eu/svjatoslav/commons/network/LocaleConfiguration.java
index
2230885
..
447f530
100755
(executable)
--- a/
src/main/java/eu/svjatoslav/commons/network/LocaleConfiguration.java
+++ b/
src/main/java/eu/svjatoslav/commons/network/LocaleConfiguration.java
@@
-1,6
+1,6
@@
/*
* Svjatoslav Commons - shared library of common functionality.
/*
* Svjatoslav Commons - shared library of common functionality.
- * Copyright ©2012-201
4
, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-201
7
, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 3 of the GNU Lesser General Public License
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 3 of the GNU Lesser General Public License
@@
-9,55
+9,49
@@
package eu.svjatoslav.commons.network;
package eu.svjatoslav.commons.network;
+import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.ArrayList;
import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-
public class LocaleConfiguration {
public class LocaleConfiguration {
- Locale defaultLocale;
-
- private final List<Locale> allowedLocales = new ArrayList<Locale>();
+ final String defaultLocale;
+ private final List<String> allowedLocales = new ArrayList<>();
-
public LocaleConfiguration(final Locale
defaultLocale,
-
final Locale
... allowedLocales) {
+
public LocaleConfiguration(final String
defaultLocale,
+
final String
... allowedLocales) {
-
this.defaultLocale = defaultLocale;
+ this.defaultLocale = defaultLocale;
-
for (final Locale
locale : allowedLocales)
-
this.
getAllowedLocales().add(locale);
-
}
+
for (final String
locale : allowedLocales)
+ getAllowedLocales().add(locale);
+ }
-
public Locale
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");
-
Locale result = localeFromString(sessionLocaleString)
;
-
if (result == null
)
-
result = defaultLocale
;
+
String result = defaultLocale
;
+
if (isAllowedLocale(sessionLocaleString)
)
+
result = sessionLocaleString
;
- final Locale requestLocale = localeFromString(request
- .getParameter("locale"));
- if (requestLocale != null)
- result = requestLocale;
+ final String requestLocale = request.getParameter("locale");
- request.getSession().setAttribute("locale", result.asString());
+ if (isAllowedLocale(requestLocale))
+ result = requestLocale;
- return result;
- }
+ request.getSession().setAttribute("locale", result);
- private Locale localeFromString(final String localeString) {
- for (final Locale locale : getAllowedLocales())
- if (locale.asString().equals(localeString))
- return locale;
+ return result;
+ }
- return null;
- }
+ public List<String> getAllowedLocales() {
+ return allowedLocales;
+ }
-
public List<Locale> getAllowedLocales(
) {
-
return allowedLocales
;
-
}
+
public boolean isAllowedLocale(final String locale
) {
+
return allowedLocales.contains(locale)
;
+ }
}
}