Author: simoneg
Date: Fri Jul 10 16:33:29 2009
New Revision: 793024
URL: http://svn.apache.org/viewvc?rev=793024&view=rev
Log:
LABS-387 : use a session parameter overriding the default borwser header for
locale
Modified:
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/i18n/Localizer.aj
labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/DefaultExpectations.java
Modified:
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/i18n/Localizer.aj
URL:
http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/i18n/Localizer.aj?rev=793024&r1=793023&r2=793024&view=diff
==============================================================================
---
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/i18n/Localizer.aj
(original)
+++
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/i18n/Localizer.aj
Fri Jul 10 16:33:29 2009
@@ -3,6 +3,7 @@
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
import org.apache.magma.i18n.CurrentLocale;
import org.apache.magma.website.Dispatch;
@@ -11,6 +12,20 @@
before(HttpServletRequest req) : execution(void
Dispatch.handle(HttpServletRequest, ..)) && args(req,..) {
Locale locale = req.getLocale();
+ HttpSession session = req.getSession(false);
+ if (session != null) {
+ String sessLocale =
(String)session.getAttribute("magma_locale");
+ if (sessLocale != null) {
+ String[] localeElements = sessLocale.split("_");
+ if (localeElements.length == 1) {
+ locale = new Locale(localeElements[0]);
+ } else if (localeElements.length == 2) {
+ locale = new Locale(localeElements[0],
localeElements[1]);
+ } else if (localeElements.length == 3) {
+ locale = new Locale(localeElements[0],
localeElements[1], localeElements[2]);
+ }
+ }
+ }
CurrentLocale.setLocale(locale);
}
Modified:
labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/DefaultExpectations.java
URL:
http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/DefaultExpectations.java?rev=793024&r1=793023&r2=793024&view=diff
==============================================================================
---
labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/DefaultExpectations.java
(original)
+++
labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/DefaultExpectations.java
Fri Jul 10 16:33:29 2009
@@ -44,10 +44,12 @@
atMost(1).of(req).getRequestURL(); will(returnValue(new
StringBuffer("http://localhost/app/tests" + path)));
allowing(req).getSession(); will(returnValue(session));
allowing(req).getSession(true); will(returnValue(session));
+ allowing(req).getSession(false); will(returnValue(session));
allowing(req).getCookies(); will(returnValue(cookies));
allowing(req).getAttribute("cookieInvalidloggedIn");
will(returnValue(null));
one(req).setAttribute("__magma_url",path);
allowing(req).getAttribute("__magma_url");
will(returnValue(path));
+ allowing(session).getAttribute("magma_locale");
will(returnValue(null));
atMost(1).of(session).getAttribute("__magma_lastmain");
will(returnValue(null));
atMost(1).of(session).getAttribute("__magma_lasttemplate");
will(returnValue(null));
allowing(session).setAttribute(with(equal("__magma_lasttemplate")),
with(any(Class.class)));
@@ -74,8 +76,10 @@
allowing(req).getRequestURL(); will(returnValue(new
StringBuffer("http://localhost/app/tests" + path)));
allowing(req).getSession(); will(returnValue(session));
allowing(req).getSession(true); will(returnValue(session));
+ allowing(req).getSession(false); will(returnValue(session));
allowing(req).getAttribute("__magma_url");
will(returnValue(path));
one(req).setAttribute("__magma_url",path);
+ allowing(session).getAttribute("magma_locale");
will(returnValue(null));
atMost(1).of(session).getAttribute("__magma_lastmain");
will(returnValue(null));
atMost(1).of(session).getAttribute("__magma_lasttemplate");
will(returnValue(null));
allowing(session).setAttribute(with(equal("__magma_lasttemplate")),
with(any(Class.class)));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]