Author: mstruk
Date: 2010-11-25 11:16:06 -0500 (Thu, 25 Nov 2010)
New Revision: 5273
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java
Log:
GTNPORTAL-1693 Add the ability to configure LocalizationFilter's portalLocale
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java 2010-11-25
15:29:30 UTC (rev 5272)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java 2010-11-25
16:16:06 UTC (rev 5273)
@@ -56,15 +56,27 @@
* override for extra-portlet requests (i.e. unbridged .jsp). Thanks to it dynamic
resources can be localized
* to keep in sync with the rest of the portal. This filter is re-entrant, and can safely
be installed for
* INCLUDE, FORWARD, and ERROR dispatch methods.
- *
+ * <p>
* A concrete example of re-entrant use is login/jsp/login.jsp used when authentication
fails at portal login.
- *
+ * <p>
* 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
- * as LocalizationLifecycle does.
- *
+ * as {@link LocalizationLifecycle} does.
+ * <p>
* This filter can be activated / deactivated via portal module's web.xml
- *
+ * <p>
+ * If default portal language is other than English, it can be configured for the filter
by using PortalLocale init param:
+ * <p>
+ * <pre><filter>
+ * <filter-name>LocalizationFilter</filter-name>
+ *
<filter-class>org.exoplatform.portal.application.localization.LocalizationFilter</filter-class>
+ * <init-param>
+ * <param-name>PortalLocale</param-name>
+ * <param-value>fr_FR</param-value>
+ * </init-param>
+ * </filter>
+ * </pre>
+ *
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public class LocalizationFilter implements Filter
@@ -73,8 +85,14 @@
private static ThreadLocal<Locale> currentLocale = new
ThreadLocal<Locale>();
+ private Locale portalLocale = Locale.ENGLISH;
+
public void init(FilterConfig filterConfig) throws ServletException
{
+ String locale = filterConfig.getInitParameter("PortalLocale");
+ locale = locale != null ? locale.trim() : null;
+ if (locale != null && locale.length() > 0)
+ portalLocale = LocaleContextInfo.getLocale(locale);
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException, ServletException
@@ -141,7 +159,7 @@
localeCtx.setUserProfileLocale(getUserProfileLocale(container,
req.getRemoteUser()));
localeCtx.setRemoteUser(req.getRemoteUser());
- localeCtx.setPortalLocale(Locale.ENGLISH);
+ localeCtx.setPortalLocale(checkPortalLocaleSupported(portalLocale,
supportedLocales));
Locale locale = localePolicy.determineLocale(localeCtx);
boolean supported = supportedLocales.contains(locale);
@@ -170,6 +188,27 @@
}
}
+ private Locale checkPortalLocaleSupported(Locale portalLocale, Set<Locale>
supportedLocales)
+ {
+ if (supportedLocales.contains(portalLocale))
+ return portalLocale;
+ if ("".equals(portalLocale.getCountry()) == false)
+ {
+ Locale loc = new Locale(portalLocale.getLanguage());
+ if (supportedLocales.contains(loc))
+ {
+ log.warn("portalLocale not supported: " +
LocaleContextInfo.getLocaleAsString(portalLocale)
+ + ". Falling back to '" + portalLocale.getLanguage()+
"'.");
+ this.portalLocale = loc;
+ return loc;
+ }
+ }
+
+ log.warn("portalLocale not supported: " +
LocaleContextInfo.getLocaleAsString(portalLocale) + ". Falling back to
Locale.ENGLISH.");
+ this.portalLocale = Locale.ENGLISH;
+ return portalLocale;
+ }
+
private Locale getUserProfileLocale(ExoContainer container, String user)
{
UserProfile userProfile = null;
Show replies by date