Author: ndkhoiits
Date: 2010-09-27 23:32:25 -0400 (Mon, 27 Sep 2010)
New Revision: 4402
Modified:
exo/portal/branches/3.1.x/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalForm.java
Log:
EXOGTN-74 Cannot change Locale of site to language having particular country
Modified:
exo/portal/branches/3.1.x/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalForm.java
===================================================================
---
exo/portal/branches/3.1.x/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalForm.java 2010-09-28
02:25:12 UTC (rev 4401)
+++
exo/portal/branches/3.1.x/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalForm.java 2010-09-28
03:32:25 UTC (rev 4402)
@@ -19,6 +19,8 @@
package org.exoplatform.portal.webui.portal;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.config.DataStorage;
import org.exoplatform.portal.config.UserPortalConfig;
@@ -37,6 +39,7 @@
import org.exoplatform.services.organization.OrganizationService;
import org.exoplatform.services.resources.LocaleConfig;
import org.exoplatform.services.resources.LocaleConfigService;
+import org.exoplatform.services.resources.ResourceBundleService;
import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.config.InitParams;
@@ -71,6 +74,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.MissingResourceException;
@ComponentConfigs({
@ComponentConfig(lifecycle = UIFormLifecycle.class, template =
"system:/groovy/webui/form/UIFormTabPane.gtmpl", events = {
@@ -119,7 +124,7 @@
}
WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
Param param = initParams.getParam("PortalTemplateConfigOption");
- List<SelectItemCategory> portalTemplates =
(List<SelectItemCategory>)param.getMapGroovyObject(context);
+ List<SelectItemCategory> portalTemplates =
(List<SelectItemCategory>)param.getFreshObject(context);
for (SelectItemCategory itemCategory : portalTemplates)
{
uiTemplateInput.getItemCategories().add(itemCategory);
@@ -166,8 +171,13 @@
LocaleConfigService localeConfigService =
getApplicationComponent(LocaleConfigService.class);
LocaleConfig localeConfig =
localeConfigService.getLocaleConfig(editPortal.getLocale());
- this.<UIFormInputSet>
getChildById("PortalSetting").<UIFormSelectBox>
getChildById(FIELD_LOCALE).setValue(
- localeConfig.getLanguage());
+ String lang = localeConfig.getLanguage();
+ if (localeConfig.getLocale().getCountry() != null &&
localeConfig.getLocale().getCountry().length() > 0)
+ {
+ lang += "_" + localeConfig.getLocale().getCountry();
+ }
+
+ this.<UIFormInputSet>
getChildById("PortalSetting").<UIFormSelectBox>
getChildById(FIELD_LOCALE).setValue(lang);
setActions(new String[]{"Save", "Close"});
}
@@ -182,21 +192,38 @@
private void createDefaultItem() throws Exception
{
- UIPortal uiPortal = Util.getUIPortal();
LocaleConfigService localeConfigService =
getApplicationComponent(LocaleConfigService.class);
Collection<?> listLocaleConfig = localeConfigService.getLocalConfigs();
LocaleConfig defaultLocale = localeConfigService.getDefaultLocaleConfig();
String defaultLanguage = defaultLocale.getLanguage();
- Locale currentLocate = Util.getPortalRequestContext().getLocale();
+ Locale currentLocale = Util.getPortalRequestContext().getLocale();
Iterator<?> iterator = listLocaleConfig.iterator();
while (iterator.hasNext())
{
LocaleConfig localeConfig = (LocaleConfig)iterator.next();
- SelectItemOption<String> option =
- new
SelectItemOption<String>(localeConfig.getLocale().getDisplayName(currentLocate),
localeConfig
- .getLanguage());
- if (defaultLanguage.equals(localeConfig.getLanguage()))
+ ResourceBundle localeResourceBundle = getResourceBundle(currentLocale);
+ Locale local = localeConfig.getLocale();
+ String lang = local.getLanguage();
+ if (local.getCountry() != null && local.getCountry().length() > 0)
{
+ lang += "_" + local.getCountry();
+ }
+
+ String displayName = null;
+ try
+ {
+ String key = "Locale." + lang;
+ String translation = localeResourceBundle.getString(key);
+ displayName = translation;
+ }
+ catch (MissingResourceException e)
+ {
+ displayName = capitalizeFirstLetter(local.getDisplayName(currentLocale));;
+ }
+
+ SelectItemOption<String> option = new
SelectItemOption<String>(displayName, lang);
+ if (defaultLanguage.equals(lang))
+ {
option.setSelected(true);
}
languages.add(option);
@@ -280,14 +307,12 @@
{
UIPortal uiPortal = uiForm.createUIComponent(UIPortal.class, null, null);
PortalDataMapper.toUIPortal(uiPortal, userConfig);
-
UIPortalApplication uiPortalApp =
(UIPortalApplication)prContext.getUIApplication();
uiForm.invokeSetBindingBean(uiPortal);
//uiPortal.refreshNavigation(localeConfigService.getLocaleConfig(uiPortal.getLocale()).getLocale())
;
if (uiPortalApp.getModeState() == UIPortalApplication.NORMAL_MODE)
{
PortalConfig portalConfig =
(PortalConfig)PortalDataMapper.buildModelObject(uiPortal);
- UserPortalConfigService configService =
uiForm.getApplicationComponent(UserPortalConfigService.class);
dataService.save(portalConfig);
}
else
@@ -319,7 +344,7 @@
{
UIPortalForm uiForm = event.getSource();
PortalRequestContext pcontext =
(PortalRequestContext)event.getRequestContext();
- String template = "classic";
+ String template = "classic";
// String template =
uiForm.getChild(UIFormInputItemSelector.class).getSelectedItemOption().getValue().toString();
String portalName = uiForm.getUIStringInput(FIELD_NAME).getValue();
DataStorage dataService = uiForm.getApplicationComponent(DataStorage.class);
@@ -370,4 +395,27 @@
}
}
+ private String capitalizeFirstLetter(String word)
+ {
+ if (word == null)
+ {
+ return null;
+ }
+ if (word.length() == 0)
+ {
+ return word;
+ }
+ StringBuilder result = new StringBuilder(word);
+ result.replace(0, 1, result.substring(0, 1).toUpperCase());
+ return result.toString();
+ }
+
+ private ResourceBundle getResourceBundle(Locale locale) throws Exception
+ {
+ ExoContainer appContainer = ExoContainerContext.getCurrentContainer();
+ ResourceBundleService service =
+
(ResourceBundleService)appContainer.getComponentInstanceOfType(ResourceBundleService.class);
+ ResourceBundle res = service.getResourceBundle("locale.portal.webui",
locale);
+ return res;
+ }
}
Show replies by date