Author: trong.tran
Date: 2010-08-12 00:54:05 -0400 (Thu, 12 Aug 2010)
New Revision: 3808
Added:
portal/branches/branched-r3776/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java
portal/branches/branched-r3776/component/resources/src/main/java/org/exoplatform/services/resources/LocalePolicy.java
portal/branches/branched-r3776/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationRequestPhaseLifecycle.java
portal/branches/branched-r3776/component/web/controller/src/main/java/org/exoplatform/web/application/Phase.java
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java
Modified:
portal/branches/branched-r3776/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIUserInfo.java
portal/branches/branched-r3776/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml
portal/branches/branched-r3776/webui/portal/src/main/java/conf/portal/configuration.xml
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/UserProfileLifecycle.java
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ExoUserContext.java
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UILanguageSelector.java
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
Log:
GTNPORTAL-1306 Fix getting wrong locale in PortletRequest
and provide a pluggable mechanism for determining of the preferred locale
Added:
portal/branches/branched-r3776/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java
===================================================================
---
portal/branches/branched-r3776/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java
(rev 0)
+++
portal/branches/branched-r3776/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -0,0 +1,190 @@
+/*
+ * 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.services.resources;
+
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Data structure that holds the inputs for {@link LocalePolicy} pluggable policies
mechanism.
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class LocaleContextInfo
+{
+ private Set<Locale> supportedLocales;
+ private List<Locale> browserLocales;
+ private List<Locale> cookieLocales;
+ private Locale userProfileLocale;
+ private String remoteUser;
+ private Locale portalLocale;
+
+ /**
+ * Setter for supportedLocales
+ * @param supportedLocales locales supported by portal
+ */
+ public void setSupportedLocales(Set<Locale> supportedLocales)
+ {
+ this.supportedLocales = supportedLocales;
+ }
+
+ /**
+ * Getter for supportedLocales
+ * @return supportedLocales
+ */
+ public Set<Locale> getSupportedLocales()
+ {
+ return supportedLocales;
+ }
+
+ /**
+ * Setter for browserLocales
+ * @param browserLocales list of locales as preferred by client's browser
+ */
+ public void setBrowserLocales(List<Locale> browserLocales)
+ {
+ this.browserLocales = browserLocales;
+ }
+
+ /**
+ * Getter for browserLocales
+ * @return browserLocales
+ */
+ public List<Locale> getBrowserLocales()
+ {
+ return browserLocales;
+ }
+
+ /**
+ * Setter for cookieLocales
+ * @param cookieLocales locales stored in user's browser cookie
+ */
+ public void setCookieLocales(List<Locale> cookieLocales)
+ {
+ this.cookieLocales = cookieLocales;
+ }
+
+ /**
+ * Getter for cookieLocales
+ * @return cookieLocales
+ */
+ public List<Locale> getCookieLocales()
+ {
+ return cookieLocales;
+ }
+
+ /**
+ * Setter for userProfileLocale
+ * @param userProfileLocale locale loaded from user's profile
+ */
+ public void setUserProfileLocale(Locale userProfileLocale)
+ {
+ this.userProfileLocale = userProfileLocale;
+ }
+
+ /**
+ * Getter for userProfileLocale
+ * @return userProfileLocale
+ */
+ public Locale getUserProfileLocale()
+ {
+ return userProfileLocale;
+ }
+
+ /**
+ * Setter for remoteUser
+ * @param remoteUser username of the currently logged in user. Null for anonymous
users.
+ */
+ public void setRemoteUser(String remoteUser)
+ {
+ this.remoteUser = remoteUser;
+ }
+
+ /**
+ * Getter for remoteUser
+ * @return remoteUser
+ */
+ public String getRemoteUser()
+ {
+ return remoteUser;
+ }
+
+ /**
+ * Setter for portalLocale
+ * @param portalLocale default locale configured for the portal
+ */
+ public void setPortalLocale(Locale portalLocale)
+ {
+ this.portalLocale = portalLocale;
+ }
+
+ /**
+ * Getter for portalLocale
+ * @return portalLocale
+ */
+ public Locale getPortalLocale()
+ {
+ return portalLocale;
+ }
+
+ /**
+ * Helper method that returns the locale only if it's supported by portal.
+ * Otherwise it returns null.
+ *
+ * @param locale locale to check
+ * @return locale if supported, null otherwise
+ */
+ public Locale getLocaleIfSupported(Locale locale)
+ {
+ if (supportedLocales.contains(locale))
+ return locale;
+ return null;
+ }
+
+ /**
+ * Helper method to convert String representation of Locale into Locale object.
+ * @param portalLocaleName String representation of Locale
+ * @return locale
+ */
+ public static Locale getLocale(String portalLocaleName)
+ {
+ int pos = portalLocaleName.indexOf("_");
+ if (pos < 0)
+ return new Locale(portalLocaleName);
+
+ return new Locale(portalLocaleName.substring(0, pos),
portalLocaleName.substring(pos+1));
+ }
+
+ /**
+ * Helper method to get a String representation of the Locale
+ * @param locale
+ * @return String representation of the locale
+ */
+ public static String getLocaleAsString(Locale locale)
+ {
+ if (locale.getCountry().length() == 0)
+ return locale.getLanguage();
+
+ return locale.getLanguage() + "_" + locale.getCountry();
+ }
+}
Added:
portal/branches/branched-r3776/component/resources/src/main/java/org/exoplatform/services/resources/LocalePolicy.java
===================================================================
---
portal/branches/branched-r3776/component/resources/src/main/java/org/exoplatform/services/resources/LocalePolicy.java
(rev 0)
+++
portal/branches/branched-r3776/component/resources/src/main/java/org/exoplatform/services/resources/LocalePolicy.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -0,0 +1,41 @@
+/*
+ * 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.services.resources;
+
+import java.util.Locale;
+
+/**
+ * This interface represents a pluggable mechanism for different locale determining
algorithms
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public interface LocalePolicy
+{
+ /**
+ * Determine the Locale to be used for current request
+ *
+ * @param localeContext locale context info available to implementations
+ * as inputs to use when determining appropriate Locale
+ * @return Locale to be used for current user's request
+ */
+ public Locale determineLocale(LocaleContextInfo localeContext);
+}
Added:
portal/branches/branched-r3776/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationRequestPhaseLifecycle.java
===================================================================
---
portal/branches/branched-r3776/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationRequestPhaseLifecycle.java
(rev 0)
+++
portal/branches/branched-r3776/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationRequestPhaseLifecycle.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -0,0 +1,47 @@
+/*
+ * 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.web.application;
+
+/**
+ * Interface that extends {@link ApplicationLifecycle} with request phase methods that
allow interception of
+ * before/after ACTION phase, and before/after RENDER phase of request processing.
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public interface ApplicationRequestPhaseLifecycle<E extends RequestContext> extends
ApplicationLifecycle<E>
+{
+ /**
+ * Perform any processing required at the beginning of {@link Phase#ACTION} or {@link
Phase#RENDER} phase.
+ * @param app Application
+ * @param context current RequestContext
+ * @param phase starting phase
+ */
+ public void onStartRequestPhase(Application app, E context, Phase phase);
+
+ /**
+ * Perform any processing required at the end of {@link Phase#ACTION} or {@link
Phase#RENDER} phase.
+ * @param app Application
+ * @param context current RequestContext
+ * @param phase ending phase
+ */
+ public void onEndRequestPhase(Application app, E context, Phase phase);
+}
Added:
portal/branches/branched-r3776/component/web/controller/src/main/java/org/exoplatform/web/application/Phase.java
===================================================================
---
portal/branches/branched-r3776/component/web/controller/src/main/java/org/exoplatform/web/application/Phase.java
(rev 0)
+++
portal/branches/branched-r3776/component/web/controller/src/main/java/org/exoplatform/web/application/Phase.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -0,0 +1,33 @@
+/*
+ * 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.web.application;
+
+/**
+ * Enum representing request processing phases.
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public enum Phase
+{
+ ACTION,
+ RENDER
+}
Modified:
portal/branches/branched-r3776/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIUserInfo.java
===================================================================
---
portal/branches/branched-r3776/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIUserInfo.java 2010-08-12
03:55:48 UTC (rev 3807)
+++
portal/branches/branched-r3776/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIUserInfo.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -21,6 +21,7 @@
import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.portal.Constants;
+import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.portal.webui.workspace.UIPortalApplication;
import org.exoplatform.portal.webui.workspace.UIWorkingWorkspace;
@@ -134,7 +135,8 @@
LocaleConfig localeConfig = localeConfigService.getLocaleConfig(language);
if (localeConfig == null)
localeConfig = localeConfigService.getDefaultLocaleConfig();
- uiApp.setLocale(localeConfig.getLocale());
+ PortalRequestContext prqCtx = PortalRequestContext.getCurrentInstance();
+ prqCtx.setLocale(localeConfig.getLocale());
uiApp.setOrientation(localeConfig.getOrientation());
uiApp.localizeNavigations();
Modified:
portal/branches/branched-r3776/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml
===================================================================
---
portal/branches/branched-r3776/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml 2010-08-12
03:55:48 UTC (rev 3807)
+++
portal/branches/branched-r3776/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml 2010-08-12
04:54:05 UTC (rev 3808)
@@ -38,6 +38,7 @@
<listener>org.exoplatform.webui.application.MonitorApplicationLifecycle</listener>
<listener>org.exoplatform.portal.application.UserProfileLifecycle</listener>
<listener>org.exoplatform.portal.application.concurrent.PortalConcurrencyMonitorLifecycle</listener>
+
<listener>org.exoplatform.portal.application.localization.LocalizationLifecycle</listener>
</application-lifecycle-listeners>
<events>
Modified:
portal/branches/branched-r3776/webui/portal/src/main/java/conf/portal/configuration.xml
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/conf/portal/configuration.xml 2010-08-12
03:55:48 UTC (rev 3807)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/conf/portal/configuration.xml 2010-08-12
04:54:05 UTC (rev 3808)
@@ -30,5 +30,11 @@
<component>
<type>org.exoplatform.portal.application.PortalStatisticService</type>
- </component>
+ </component>
+
+ <component>
+ <key>org.exoplatform.services.resources.LocalePolicy</key>
+
<!--type>org.exoplatform.portal.application.NoBrowserLocalePolicyService</type-->
+
<type>org.exoplatform.portal.application.localization.DefaultLocalePolicyService</type>
+ </component>
</configuration>
Modified:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-08-12
03:55:48 UTC (rev 3807)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -116,6 +116,8 @@
private Map<String, String[]> parameterMap;
+ private Locale locale = Locale.ENGLISH;
+
public JavascriptManager getJavascriptManager()
{
return jsmanager_;
@@ -169,12 +171,10 @@
// Reconstructing the getPathInfo from the non server decoded values.
String servletPath = URLDecoder.decode(req.getServletPath(), "UTF-8");
String contextPath = URLDecoder.decode(req.getContextPath(), "UTF-8");
- String pathInfo = requestURI_.substring((servletPath + contextPath).length());
+ String pathInfo = "/";
+ if (requestURI_.length() > servletPath.length() + contextPath.length())
+ pathInfo = requestURI_.substring(servletPath.length() + contextPath.length());
- if (pathInfo == null || pathInfo.length() == 0)
- {
- pathInfo = "/";
- }
int colonIndex = pathInfo.indexOf("/", 1);
if (colonIndex < 0)
{
@@ -241,9 +241,14 @@
return ((UIPortalApplication)uiApplication_).getOrientation();
}
+ public void setLocale(Locale locale)
+ {
+ this.locale = locale;
+ }
+
public Locale getLocale()
{
- return ((UIPortalApplication)uiApplication_).getLocale();
+ return locale;
}
@SuppressWarnings("unchecked")
Modified:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2010-08-12
03:55:48 UTC (rev 3807)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -26,6 +26,8 @@
import org.exoplatform.web.WebAppController;
import org.exoplatform.web.WebRequestHandler;
import org.exoplatform.web.application.ApplicationLifecycle;
+import org.exoplatform.web.application.ApplicationRequestPhaseLifecycle;
+import org.exoplatform.web.application.Phase;
import org.exoplatform.web.application.RequestFailure;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.core.UIApplication;
@@ -104,11 +106,17 @@
if (!context.isResponseComplete() && !context.getProcessRender())
{
+ startRequestPhaseLifecycle(app, context, lifecycles, Phase.ACTION);
uiApp.processAction(context);
+ endRequestPhaseLifecycle(app, context, lifecycles, Phase.ACTION);
}
if (!context.isResponseComplete())
+ {
+ startRequestPhaseLifecycle(app, context, lifecycles, Phase.RENDER);
uiApp.processRender(context);
+ endRequestPhaseLifecycle(app, context, lifecycles, Phase.RENDER);
+ }
if (uiApp != null)
uiApp.setLastAccessApplication(System.currentTimeMillis());
@@ -149,4 +157,25 @@
WebuiRequestContext.setCurrentInstance(null);
}
}
+
+ private void startRequestPhaseLifecycle(PortalApplication app, PortalRequestContext
context,
+ List<ApplicationLifecycle> lifecycles,
Phase phase)
+ {
+ for (ApplicationLifecycle lifecycle : lifecycles)
+ {
+ if (lifecycle instanceof ApplicationRequestPhaseLifecycle)
+ ((ApplicationRequestPhaseLifecycle) lifecycle).onStartRequestPhase(app,
context, phase);
+ }
+ }
+
+ private void endRequestPhaseLifecycle(PortalApplication app, PortalRequestContext
context,
+ List<ApplicationLifecycle> lifecycles,
Phase phase)
+ {
+ for (ApplicationLifecycle lifecycle : lifecycles)
+ {
+ if (lifecycle instanceof ApplicationRequestPhaseLifecycle)
+ ((ApplicationRequestPhaseLifecycle) lifecycle).onEndRequestPhase(app,
context, phase);
+ }
+ }
+
}
Modified:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java 2010-08-12
03:55:48 UTC (rev 3807)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -141,7 +141,7 @@
// For now do nothing....
}
- private UserPortalConfig getUserPortalConfig(PortalRequestContext context) throws
Exception
+ public static UserPortalConfig getUserPortalConfig(PortalRequestContext context)
throws Exception
{
ExoContainer appContainer =
context.getApplication().getApplicationServiceContainer();
UserPortalConfigService service_ =
(UserPortalConfigService)appContainer.getComponentInstanceOfType(UserPortalConfigService.class);
Modified:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/UserProfileLifecycle.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/UserProfileLifecycle.java 2010-08-12
03:55:48 UTC (rev 3807)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/UserProfileLifecycle.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -31,7 +31,7 @@
{
public static final String USER_PROFILE_ATTRIBUTE_NAME =
"PortalUserProfile";
- private final ThreadLocal<UserProfile> currentUserProfile = new
ThreadLocal<UserProfile>();
+ private final static ThreadLocal<UserProfile> currentUserProfile = new
ThreadLocal<UserProfile>();
@SuppressWarnings("unused")
public void onInit(Application app)
@@ -55,15 +55,15 @@
}
}
-
+
currentUserProfile.set(userProfile);
context.setAttribute(this.USER_PROFILE_ATTRIBUTE_NAME, userProfile);
}
-
+
@SuppressWarnings("unused")
public void onFailRequest(Application app, WebuiRequestContext context, RequestFailure
failureType) throws Exception
{
-
+
}
@SuppressWarnings("unused")
Added:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java
(rev 0)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -0,0 +1,142 @@
+/*
+ * 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.services.resources.LocaleContextInfo;
+import org.exoplatform.services.resources.LocalePolicy;
+import org.picocontainer.Startable;
+
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * This service represents a default policy for determining LocaleConfig to be used for
user's session.
+ * This service is registered through portal services configuration file:
conf/portal/configuration.xml
+ * Custom locale determination policy can be implemented by overriding or completely
replacing this class,
+ * and registering an alternative implementation.
+ *
+ * @see NoBrowserLocalePolicyService
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class DefaultLocalePolicyService implements LocalePolicy, Startable
+{
+ /**
+ * @see LocalePolicy#determineLocale(LocaleContextInfo)
+ */
+ public Locale determineLocale(LocaleContextInfo context)
+ {
+ Locale locale = null;
+ if (context.getRemoteUser() == null)
+ locale = getLocaleConfigForAnonymous(context);
+ else
+ locale = getLocaleConfigForRegistered(context);
+
+ if (locale == null)
+ locale = context.getPortalLocale();
+
+ return locale;
+ }
+
+ /**
+ * Override this method to change the LocaleConfig determination for registered
users.
+ * Default is: use user's profile language, if not available fall back to LOCALE
cookie,
+ * and finally if that is not available either fall back to browser language
preference.
+ *
+ * @param context locale context info available to implementations in order to
determine appropriate Locale
+ * @return Locale representing a language to use, or null
+ */
+ protected Locale getLocaleConfigForRegistered(LocaleContextInfo context)
+ {
+ Locale locale = context.getLocaleIfSupported(context.getUserProfileLocale());
+ if (locale == null)
+ locale = getLocaleConfigFromCookie(context);
+ if (locale == null)
+ locale = getLocaleConfigFromBrowser(context);
+
+ return locale;
+ }
+
+ /**
+ * Override this method to change the Locale determination based on browser language
preferences.
+ * If you want to disable the use of browser language preferences simply return null.
+ *
+ * @param context locale context info available to implementations in order to
determine appropriate Locale
+ * @return Locale representing a language to use, or null
+ */
+ protected Locale getLocaleConfigFromBrowser(LocaleContextInfo context)
+ {
+ List<Locale> locales = context.getBrowserLocales();
+ for (Locale loc: locales)
+ return context.getLocaleIfSupported(loc);
+
+ return null;
+ }
+
+ /**
+ * Override this method to change Locale determination for users that aren't
logged in.
+ * By default the request's LOCALE cookie is used, if that is not available the
browser
+ * language preferences are used.
+ *
+ * @param context locale context info available to implementations in order to
determine appropriate Locale
+ * @return Locale representing a language to use, or null
+ */
+ protected Locale getLocaleConfigForAnonymous(LocaleContextInfo context)
+ {
+ Locale locale = getLocaleConfigFromCookie(context);
+ if (locale == null)
+ locale = getLocaleConfigFromBrowser(context);
+
+ return locale;
+ }
+
+ /**
+ * Override this method to change the Locale determination based on browser cookie.
+ * If you want to disable the use of browser cookies simply return null.
+ *
+ * @param context locale context info available to implementations in order to
determine appropriate Locale
+ * @return Locale representing a language to use, or null
+ */
+ protected Locale getLocaleConfigFromCookie(LocaleContextInfo context)
+ {
+ List<Locale> locales = context.getCookieLocales();
+ for (Locale locale: locales)
+ return context.getLocaleIfSupported(locale);
+
+ return null;
+ }
+
+ /**
+ * Starter interface method
+ */
+ public void start()
+ {
+ }
+
+ /**
+ * Starter interface method
+ */
+ public void stop()
+ {
+ }
+
+}
Added:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java
(rev 0)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -0,0 +1,314 @@
+/*
+ * 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.portal.Constants;
+import org.exoplatform.portal.application.PortalRequestContext;
+import org.exoplatform.portal.application.PortalStateManager;
+import org.exoplatform.portal.application.UserProfileLifecycle;
+import org.exoplatform.portal.config.UserPortalConfig;
+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 org.exoplatform.web.application.Application;
+import org.exoplatform.web.application.ApplicationRequestPhaseLifecycle;
+import org.exoplatform.web.application.Phase;
+import org.exoplatform.web.application.RequestFailure;
+import org.exoplatform.webui.application.WebuiRequestContext;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * This class takes care of loading / initializing / saving the current Locale.
+ * Current Locale is used to create properly localized response to current request.
+ *
+ * At the beginning of request {@link LocalePolicy} is used to determine the
+ * initial Locale to be used for processing the request.
+ *
+ * This Locale is then set on current {@link
org.exoplatform.portal.application.PortalRequestContext} (it's presumed that current
+ * {@link org.exoplatform.web.application.RequestContext} is of type
PortalRequestContext) by calling
+ * {@link org.exoplatform.portal.application.PortalRequestContext#setLocale}.
+ *
+ * During request processing {@link
org.exoplatform.portal.application.PortalRequestContext#getLocale} is the ultimate
reference consulted by any
+ * rendering code that needs to know about current Locale.
+ *
+ * When this Locale is changed during action processing, the new Locale choice is saved
+ * into user's profile or into browser's cookie in order to be used by future
requests.
+ *
+ * This Lifecycle depends on UserProfileLifecycle being registered before this one, as it
relies on it
+ * for loading the user profile. See WEB-INF/webui-configuration.xml in web/portal
module.
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class LocalizationLifecycle implements
ApplicationRequestPhaseLifecycle<WebuiRequestContext>
+{
+ private static final String COOKIE_NAME = "LOCALE";
+
+ private static final ThreadLocal<Locale> calculatedLocale = new
ThreadLocal<Locale>();
+
+ private static Log log =
ExoLogger.getLogger("portal:LocalizationLifecycle");
+
+ /**
+ * @see org.exoplatform.web.application.ApplicationLifecycle#onInit
+ */
+ public void onInit(Application app) throws Exception
+ {
+ }
+
+ /**
+ * Initialize Locale to be used for the processing of current request
+ *
+ * @see org.exoplatform.web.application.ApplicationLifecycle#onStartRequest
+ */
+ public void onStartRequest(Application app, WebuiRequestContext context) throws
Exception
+ {
+ if (context instanceof PortalRequestContext == false)
+ throw new IllegalArgumentException("Expected PortalRequestContext, but got:
" + context);
+
+ PortalRequestContext reqCtx = (PortalRequestContext) context;
+ ExoContainer container = app.getApplicationServiceContainer();
+
+ 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);
+
+ HttpServletRequest request = HttpServletRequest.class.cast(context.getRequest());
+ localeCtx.setBrowserLocales(Collections.list(request.getLocales()));
+
+ localeCtx.setCookieLocales(getCookieLocales(request));
+ localeCtx.setUserProfileLocale(getUserProfileLocale(reqCtx));
+ localeCtx.setRemoteUser(reqCtx.getRemoteUser());
+
+ UserPortalConfig userPortalConfig = null;
+ try
+ {
+ userPortalConfig = PortalStateManager.getUserPortalConfig(reqCtx);
+ if (userPortalConfig == null)
+ log.warn("No UserPortalConfig available! Portal locale set to
'en'");
+ }
+ catch(Exception ignored)
+ {
+ if (log.isDebugEnabled())
+ log.debug("IGNORED: Failed to load UserPortalConfig: ", ignored);
+ }
+
+ String portalLocaleName = "en";
+ if (userPortalConfig != null)
+ portalLocaleName = userPortalConfig.getPortalConfig().getLocale();
+
+ Locale portalLocale = LocaleContextInfo.getLocale(portalLocaleName);
+ localeCtx.setPortalLocale(portalLocale);
+
+ 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;
+ }
+ reqCtx.setLocale(locale);
+ calculatedLocale.set(locale);
+ }
+
+ /**
+ * @see
org.exoplatform.web.application.ApplicationRequestPhaseLifecycle#onStartRequestPhase
+ */
+ public void onStartRequestPhase(Application app, WebuiRequestContext context, Phase
phase)
+ {
+ }
+
+ /**
+ * Save any locale change - to cookie for anonymous users, to profile for logged-in
users
+ *
+ * @see
org.exoplatform.web.application.ApplicationRequestPhaseLifecycle#onEndRequestPhase
+ */
+ public void onEndRequestPhase(Application app, WebuiRequestContext context, Phase
phase)
+ {
+ if (phase == Phase.ACTION)
+ {
+ // if onStartRequest survived the cast, this one should as well - no check
necessary
+ PortalRequestContext reqCtx = (PortalRequestContext) context;
+ Locale loc = reqCtx.getLocale();
+ Locale remembered = calculatedLocale.get();
+ calculatedLocale.remove();
+ if (loc != null && (remembered == null || !loc.equals(remembered)))
+ saveLocale(reqCtx, loc);
+ }
+ }
+
+ /**
+ * @see org.exoplatform.web.application.ApplicationLifecycle#onEndRequest
+ */
+ public void onEndRequest(Application app, WebuiRequestContext context) throws
Exception
+ {
+ }
+
+ /**
+ * @see org.exoplatform.web.application.ApplicationLifecycle#onFailRequest
+ */
+ public void onFailRequest(Application app, WebuiRequestContext context, RequestFailure
failureType) throws Exception
+ {
+ }
+
+ /**
+ * @see org.exoplatform.web.application.ApplicationLifecycle#onDestroy
+ */
+ public void onDestroy(Application app) throws Exception
+ {
+ }
+
+ /**
+ * Use {@link UserProfile} already loaded by {@link
org.exoplatform.portal.application.UserProfileLifecycle} or load one ourselves.
+ * @param context current PortalRequestContext
+ * @return Locale from user's profile or null
+ */
+ private Locale getUserProfileLocale(PortalRequestContext context)
+ {
+ String lang = null;
+
+ UserProfile userProfile = getLoadedProfile(context);
+ lang = userProfile == null ? null :
userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE);
+ return (lang != null) ? new Locale(lang) : null;
+ }
+
+ private UserProfile loadUserProfile(ExoContainer container, PortalRequestContext
context)
+ {
+ UserProfile userProfile = null;
+ OrganizationService svc = (OrganizationService)
+ container.getComponentInstanceOfType(OrganizationService.class);
+
+ String user = context.getRemoteUser();
+ 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.");
+ }
+ return userProfile;
+ }
+
+ private UserProfile getLoadedProfile(PortalRequestContext context)
+ {
+ return (UserProfile)
context.getAttribute(UserProfileLifecycle.USER_PROFILE_ATTRIBUTE_NAME);
+ }
+
+ public static List<Locale> getCookieLocales(HttpServletRequest request)
+ {
+ Cookie [] cookies = request.getCookies();
+ if (cookies != null)
+ {
+ for (Cookie cookie: cookies)
+ {
+ if (COOKIE_NAME.equals(cookie.getName()))
+ {
+ List<Locale> locales = new ArrayList<Locale>();
+ locales.add(LocaleContextInfo.getLocale(cookie.getValue()));
+ return locales;
+ }
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ private void saveLocale(PortalRequestContext context, Locale loc)
+ {
+ String user = context.getRemoteUser();
+ if (user != null)
+ {
+ saveLocaleToUserProfile(context, loc, user);
+ }
+ else
+ {
+ saveLocaleToCookie(context, loc);
+ }
+ }
+
+ private void saveLocaleToCookie(PortalRequestContext context, Locale loc)
+ {
+ HttpServletResponse res = context.getResponse();
+ Cookie cookie = new Cookie(COOKIE_NAME, LocaleContextInfo.getLocaleAsString(loc));
+ cookie.setMaxAge(Integer.MAX_VALUE);
+ cookie.setPath("/");
+ res.addCookie(cookie);
+ }
+
+ private void saveLocaleToUserProfile(PortalRequestContext context, Locale loc, String
user)
+ {
+ ExoContainer container =
context.getApplication().getApplicationServiceContainer();
+ OrganizationService svc = (OrganizationService)
+ container.getComponentInstanceOfType(OrganizationService.class);
+
+ // Don't rely on UserProfileLifecycle loaded UserProfile when doing
+ // an update to avoid a potential overwrite of other changes
+ UserProfile userProfile = loadUserProfile(container, context);
+ if (userProfile != null)
+ {
+ userProfile.getUserInfoMap().put(Constants.USER_LANGUAGE, loc.getLanguage());
+ try
+ {
+ svc.getUserProfileHandler().saveUserProfile(userProfile, false);
+ }
+ catch (Exception ignored)
+ {
+ log.error("IGNORED: Failed to save profile for user: " + user,
ignored);
+ userProfile = null;
+ }
+ }
+
+ if (userProfile == null)
+ {
+ if (log.isWarnEnabled())
+ log.warn("Unable to save locale into profile for user: " + user);
+ }
+ }
+}
Added:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java
(rev 0)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -0,0 +1,47 @@
+/*
+ * 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.services.resources.LocaleContextInfo;
+
+import java.util.Locale;
+
+/**
+ * This implementation of {@link org.exoplatform.services.resources.LocalePolicy}
disregards client browser language preference.
+ * Localization will therefore not be affected by different OS or browser language
settings.
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class NoBrowserLocalePolicyService extends DefaultLocalePolicyService
+{
+ /**
+ * Override super method with no-op.
+ *
+ * @param context locale context info available to implementations in order to
determine appropriate Locale
+ * @return null
+ */
+ @Override
+ protected Locale getLocaleConfigFromBrowser(LocaleContextInfo context)
+ {
+ return null;
+ }
+}
Modified:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ExoUserContext.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ExoUserContext.java 2010-08-12
03:55:48 UTC (rev 3807)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ExoUserContext.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -19,8 +19,8 @@
package org.exoplatform.portal.webui.application;
+import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.services.organization.UserProfile;
-import org.gatein.common.util.Tools;
import org.gatein.pc.api.invocation.resolver.AttributeResolver;
import org.gatein.pc.api.invocation.resolver.PrincipalAttributeResolver;
import org.gatein.pc.api.spi.UserContext;
@@ -29,6 +29,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -119,23 +120,52 @@
return Collections.unmodifiableMap(filteredMap);
}
- /** Returns the client request locale or <code>Locale.ENGLISH</code> if no
request was provided. */
+ /**
+ * Returns current PortalRequestContext's locale. It falls back to
+ * clientRequest locale ({@link HttpServletRequest#getLocale}), or
<code>Locale.ENGLISH</code>
+ * if clientRequest object is not available.
+ */
public Locale getLocale()
{
+ PortalRequestContext context = PortalRequestContext.getCurrentInstance();
+
+ if(context != null) {
+ Locale loc = context.getLocale();
+ if (loc != null)
+ return loc;
+ }
+
return clientRequest != null ? clientRequest.getLocale() : Locale.ENGLISH;
}
- /** Returns the client request locales or an empty list if no request was provided.
*/
+ /**
+ * Returns the list of client request locales, making sure the first one in the List
+ * is the same as what getLocale() method returns.
+ */
@SuppressWarnings("unchecked")
public List<Locale> getLocales()
{
- if (clientRequest == null)
+ Locale loc = getLocale();
+ if (loc == null)
{
return EMPTY_LOCALE_LIST;
}
else
{
- return Tools.toList((Enumeration<Locale>)clientRequest.getLocales());
+ LinkedList<Locale> locs = new LinkedList<Locale>();
+ locs.add(loc);
+ if (clientRequest != null)
+ {
+ Enumeration<Locale> clientLocs = (Enumeration<Locale>)
clientRequest.getLocales();
+ while (clientLocs.hasMoreElements())
+ {
+ Locale current = clientLocs.nextElement();
+ if (current.getLanguage().equals(loc.getLanguage()) &&
current.getCountry().equals(loc.getCountry()))
+ continue;
+ locs.add(current);
+ }
+ }
+ return Collections.unmodifiableList(locs);
}
}
Modified:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UILanguageSelector.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UILanguageSelector.java 2010-08-12
03:55:48 UTC (rev 3807)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UILanguageSelector.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -21,21 +21,13 @@
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.portal.Constants;
-import org.exoplatform.portal.config.model.PageNavigation;
-import org.exoplatform.portal.config.model.PageNode;
-import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.portal.webui.workspace.UIMaskWorkspace;
import org.exoplatform.portal.webui.workspace.UIPortalApplication;
-import org.exoplatform.services.organization.OrganizationService;
-import org.exoplatform.services.organization.UserProfile;
-import org.exoplatform.services.organization.UserProfileHandler;
import org.exoplatform.services.resources.LocaleConfig;
import org.exoplatform.services.resources.LocaleConfigService;
-import org.exoplatform.services.resources.ResourceBundleManager;
import org.exoplatform.services.resources.ResourceBundleService;
-import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.config.annotation.EventConfig;
import org.exoplatform.webui.core.UIContainer;
@@ -180,18 +172,10 @@
LocaleConfig localeConfig = localeConfigService.getLocaleConfig(language);
if (localeConfig == null)
localeConfig = localeConfigService.getDefaultLocaleConfig();
- uiApp.setLocale(localeConfig.getLocale());
+ PortalRequestContext prqCtx = PortalRequestContext.getCurrentInstance();
+ prqCtx.setLocale(localeConfig.getLocale());
uiApp.setOrientation(localeConfig.getOrientation());
uiApp.localizeNavigations();
- OrganizationService orgService =
event.getSource().getApplicationComponent(OrganizationService.class);
- String remoteUser = event.getRequestContext().getRemoteUser();
- if (remoteUser != null)
- {
- UserProfile userProfile =
orgService.getUserProfileHandler().findUserProfileByName(remoteUser);
- userProfile.getUserInfoMap().put(Constants.USER_LANGUAGE, language);
- UserProfileHandler hanlder = orgService.getUserProfileHandler();
- hanlder.saveUserProfile(userProfile, true);
- }
}
}
Modified:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java 2010-08-12
03:55:48 UTC (rev 3807)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -238,7 +238,7 @@
uiPageBody.setPageBody(selectedNode_, this);
//Refresh locale
- Locale locale = Util.getUIPortalApplication().getLocale();
+ Locale locale = Util.getPortalRequestContext().getLocale();
localizePageNavigation(navigation, locale);
}
Modified:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java 2010-08-12
03:55:48 UTC (rev 3807)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -220,7 +220,7 @@
// TODO dang.tung - change layout when portal get language from UIPortal
// (user and browser not support)
//
----------------------------------------------------------------------------------------------------
- String portalAppLanguage = uiPortalApp.getLocale().getLanguage();
+ String portalAppLanguage = prContext.getLocale().getLanguage();
OrganizationService orgService =
getApplicationComponent(OrganizationService.class);
UserProfile userProfile =
orgService.getUserProfileHandler().findUserProfileByName(remoteUser);
String userLanguage = userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE);
@@ -231,7 +231,7 @@
{
if (!portalAppLanguage.equals(userLanguage) &&
!portalAppLanguage.equals(browserLanguage))
{
- uiPortalApp.setLocale(localeConfig.getLocale());
+ prContext.setLocale(localeConfig.getLocale());
//editPortal.refreshNavigation(localeConfig.getLocale());
uiPortalApp.localizeNavigations();
}
Modified:
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
===================================================================
---
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2010-08-12
03:55:48 UTC (rev 3807)
+++
portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2010-08-12
04:54:05 UTC (rev 3808)
@@ -46,6 +46,7 @@
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.Orientation;
import org.exoplatform.services.resources.ResourceBundleManager;
import org.exoplatform.web.application.javascript.JavascriptConfigService;
@@ -94,8 +95,6 @@
private String nodePath_;
- private Locale locale_ = Locale.ENGLISH;
-
private Orientation orientation_ = Orientation.LT;
final static public String UI_WORKING_WS_ID = "UIWorkingWorkspace";
@@ -144,10 +143,9 @@
// dang.tung - set portal language by user preference -> browser ->
// default
// ------------------------------------------------------------------------------
- String portalLanguage = null;
LocaleConfigService localeConfigService =
getApplicationComponent(LocaleConfigService.class);
OrganizationService orgService =
getApplicationComponent(OrganizationService.class);
- LocaleConfig localeConfig =
localeConfigService.getLocaleConfig(userPortalConfig_.getPortalConfig().getLocale());
+
String user = context.getRemoteUser();
String portalSkin = null;
@@ -156,7 +154,6 @@
UserProfile userProfile =
orgService.getUserProfileHandler().findUserProfileByName(user);
if (userProfile != null)
{
- portalLanguage = userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE);
portalSkin = userProfile.getUserInfoMap().get(Constants.USER_SKIN);
}
else
@@ -165,24 +162,25 @@
log.warn("Could not load user profile for " + user + ".
Using default portal locale.");
}
}
- localeConfig = localeConfigService.getLocaleConfig(portalLanguage);
- String localeLanguage = (localeConfig.getLocale().getCountry().length() > 0) ?
localeConfig.getLocale()
- .getLanguage()
- + "_" + localeConfig.getLocale().getCountry() :
localeConfig.getLocale().getLanguage();
- if (portalLanguage == null || !portalLanguage.equals(localeLanguage))
+
+ Locale locale = context.getLocale();
+ if (locale == null)
{
- // if user language no support by portal -> get browser language if no
- // ->
- // get portal
- portalLanguage = context.getRequest().getLocale().getLanguage();
- localeConfig = localeConfigService.getLocaleConfig(portalLanguage);
- if (!portalLanguage.equals(localeConfig.getLanguage()))
- {
- localeConfig =
localeConfigService.getLocaleConfig(userPortalConfig_.getPortalConfig().getLocale());
- }
+ if (log.isWarnEnabled())
+ log.warn("No locale set on PortalRequestContext! Falling back to
'en'.");
+ locale = Locale.ENGLISH;
}
- setLocale(localeConfig.getLocale());
+
+ String localeName = LocaleContextInfo.getLocaleAsString(locale);
+ LocaleConfig localeConfig = localeConfigService.getLocaleConfig(localeName);
+ if (localeConfig == null)
+ {
+ if (log.isWarnEnabled())
+ log.warn("Unsupported locale set on PortalRequestContext: " +
localeName + "! Falling back to 'en'.");
+ localeConfig =
localeConfigService.getLocaleConfig(Locale.ENGLISH.getLanguage());
+ }
setOrientation(localeConfig.getOrientation());
+
// -------------------------------------------------------------------------------
context.setUIApplication(this);
@@ -305,14 +303,9 @@
public Locale getLocale()
{
- return locale_;
+ return Util.getPortalRequestContext().getLocale();
}
- public void setLocale(Locale locale)
- {
- locale_ = locale;
- }
-
public void setModeState(int mode)
{
this.modeState = mode;