[jboss-svn-commits] JBoss Portal SVN: r5289 - in trunk/portlet/src/main/org/jboss/portal: portlet/container/info portlet/info portlet/test/support/info test/portlet/info

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Sep 28 20:27:57 EDT 2006


Author: julien at jboss.com
Date: 2006-09-28 20:27:48 -0400 (Thu, 28 Sep 2006)
New Revision: 5289

Modified:
   trunk/portlet/src/main/org/jboss/portal/portlet/container/info/ContainerPreferenceInfo.java
   trunk/portlet/src/main/org/jboss/portal/portlet/container/info/ContainerPreferencesInfo.java
   trunk/portlet/src/main/org/jboss/portal/portlet/container/info/PortletResourceBundleManager.java
   trunk/portlet/src/main/org/jboss/portal/portlet/info/PreferenceInfo.java
   trunk/portlet/src/main/org/jboss/portal/portlet/test/support/info/PreferenceInfoSupport.java
   trunk/portlet/src/main/org/jboss/portal/test/portlet/info/PreferenceInfoTest.java
Log:
JBPORTAL-1061 : Support localized description of portlet preference entries

Modified: trunk/portlet/src/main/org/jboss/portal/portlet/container/info/ContainerPreferenceInfo.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/container/info/ContainerPreferenceInfo.java	2006-09-28 22:58:14 UTC (rev 5288)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/container/info/ContainerPreferenceInfo.java	2006-09-29 00:27:48 UTC (rev 5289)
@@ -34,13 +34,15 @@
 
    private String key;
    private LocalizedString displayName;
+   private LocalizedString description;
    private Boolean readOnly;
    private Value value;
 
-   public ContainerPreferenceInfo(String key, LocalizedString displayName, boolean readOnly, Value value)
+   public ContainerPreferenceInfo(String key, LocalizedString displayName, LocalizedString description, boolean readOnly, Value value)
    {
       this.key = key;
       this.displayName = displayName;
+      this.description = description;
       this.readOnly = Boolean.valueOf(readOnly);
       this.value = value;
    }
@@ -55,6 +57,11 @@
       return displayName;
    }
 
+   public LocalizedString getDescription()
+   {
+      return description;
+   }
+
    public Boolean isReadOnly()
    {
       return readOnly;

Modified: trunk/portlet/src/main/org/jboss/portal/portlet/container/info/ContainerPreferencesInfo.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/container/info/ContainerPreferencesInfo.java	2006-09-28 22:58:14 UTC (rev 5288)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/container/info/ContainerPreferencesInfo.java	2006-09-29 00:27:48 UTC (rev 5289)
@@ -32,11 +32,8 @@
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
-import java.util.ResourceBundle;
-import java.util.MissingResourceException;
 
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
@@ -62,27 +59,9 @@
       {
          PreferenceMetaData prefMD = (PreferenceMetaData)i.next();
          Value value = new StringValue(prefMD.getValues());
-         String key = "javax.portlet.preference.description." + prefMD.getName();
-         Map m = new HashMap();
-         for (Iterator j = portletMD.getLanguages().getSupportedLocales().iterator(); j.hasNext();)
-         {
-            try
-            {
-               Locale locale = (Locale)j.next();
-               ResourceBundle bundle = bundleMgr.getResourceBundle(locale);
-               String localizedDisplayName = bundle.getString(key);
-               m.put(locale, localizedDisplayName);
-            }
-            catch (MissingResourceException ignore)
-            {
-            }
-         }
-         if (!m.containsKey(Locale.ENGLISH))
-         {
-            m.put(Locale.ENGLISH, prefMD.getName());
-         }
-         LocalizedString displayName = new LocalizedString(m, Locale.ENGLISH);
-         ContainerPreferenceInfo pref = new ContainerPreferenceInfo(prefMD.getName(), displayName, prefMD.isReadOnly(), value);
+         LocalizedString displayName = bundleMgr.getLocalizedValue("javax.portlet.preference.name." + prefMD.getName(), prefMD.getName());
+         LocalizedString description = bundleMgr.getLocalizedValue("javax.portlet.preference.description." + prefMD.getName(), prefMD.getName());
+         ContainerPreferenceInfo pref = new ContainerPreferenceInfo(prefMD.getName(), displayName, description, prefMD.isReadOnly(), value);
          content.put(pref.getKey(), pref);
       }
    }

Modified: trunk/portlet/src/main/org/jboss/portal/portlet/container/info/PortletResourceBundleManager.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/container/info/PortletResourceBundleManager.java	2006-09-28 22:58:14 UTC (rev 5288)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/container/info/PortletResourceBundleManager.java	2006-09-29 00:27:48 UTC (rev 5289)
@@ -25,12 +25,15 @@
 import org.jboss.portal.portlet.impl.jsr168.metadata.LanguagesMetaData;
 import org.jboss.portal.common.util.ParentChildResourceBundle;
 import org.jboss.portal.common.util.EmptyResourceBundle;
+import org.jboss.portal.common.util.LocalizedString;
 
 import java.util.ResourceBundle;
 import java.util.Map;
 import java.util.Locale;
 import java.util.HashMap;
 import java.util.MissingResourceException;
+import java.util.Collection;
+import java.util.Iterator;
 
 /**
  * Manage resource bundles for a portlet.
@@ -56,6 +59,9 @@
    /** */
    private ResourceBundle infoBundle;
 
+   /** */
+   private Collection supportedLocales;
+
    public PortletResourceBundleManager(ClassLoader classLoader, LanguagesMetaData metaData)
    {
       if (classLoader == null)
@@ -69,6 +75,7 @@
       this.classLoader = classLoader;
       this.baseName = metaData.getResourceBundle();
       this.localeBundles = new HashMap();
+      this.supportedLocales = metaData.getSupportedLocales();
 
       // Get the resource bundle containing the portlet info
       LanguagesMetaData.InfoMetaData infoMD = metaData.getInfo();
@@ -83,6 +90,47 @@
    }
 
    /**
+    * Return a localized value constructed from the various resource bundles. The supported locales of the
+    * manager are used in combination with the specified key. The default value is used if no value
+    * is found for the <code>Locale.ENGLISH</code>.
+    *
+    * @param key the key to lookup in the bundles
+    * @param defaultValue
+    * @return the localized string
+    * @throws IllegalArgumentException if the key of the default value is null
+    */
+   public LocalizedString getLocalizedValue(String key, String defaultValue) throws IllegalArgumentException
+   {
+      if (key == null)
+      {
+         throw new IllegalArgumentException("No null key accepted");
+      }
+      if (defaultValue == null)
+      {
+         throw new IllegalArgumentException("No null default value accepted");
+      }
+      Map m = new HashMap();
+      for (Iterator j = supportedLocales.iterator(); j.hasNext();)
+      {
+         try
+         {
+            Locale locale = (Locale)j.next();
+            ResourceBundle bundle = getResourceBundle(locale);
+            String localizedDisplayName = bundle.getString(key);
+            m.put(locale, localizedDisplayName);
+         }
+         catch (MissingResourceException ignore)
+         {
+         }
+      }
+      if (!m.containsKey(Locale.ENGLISH))
+      {
+         m.put(Locale.ENGLISH, defaultValue);
+      }
+      return new LocalizedString(m, Locale.ENGLISH);
+   }
+
+   /**
     * Return a bundle for the given locale. If the complete locale (language + country + variant) does not
     * exist then it falls back to (language + country) or (language) or the default file.
     * <p/>

Modified: trunk/portlet/src/main/org/jboss/portal/portlet/info/PreferenceInfo.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/info/PreferenceInfo.java	2006-09-28 22:58:14 UTC (rev 5288)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/info/PreferenceInfo.java	2006-09-29 00:27:48 UTC (rev 5289)
@@ -49,6 +49,14 @@
    LocalizedString getDisplayName();
 
    /**
+    * Retrieves the localized description of the described preference.
+    *
+    * @return the localized description of the described preference.
+    * @see LocalizedString
+    */
+   LocalizedString getDescription();
+
+   /**
     * Return true if the preference is read-only, false otherwise or null if it cannot be determined.
     *
     * @return <code>true</code> if the described preference is read-only, <code>false</code> otherwise.

Modified: trunk/portlet/src/main/org/jboss/portal/portlet/test/support/info/PreferenceInfoSupport.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/test/support/info/PreferenceInfoSupport.java	2006-09-28 22:58:14 UTC (rev 5288)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/test/support/info/PreferenceInfoSupport.java	2006-09-29 00:27:48 UTC (rev 5289)
@@ -34,14 +34,25 @@
 public class PreferenceInfoSupport implements PreferenceInfo
 {
 
+   /** . */
    private final String key;
+
+   /** . */
+   private LocalizedString displayName;
+
+   /** . */
    private LocalizedString description;
+
+   /** . */
    private Boolean readOnly;
+
+   /** . */
    private Value defaultValue;
 
    public PreferenceInfoSupport(String key)
    {
       this.key = key;
+      this.displayName = new LocalizedString("Display name of " + key, Locale.ENGLISH);
       this.description = new LocalizedString("Description of " + key, Locale.ENGLISH);
       this.readOnly = null;
       this.defaultValue = null;
@@ -50,6 +61,7 @@
    public PreferenceInfoSupport(String key, Value defaultValue)
    {
       this.key = key;
+      this.displayName = new LocalizedString("Display name of " + key, Locale.ENGLISH);
       this.description = new LocalizedString("Description of " + key, Locale.ENGLISH);
       this.readOnly = Boolean.FALSE;
       this.defaultValue = defaultValue;
@@ -58,6 +70,7 @@
    public PreferenceInfoSupport(String key, Value defaultValue, Boolean readOnly)
    {
       this.key = key;
+      this.displayName = new LocalizedString("Display name of " + key, Locale.ENGLISH);
       this.description = new LocalizedString("Description of " + key, Locale.ENGLISH);
       this.readOnly = readOnly;
       this.defaultValue = defaultValue;
@@ -70,6 +83,11 @@
 
    public LocalizedString getDisplayName()
    {
+      return displayName;
+   }
+
+   public LocalizedString getDescription()
+   {
       return description;
    }
 
@@ -92,4 +110,14 @@
    {
       this.defaultValue = defaultValue;
    }
+
+   public void setDisplayName(LocalizedString displayName)
+   {
+      this.displayName = displayName;
+   }
+
+   public void setDescription(LocalizedString description)
+   {
+      this.description = description;
+   }
 }

Modified: trunk/portlet/src/main/org/jboss/portal/test/portlet/info/PreferenceInfoTest.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/test/portlet/info/PreferenceInfoTest.java	2006-09-28 22:58:14 UTC (rev 5288)
+++ trunk/portlet/src/main/org/jboss/portal/test/portlet/info/PreferenceInfoTest.java	2006-09-29 00:27:48 UTC (rev 5289)
@@ -59,28 +59,26 @@
 
    public Result execute(ServerInvocation invocation)
    {
-
       AssertResult result = new AssertResult();
       result.execute(new AssertResult.Test()
       {
          public void run() throws Exception
          {
-            PortletContainer container = (PortletContainer)registry.getPortletContainer("/test-info.PreferenceInfoPortlet");
+            PortletContainer container = registry.getPortletContainer("/test-info.PreferenceInfoPortlet");
+
+            //
             PortletInfo info = container.getInfo();
-            //MetaInfo metaInfo = info.getMeta();
             PreferencesInfo prefsInfo = info.getPreferences();
 
-
+            //
             PreferenceInfo prefInfo = prefsInfo.getPreference("localized_pref");
-
-            //localized stuff (from bundle)
             assertEquals("localized_pref", prefInfo.getKey());
+            assertEquals("english localized description", prefInfo.getDescription().getString(Locale.ENGLISH, false));
+            assertEquals("polish localized description", prefInfo.getDescription().getString(new Locale("pl"), false));
+            assertEquals("english_localized_name", prefInfo.getDisplayName().getString(Locale.ENGLISH, false));
+            assertEquals("polish_localized_name", prefInfo.getDisplayName().getString(new Locale("pl"), false));
 
-            //TODO:localized name and value
-            assertEquals("english localized description", prefInfo.getDisplayName().getString(Locale.ENGLISH, false));
-            assertEquals("polish localized description", prefInfo.getDisplayName().getString(new Locale("pl"), false));
-
-            //usual prefs
+            //
             Set keys = prefsInfo.getKeys();
             assertTrue(keys.contains("localized_pref"));
             assertTrue(keys.contains("single_pref"));
@@ -88,26 +86,28 @@
             assertTrue(keys.contains("single_pref_bis"));
             assertTrue(keys.contains("multi_pref_bis"));
 
-
-
+            //
             prefInfo = prefsInfo.getPreference("single_pref");
             assertEquals("single_pref", prefInfo.getKey());
             String[] values = prefInfo.getDefaultValue().asStringArray();
             assertEquals(new String[] {"single_pref_value"}, values);
             assertTrue(!prefInfo.isReadOnly().booleanValue());
 
+            //
             prefInfo = prefsInfo.getPreference("multi_pref");
             assertEquals("multi_pref", prefInfo.getKey());
             values = prefInfo.getDefaultValue().asStringArray();
             assertEquals(new String[] {"multi_pref_value_1", "multi_pref_value_2"}, values);
             assertTrue(!prefInfo.isReadOnly().booleanValue());
 
+            //
             prefInfo = prefsInfo.getPreference("single_pref_bis");
             assertEquals("single_pref_bis", prefInfo.getKey());
             values = prefInfo.getDefaultValue().asStringArray();
             assertEquals(new String[] {"single_pref_value"}, values);
             assertTrue(prefInfo.isReadOnly().booleanValue());
 
+            //
             prefInfo = prefsInfo.getPreference("multi_pref_bis");
             assertEquals("multi_pref_bis", prefInfo.getKey());
             values = prefInfo.getDefaultValue().asStringArray();
@@ -115,7 +115,6 @@
             assertTrue(prefInfo.isReadOnly().booleanValue());
          }
       });
-
       return result;
    }
 }




More information about the jboss-svn-commits mailing list