[seam-commits] Seam SVN: r10550 - in branches/community/Seam_2_1/src/main/org/jboss/seam: theme and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Apr 21 11:55:05 EDT 2009


Author: norman.richards at jboss.com
Date: 2009-04-21 11:55:05 -0400 (Tue, 21 Apr 2009)
New Revision: 10550

Modified:
   branches/community/Seam_2_1/src/main/org/jboss/seam/international/Messages.java
   branches/community/Seam_2_1/src/main/org/jboss/seam/theme/Theme.java
Log:
JBSEAM-4131

Modified: branches/community/Seam_2_1/src/main/org/jboss/seam/international/Messages.java
===================================================================
--- branches/community/Seam_2_1/src/main/org/jboss/seam/international/Messages.java	2009-04-21 13:12:21 UTC (rev 10549)
+++ branches/community/Seam_2_1/src/main/org/jboss/seam/international/Messages.java	2009-04-21 15:55:05 UTC (rev 10550)
@@ -4,9 +4,7 @@
 import static org.jboss.seam.annotations.Install.BUILT_IN;
 
 import java.util.AbstractMap;
-import java.util.Collections;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.MissingResourceException;
@@ -20,11 +18,12 @@
 import org.jboss.seam.annotations.Scope;
 import org.jboss.seam.annotations.intercept.BypassInterceptors;
 import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.Interpolator;
 import org.jboss.seam.core.SeamResourceBundle;
 
 /**
- * Factory for a Map that contains interpolated messages defined in the
- * Seam ResourceBundle.
+ * Factory for a Map that contains interpolated messages defined in the Seam
+ * ResourceBundle.
  * 
  * @see org.jboss.seam.core.SeamResourceBundle
  * 
@@ -33,101 +32,87 @@
 @Scope(ScopeType.STATELESS)
 @BypassInterceptors
 @Name("org.jboss.seam.international.messagesFactory")
- at Install(precedence=BUILT_IN)
-public class Messages
-{
-   //TODO: now we have ELResolver, it doesn't *have* to be a Map...
-      
-   protected Map createMap() 
-   {  
-	  // AbstractMap uses the implementation of entrySet to perform all its 
-	  // operations - for a resource bundle this is very inefficient for keys
-      return new AbstractMap<String, String>()
-      {
-         private java.util.ResourceBundle bundle = SeamResourceBundle.getBundle();
-         
-         @Override
-         public String get(Object key) 
-         {
-            if (key instanceof String)
-            {
-               String resourceKey = (String) key;
-               String resource=null;
-               if (bundle!=null)
-               {
-                  try
-                  {
-                     resource = bundle.getString(resourceKey);
-                  }
-                  catch (MissingResourceException mre)
-                  {
-                     //Just swallow
-                  }
-               }
-               return resource==null ? resourceKey : resource;
+ at Install(precedence = BUILT_IN)
+public class Messages {
+    protected Map<String, String> createMap() {
+        final java.util.ResourceBundle bundle = SeamResourceBundle.getBundle();
+
+        if (bundle == null) {
+            return null;
+        }
+
+        return new AbstractMap<String, String>() {
+            @Override
+            public String get(Object key) {
+                if (key instanceof String) {
+                    String resourceKey = (String) key;
+
+                    String resource;
+                    try {
+                        resource = bundle.getString(resourceKey);
+                    } catch (MissingResourceException mre) {
+                        return resourceKey;
+                    }
+                    if (resource == null) {
+                        return resourceKey;
+                    } else {
+                        return Interpolator.instance().interpolate(resource);
+                    }
+                } else {
+                    return null;
+                }
             }
-            else
-            {
-               return null;
+
+            @Override
+            public Set<Map.Entry<String, String>> entrySet() {
+                Set<Map.Entry<String, String>> entrySet = new HashSet<Map.Entry<String, String>>();
+
+                Enumeration<String> keys = bundle.getKeys();
+
+                while (keys.hasMoreElements()) {
+                    final String key = keys.nextElement();
+
+                    entrySet.add(new Map.Entry<String, String>() {
+
+                        public String getKey() {
+                            return key;
+                        }
+
+                        public String getValue() {
+                            return get(key);
+                        }
+
+                        public String setValue(String arg0) {
+                            throw new UnsupportedOperationException("not implemented");
+                        }
+                    });
+                }
+
+                return entrySet;
             }
-         }
-         
-         @Override
-         public Set<Map.Entry<String, String>> entrySet() 
-         {
-        	Enumeration<String> keys = bundle.getKeys();  
-            Map<String, String> map = new HashMap<String, String>();
-            while ( keys.hasMoreElements() )
-            {
-               String key = keys.nextElement();
-               map.put( key, get(key) );
-            }  
-            return Collections.unmodifiableSet(map.entrySet());
-         }
 
-         @Override
-         public boolean containsKey(Object key)
-         {
-            return get(key) != null;
-         }
+        };
 
-         @Override
-         public Set<String> keySet()
-         {
-            Enumeration<String> keys = bundle.getKeys();  
-            return new HashSet<String>(Collections.list(keys));
-         }
+    }
 
-         @Override
-         public int size()
-         {
-            return keySet().size();
-         }
-         
-      };
-   }
+    /**
+     * Create the Map and cache it in the EVENT scope. No need to cache it in
+     * the SESSION scope, since it is inexpensive to create.
+     * 
+     * @return a Map that interpolates messages in the Seam ResourceBundle
+     */
+    @Factory(value = "org.jboss.seam.international.messages", autoCreate = true, scope = EVENT)
+    public Map<String, String> getMessages() {
+        return createMap();
+    }
 
-   /**
-    * Create the Map and cache it in the EVENT scope. No need to cache
-    * it in the SESSION scope, since it is inexpensive to create.
-    * 
-    * @return a Map that interpolates messages in the Seam ResourceBundle
-    */
-   @Factory(value="org.jboss.seam.international.messages", autoCreate=true, scope=EVENT)
-   public Map<String, String> getMessages()
-   {
-      return createMap();
-   }
-   
-   /**
-    * @return the message Map instance
-    */
-   public static Map<String, String> instance()
-   {
-      if ( !Contexts.isSessionContextActive() )
-      {
-         throw new IllegalStateException("no event context active");
-      }
-      return (Map<String, String>) Component.getInstance("org.jboss.seam.international.messages", true);
-   }
+    /**
+     * @return the message Map instance
+     */
+    public static Map<String, String> instance() {
+        if (!Contexts.isSessionContextActive()) {
+            throw new IllegalStateException("no event context active");
+        }
+        return (Map<String, String>) Component.getInstance("org.jboss.seam.international.messages", true);
+    }
 }

Modified: branches/community/Seam_2_1/src/main/org/jboss/seam/theme/Theme.java
===================================================================
--- branches/community/Seam_2_1/src/main/org/jboss/seam/theme/Theme.java	2009-04-21 13:12:21 UTC (rev 10549)
+++ branches/community/Seam_2_1/src/main/org/jboss/seam/theme/Theme.java	2009-04-21 15:55:05 UTC (rev 10550)
@@ -71,7 +71,6 @@
                         }
 
                         public String getValue() {
-                            System.out.println("GET VALUE FOR " + key);
                             return get(key);
                         }
 




More information about the seam-commits mailing list