-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.svjatoslav</groupId>
<artifactId>svjatoslavcommons</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<distributionManagement>
<repository>
<id>svjatoslav.eu</id>
<name>svjatoslav.eu</name>
- <url>scp://svjatoslav.eu/var/www/svjatoslav.eu/maven</url>
+ <url>scp://svjatoslav.eu/var/www/svjatoslav.eu/maven</url>
</repository>
</distributionManagement>
--- /dev/null
+package eu.svjatoslav.commons.network;
+
+public enum Locale {
+ ENG("eng"), EST("est"), RUS("rus");
+
+ String asString;
+
+ Locale(final String asString) {
+ this.asString = asString;
+ }
+
+ public String asString() {
+ return asString;
+ }
+
+}
--- /dev/null
+package eu.svjatoslav.commons.network;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class LocaleHelper {
+
+ public static Locale detectLocale(final HttpServletRequest request) {
+
+ final String sessionLocaleString = (String) request.getSession().getAttribute("locale");
+
+ Locale sessionLocale = localeFromString(sessionLocaleString);
+ if (sessionLocale == null) {
+ sessionLocale = Locale.ENG;
+ }
+
+ final Locale requestLocale = localeFromString(request.getParameter("locale"));
+ if (requestLocale != null) {
+ sessionLocale = requestLocale;
+ }
+
+ request.getSession().setAttribute("locale", sessionLocale.asString());
+
+ return sessionLocale;
+ }
+
+ public static Locale localeFromString(final String localeString) {
+ for (final Locale locale : Locale.values()) {
+ if (locale.asString().equals(localeString)) {
+ return locale;
+ }
+ }
+
+ return null;
+ }
+
+}