Author: trong.tran
Date: 2010-08-12 08:29:15 -0400 (Thu, 12 Aug 2010)
New Revision: 3811
Added:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java
Modified:
portal/branches/branched-r3776/web/portal/src/main/webapp/WEB-INF/web.xml
Log:
GTNPORTAL-1355 Locale is not set correctly in login form when login failed
Modified: portal/branches/branched-r3776/web/portal/src/main/webapp/WEB-INF/web.xml
===================================================================
--- portal/branches/branched-r3776/web/portal/src/main/webapp/WEB-INF/web.xml 2010-08-12
07:43:42 UTC (rev 3810)
+++ portal/branches/branched-r3776/web/portal/src/main/webapp/WEB-INF/web.xml 2010-08-12
12:29:15 UTC (rev 3811)
@@ -1,19 +1,19 @@
-<?xml version="1.0" encoding="ISO-8859-1" ?>
+<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
Copyright (C) 2009 eXo Platform SAS.
-
+
This is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
-
+
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public
License along with this software; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
@@ -21,9 +21,11 @@
-->
-<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN"
- "http://java.sun.com/dtd/web-app_2_3.dtd">
-<web-app>
+<web-app
xmlns="http://java.sun.com/xml/ns/j2ee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ version="2.4">
<display-name>portal</display-name>
<!--Uncomment for clustered setup-->
@@ -34,31 +36,33 @@
<context-param>
<param-name>org.exoplatform.frameworks.jcr.command.web.fckeditor.digitalAssetsWorkspace</param-name>
<param-value>portal</param-value>
- <description>Binary assets workspace name</description>
</context-param>
<context-param>
<param-name>org.exoplatform.frameworks.jcr.command.web.fckeditor.digitalAssetsPath</param-name>
<param-value>/</param-value>
- <description>Binary assets path</description>
</context-param>
-
+
<!-- ================================================================== -->
<!-- RESOURCE FILTER TO CACHE MERGED JAVASCRIPT AND CSS -->
<!-- ================================================================== -->
+ <filter>
+ <filter-name>LocalizationFilter</filter-name>
+ <filter-class>org.exoplatform.portal.application.localization.LocalizationFilter</filter-class>
+ </filter>
<filter>
<filter-name>GenericFilter</filter-name>
<filter-class>org.exoplatform.web.filter.GenericFilter</filter-class>
</filter>
<filter>
- <filter-name>ResourceRequestFilter</filter-name>
-
<filter-class>org.exoplatform.portal.application.ResourceRequestFilter</filter-class>
+ <filter-name>ResourceRequestFilter</filter-name>
+
<filter-class>org.exoplatform.portal.application.ResourceRequestFilter</filter-class>
</filter>
-
+
<filter>
<filter-name>ThreadLocalSessionProviderInitializedFilter</filter-name>
<filter-class>org.exoplatform.frameworks.jcr.web.ThreadLocalSessionProviderInitializedFilter</filter-class>
- </filter>
+ </filter>
<filter>
<filter-name>SetCurrentIdentityFilter</filter-name>
@@ -66,17 +70,17 @@
</filter>
-
- <filter>
- <filter-name>RestEncodingFilter</filter-name>
-
<filter-class>org.exoplatform.services.rest.servlet.RestEncodingFilter</filter-class>
- <init-param>
- <param-name>REQUEST_ENCODING</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- </filter>
<filter>
+ <filter-name>RestEncodingFilter</filter-name>
+
<filter-class>org.exoplatform.services.rest.servlet.RestEncodingFilter</filter-class>
+ <init-param>
+ <param-name>REQUEST_ENCODING</param-name>
+ <param-value>UTF-8</param-value>
+ </init-param>
+ </filter>
+
+ <filter>
<filter-name>CacheUserProfileFilter</filter-name>
<filter-class>org.exoplatform.web.CacheUserProfileFilter</filter-class>
</filter>
@@ -101,6 +105,15 @@
<url-pattern>/*</url-pattern>
</filter-mapping>
+ <filter-mapping>
+ <filter-name>LocalizationFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ <dispatcher>INCLUDE</dispatcher>
+ <dispatcher>FORWARD</dispatcher>
+ <dispatcher>REQUEST</dispatcher>
+ <dispatcher>ERROR</dispatcher>
+ </filter-mapping>
+
<filter-mapping>
<filter-name>GenericFilter</filter-name>
<url-pattern>/*</url-pattern>
@@ -108,29 +121,29 @@
<filter-mapping>
<filter-name>ResourceRequestFilter</filter-name>
- <url-pattern>*.css</url-pattern>
+ <url-pattern>*.css</url-pattern>
</filter-mapping>
-
+
<filter-mapping>
<filter-name>ResourceRequestFilter</filter-name>
- <url-pattern>*.gif</url-pattern>
+ <url-pattern>*.gif</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ResourceRequestFilter</filter-name>
- <url-pattern>*.png</url-pattern>
+ <url-pattern>*.png</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ResourceRequestFilter</filter-name>
- <url-pattern>*.jpg</url-pattern>
+ <url-pattern>*.jpg</url-pattern>
</filter-mapping>
<filter-mapping>
- <filter-name>ResourceRequestFilter</filter-name>
- <url-pattern>/javascript/*</url-pattern>
+ <filter-name>ResourceRequestFilter</filter-name>
+ <url-pattern>/javascript/*</url-pattern>
</filter-mapping>
-
+
<filter-mapping>
<filter-name>SetCurrentIdentityFilter</filter-name>
<url-pattern>/*</url-pattern>
@@ -140,12 +153,12 @@
<filter-name>ThreadLocalSessionProviderInitializedFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-
+
<filter-mapping>
<filter-name>CacheUserProfileFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-
+
<filter-mapping>
<filter-name>RestEncodingFilter</filter-name>
<url-pattern>/rest/*</url-pattern>
@@ -158,36 +171,35 @@
<listener-class>org.exoplatform.web.GenericHttpListener</listener-class>
</listener>
<listener>
-
<listener-class>org.exoplatform.portal.application.PortalSessionListener</listener-class>
+
<listener-class>org.exoplatform.portal.application.PortalSessionListener</listener-class>
</listener>
<listener>
<listener-class>org.exoplatform.services.security.web.JAASConversationStateListener</listener-class>
- </listener>
+ </listener>
<!-- ================================================================== -->
<!-- SERVLET -->
- <!-- ================================================================== -->
+ <!-- ================================================================== -->
<servlet>
- <servlet-name>portal</servlet-name>
-
<servlet-class>org.exoplatform.portal.application.PortalController</servlet-class>
+ <servlet-name>portal</servlet-name>
+
<servlet-class>org.exoplatform.portal.application.PortalController</servlet-class>
<init-param>
- <param-name>webui.configuration</param-name>
- <param-value>app:/WEB-INF/webui-configuration.xml</param-value>
+ <param-name>webui.configuration</param-name>
+ <param-value>app:/WEB-INF/webui-configuration.xml</param-value>
</init-param>
- <load-on-startup>1</load-on-startup>
+ <load-on-startup>1</load-on-startup>
</servlet>
-
+
<servlet>
<servlet-name>RestServer</servlet-name>
- <description>eXo - Platform REST Server</description>
<servlet-class>org.exoplatform.services.rest.servlet.RestServlet</servlet-class>
<load-on-startup>4</load-on-startup>
</servlet>
-
+
<servlet>
- <servlet-name>javascript</servlet-name>
-
<servlet-class>org.exoplatform.portal.webui.javascript.JavascriptServlet</servlet-class>
+ <servlet-name>javascript</servlet-name>
+
<servlet-class>org.exoplatform.portal.webui.javascript.JavascriptServlet</servlet-class>
</servlet>
-
+
<servlet>
<servlet-name>Controller</servlet-name>
<servlet-class>org.exoplatform.frameworks.jcr.web.CommandControllerServlet</servlet-class>
@@ -232,114 +244,114 @@
</servlet-mapping>
- <!-- ================================================================= -->
+ <!-- ================================================================= -->
<servlet-mapping>
- <servlet-name>InitiateLoginServlet</servlet-name>
- <url-pattern>/initiatelogin</url-pattern>
+ <servlet-name>InitiateLoginServlet</servlet-name>
+ <url-pattern>/initiatelogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ErrorLoginServlet</servlet-name>
<url-pattern>/errorlogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>PortalLoginController</servlet-name>
- <url-pattern>/login</url-pattern>
+ <servlet-name>PortalLoginController</servlet-name>
+ <url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>javascript</servlet-name>
- <url-pattern>/javascript/*</url-pattern>
+ <servlet-name>javascript</servlet-name>
+ <url-pattern>/javascript/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/private/*</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/private/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/public/*</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/public/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/admin/*</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/admin/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/service</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/service</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/upload/*</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/upload/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/download/*</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/download/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RestServer</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
-
+
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/connector</url-pattern>
- </servlet-mapping>
-
+ </servlet-mapping>
+
<servlet-mapping>
<servlet-name>GateInServlet</servlet-name>
<url-pattern>/gateinservlet</url-pattern>
</servlet-mapping>
<session-config>
- <session-timeout>30</session-timeout>
+ <session-timeout>30</session-timeout>
</session-config>
<!-- The Welcome File List for IBM WebSphere -->
-
+
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
-
+
<security-constraint>
<web-resource-collection>
- <web-resource-name>user authentication</web-resource-name>
- <url-pattern>/private/*</url-pattern>
- <http-method>POST</http-method>
- <http-method>GET</http-method>
+ <web-resource-name>user authentication</web-resource-name>
+ <url-pattern>/private/*</url-pattern>
+ <http-method>POST</http-method>
+ <http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
- <role-name>users</role-name>
+ <role-name>users</role-name>
</auth-constraint>
<user-data-constraint>
- <transport-guarantee>NONE</transport-guarantee>
+ <transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
- <web-resource-name>admin authentication</web-resource-name>
- <url-pattern>/admin/*</url-pattern>
- <http-method>POST</http-method>
- <http-method>GET</http-method>
+ <web-resource-name>admin authentication</web-resource-name>
+ <url-pattern>/admin/*</url-pattern>
+ <http-method>POST</http-method>
+ <http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
- <role-name>admin</role-name>
+ <role-name>admin</role-name>
</auth-constraint>
<user-data-constraint>
- <transport-guarantee>NONE</transport-guarantee>
+ <transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
- <auth-method>FORM</auth-method>
- <realm-name>gatein-domain</realm-name>
+ <auth-method>FORM</auth-method>
+ <realm-name>gatein-domain</realm-name>
<form-login-config>
- <form-login-page>/initiatelogin</form-login-page>
+ <form-login-page>/initiatelogin</form-login-page>
<form-error-page>/errorlogin</form-error-page>
</form-login-config>
</login-config>
<security-role>
- <description>a simple user role</description>
- <role-name>users</role-name>
+ <description>a simple user role</description>
+ <role-name>users</role-name>
</security-role>
<security-role>
<description>the admin role</description>
- <role-name>admin</role-name>
+ <role-name>admin</role-name>
</security-role>
</web-app>
Added:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java
(rev 0)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java 2010-08-12
12:29:15 UTC (rev 3811)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.application.localization;
+
+import org.exoplatform.portal.application.PortalRequestContext;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class HttpRequestWrapper extends HttpServletRequestWrapper
+{
+ private static final List<Locale> EMPTY_LOCALE_LIST = Collections.emptyList();
+
+ /**
+ * Constructs a request object wrapping the given request.
+ *
+ * @throws IllegalArgumentException if the request is null
+ */
+ public HttpRequestWrapper(HttpServletRequest request)
+ {
+ super(request);
+ }
+
+ /**
+ * Note: Keep the implementation here in sync with {@link
org.exoplatform.portal.webui.application.ExoUserContext#getLocale}
+ * @return
+ */
+ @Override
+ public Locale getLocale()
+ {
+ if (PortalRequestContext.getCurrentInstance() != null)
+ return getRequest().getLocale();
+
+ Locale current = LocalizationFilter.getCurrentLocale();
+ if (current != null)
+ return current;
+
+ return getRequest().getLocale();
+ }
+
+ @Override
+ public Enumeration getLocales()
+ {
+ Locale current = LocalizationFilter.getCurrentLocale();
+ if (PortalRequestContext.getCurrentInstance() != null || current == null)
+ return getRequest().getLocales();
+
+ Locale loc = getLocale();
+ if (loc == null)
+ {
+ return Collections.enumeration(EMPTY_LOCALE_LIST);
+ }
+ else
+ {
+ LinkedList<Locale> locs = new LinkedList<Locale>();
+ locs.add(loc);
+
+ Enumeration<Locale> clientLocs = (Enumeration<Locale>)
getRequest().getLocales();
+ while (clientLocs.hasMoreElements())
+ {
+ current = clientLocs.nextElement();
+ if (current.getLanguage().equals(loc.getLanguage()) &&
current.getCountry().equals(loc.getCountry()))
+ continue;
+ locs.add(current);
+ }
+
+ return Collections.enumeration(locs);
+ }
+ }
+}
Added:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java
(rev 0)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java 2010-08-12
12:29:15 UTC (rev 3811)
@@ -0,0 +1,195 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.application.localization;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.RootContainer;
+import org.exoplatform.portal.Constants;
+import org.exoplatform.portal.application.PortalRequestContext;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.organization.OrganizationService;
+import org.exoplatform.services.organization.UserProfile;
+import org.exoplatform.services.resources.LocaleConfig;
+import org.exoplatform.services.resources.LocaleConfigService;
+import org.exoplatform.services.resources.LocaleContextInfo;
+import org.exoplatform.services.resources.LocalePolicy;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * This filter provides {@link HttpServletRequest#getLocale()} and {@link
HttpServletRequest#getLocales()}
+ * override for extra-portlet requests (i.e. unbridged .jsp). Thanks to this dynamic
resources can be localized
+ * to keep in synch with the rest of the portal.
+ *
+ * A concrete example for this is login/jsp/login.jsp used when authentication fails at
portal login.
+ *
+ * By default {@link HttpServletRequest#getLocale()} and {@link
HttpServletRequest#getLocales()} reflect
+ * browser language preference. When using this filter these two calls employ the same
Locale determination algorithm
+ * that LocalizationLifecycle uses.
+ *
+ * This filter can be activated / deactivated via portal module's web.xml
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class LocalizationFilter implements Filter
+{
+ private static Log log = ExoLogger.getLogger("portal:LocalizationFilter");
+
+ private static ThreadLocal<Locale> currentLocale = new
ThreadLocal<Locale>();
+
+ public void init(FilterConfig filterConfig) throws ServletException
+ {
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException, ServletException
+ {
+
+ HttpServletRequest req = (HttpServletRequest) request;
+ HttpServletResponse res = (HttpServletResponse) response;
+
+ try
+ {
+ // Due to forwards, and includes the filter might be reentered
+ // If current requestContext exists use its Locale
+ PortalRequestContext context = PortalRequestContext.getCurrentInstance();
+ if (context != null && context.getLocale() != null)
+ {
+ // No need to wrap if reentered
+ boolean skipWrapping = currentLocale.get() != null;
+ // overwrite any already set currentLocale
+ currentLocale.set(context.getLocale());
+ if (!skipWrapping)
+ {
+ req = new HttpRequestWrapper(req);
+ }
+ chain.doFilter(req, res);
+ return;
+ }
+
+ // If reentered we don't need to wrap
+ if (currentLocale.get() != null)
+ {
+ chain.doFilter(request, response);
+ return;
+ }
+
+
+ // Initialize currentLocale
+ ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent();
+ if (container == null)
+ {
+ // Nothing we can do, move on
+ chain.doFilter(req, res);
+ return;
+ }
+
+ if (container instanceof RootContainer)
+ container = (ExoContainer)
container.getComponentInstance("portal");
+
+ LocaleConfigService localeConfigService = (LocaleConfigService)
+ container.getComponentInstanceOfType(LocaleConfigService.class);
+ LocalePolicy localePolicy = (LocalePolicy)
container.getComponentInstanceOfType(LocalePolicy.class);
+
+ LocaleContextInfo localeCtx = new LocaleContextInfo();
+
+ Set<Locale> supportedLocales = new HashSet();
+ for (LocaleConfig lc: localeConfigService.getLocalConfigs())
+ {
+ supportedLocales.add(lc.getLocale());
+ }
+ localeCtx.setSupportedLocales(supportedLocales);
+
+ localeCtx.setBrowserLocales(Collections.list(request.getLocales()));
+ localeCtx.setCookieLocales(LocalizationLifecycle.getCookieLocales(req));
+ localeCtx.setUserProfileLocale(getUserProfileLocale(container,
req.getRemoteUser()));
+ localeCtx.setRemoteUser(req.getRemoteUser());
+
+ localeCtx.setPortalLocale(Locale.ENGLISH);
+ Locale locale = localePolicy.determineLocale(localeCtx);
+ if (!supportedLocales.contains(locale))
+ {
+ if (log.isWarnEnabled())
+ log.warn("Unsupported locale returned by LocalePolicy: " +
localePolicy + ". Falling back to 'en'.");
+ locale = Locale.ENGLISH;
+ }
+
+ currentLocale.set(locale);
+ chain.doFilter(new HttpRequestWrapper(req), res);
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException("LocalizationFilter exception: ", e);
+ }
+ finally
+ {
+ currentLocale.remove();
+ }
+ }
+
+ private Locale getUserProfileLocale(ExoContainer container, String user)
+ {
+ UserProfile userProfile = null;
+ OrganizationService svc = (OrganizationService)
+ container.getComponentInstanceOfType(OrganizationService.class);
+
+ if (user != null)
+ {
+ try
+ {
+ userProfile = svc.getUserProfileHandler().findUserProfileByName(user);
+ }
+ catch (Exception ignored)
+ {
+ log.error("IGNORED: Failed to load UserProfile for username: " +
user, ignored);
+ }
+
+ if (userProfile == null && log.isWarnEnabled())
+ log.warn("Could not load user profile for " + user + ". Using
default portal locale.");
+ }
+
+ String lang = userProfile == null ? null :
userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE);
+ return (lang != null) ? new Locale(lang) : null;
+ }
+
+ public void destroy()
+ {
+ }
+
+ public static Locale getCurrentLocale()
+ {
+ return currentLocale.get();
+ }
+}