[gatein-commits] gatein SVN: r5144 - exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/webui/organization.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Nov 17 22:01:57 EST 2010


Author: ndkhoiits
Date: 2010-11-17 22:01:56 -0500 (Wed, 17 Nov 2010)
New Revision: 5144

Modified:
   exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/webui/organization/UIUserProfileInputSet.java
Log:
EXOGTN-158 Set language default is empty when create new user and listed in alphabetical order

Modified: exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/webui/organization/UIUserProfileInputSet.java
===================================================================
--- exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/webui/organization/UIUserProfileInputSet.java	2010-11-18 02:52:57 UTC (rev 5143)
+++ exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/webui/organization/UIUserProfileInputSet.java	2010-11-18 03:01:56 UTC (rev 5144)
@@ -20,12 +20,15 @@
 package org.exoplatform.webui.organization;
 
 import org.exoplatform.commons.serialization.api.annotations.Serialized;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
 import org.exoplatform.portal.Constants;
 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.ResourceBundleService;
 import org.exoplatform.web.application.ApplicationMessage;
 import org.exoplatform.webui.application.WebuiRequestContext;
 import org.exoplatform.webui.application.portlet.PortletRequestContext;
@@ -39,9 +42,13 @@
 import org.exoplatform.webui.form.UIFormStringInput;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.MissingResourceException;
 
 /**
  * Created by The eXo Platform SARL Author : Dang Van Minh minhdv81 at yahoo.com
@@ -141,7 +148,6 @@
       LocaleConfigService localeService = getApplicationComponent(LocaleConfigService.class);
       Locale currentLocale = ((PortletRequestContext)WebuiRequestContext.getCurrentInstance()).getLocale();
       Iterator<LocaleConfig> i = localeService.getLocalConfigs().iterator();
-      String displayLanguage = null;
       String displayName = null;
       String language = null;
       String country = null;
@@ -150,30 +156,46 @@
       {
          LocaleConfig config = i.next();
          Locale locale = config.getLocale();
-         displayName = locale.getDisplayName(currentLocale);
+         
          language = locale.getLanguage();
          country = locale.getCountry();
          if (country != null && country.length() > 0)
          {
-            displayLanguage = displayName + " (" + locale.getDisplayCountry(currentLocale) + ")";
             language = language + "_" + country;
          }
-         else
+
+         
+         ResourceBundle localeResourceBundle;
+
+         displayName = null;
+         try
          {
-            displayLanguage = displayName;
+            localeResourceBundle = getResourceBundle(currentLocale);
+            String key = "Locale." + language;
+            String translation = localeResourceBundle.getString(key);
+            displayName = translation;
          }
-         option = new SelectItemOption<String>(displayLanguage, language, displayName);
+         catch (MissingResourceException e)
+         {
+            displayName = capitalizeFirstLetter(locale.getDisplayName(currentLocale));
+         }
+         catch (Exception e)
+         {
+     
+         }
+         
+         option = new SelectItemOption<String>(displayName, language);
          if (language.equals(selectedLang))
          {
             option.setSelected(true);
          }
-         if (config.getLanguage().equals("en"))
-         {
-            lang.add(0, option);
-            continue;
-         }
          lang.add(option);
       }
+      
+      // Set default language for new user is empty
+      lang.add(new SelectItemOption<String>("", ""));
+      
+      Collections.sort(lang, new LanguagesComparator());
 
       langSelectBox.setOptions(lang);
    }
@@ -242,5 +264,36 @@
       }
       uiApp.addMessage(new ApplicationMessage("UIUserProfileInputSet.msg.sucsesful.update.userprofile", args));
    }
+   
+   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;
+   }
+   
+   private class LanguagesComparator implements Comparator<SelectItemOption>
+   {
+      public int compare(SelectItemOption item0, SelectItemOption item1)
+      {
+         return item0.getLabel().compareToIgnoreCase(item1.getLabel());
+      }
+   }
 }



More information about the gatein-commits mailing list