You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2016/12/01 19:06:52 UTC

[4/8] struts git commit: WW-4722 Extracts logic to store locale in cookie into a method

WW-4722 Extracts logic to store locale in cookie into a method


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/8971b508
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/8971b508
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/8971b508

Branch: refs/heads/master
Commit: 8971b5081055bd309f715aad63fd96825154c3f8
Parents: 6457f00
Author: Lukasz Lenart <lu...@apache.org>
Authored: Thu Dec 1 17:25:33 2016 +0100
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Thu Dec 1 17:25:33 2016 +0100

----------------------------------------------------------------------
 .../struts2/interceptor/I18nInterceptor.java    | 28 +++++++++++++-------
 1 file changed, 19 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/8971b508/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java
index 02409c4..cfed10a 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java
@@ -234,20 +234,18 @@ public class I18nInterceptor extends AbstractInterceptor {
      */
     protected Locale readStoredLocale(ActionInvocation invocation, Map<String, Object> session) {
         Locale locale = this.readStoredLocalFromSession(invocation, session);
-
         if (locale != null) {
+            LOG.debug("Found stored Locale {} in session, using it!", locale);
             return locale;
         }
 
-        Cookie[] cookies = ServletActionContext.getRequest().getCookies();
-        if (cookies != null) {
-            for (Cookie cookie : cookies) {
-                if (DEFAULT_COOKIE_ATTRIBUTE.equals(cookie.getName())) {
-                    return getLocaleFromParam(cookie.getValue());
-                }
-            }
+        Locale cookie = readStoredLocaleFromCookie(invocation);
+        if (cookie != null) {
+            LOG.debug("Found stored Locale {} in cookies, using it!", locale);
+            return cookie;
         }
 
+        LOG.debug("Neither locale was in session nor in cookies, searching current Invocation context");
         return this.readStoredLocalFromCurrentInvocation(invocation);
     }
 
@@ -283,7 +281,7 @@ public class I18nInterceptor extends AbstractInterceptor {
         return locale;
     }
 
-    protected Locale readStoredLocalFromSession(ActionInvocation invocation, Map<String, Object> session) {
+    protected Locale readStoredLocalFromSession(ActionInvocation ignore, Map<String, Object> session) {
         // check session for saved locale
         Object sessionLocale = session.get(attributeName);
         if (sessionLocale != null && sessionLocale instanceof Locale) {
@@ -294,6 +292,18 @@ public class I18nInterceptor extends AbstractInterceptor {
         return null;
     }
 
+    protected Locale readStoredLocaleFromCookie(ActionInvocation ignore) {
+        Cookie[] cookies = ServletActionContext.getRequest().getCookies();
+        if (cookies != null) {
+            for (Cookie cookie : cookies) {
+                if (DEFAULT_COOKIE_ATTRIBUTE.equals(cookie.getName())) {
+                    return getLocaleFromParam(cookie.getValue());
+                }
+            }
+        }
+        return null;
+    }
+
     protected Locale readStoredLocalFromCurrentInvocation(ActionInvocation invocation) {
         // no overriding locale definition found, stay with current invocation (=browser) locale
         Locale locale = invocation.getInvocationContext().getLocale();