svn commit: r674387 - in /ofbiz/trunk/framework: base/src/base/org/ofbiz/base/util/UtilProperties.java base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java widget/src/org/ofbiz/widget/screen/ModelScreenAction.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r674387 - in /ofbiz/trunk/framework: base/src/base/org/ofbiz/base/util/UtilProperties.java base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java widget/src/org/ofbiz/widget/screen/ModelScreenAction.java

adrianc
Author: adrianc
Date: Sun Jul  6 20:21:18 2008
New Revision: 674387

URL: http://svn.apache.org/viewvc?rev=674387&view=rev
Log:
Improved screen widget UI label rendering - now expands expressions contained in UI labels (${...}).

Modified:
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java?rev=674387&r1=674386&r2=674387&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java Sun Jul  6 20:21:18 2008
@@ -503,6 +503,17 @@
         return new ResourceBundleMapWrapper(getResourceBundle(resource, locale));
     }
 
+    /** Returns the specified resource/properties file as a Map with the original
+     *  ResourceBundle in the Map under the key _RESOURCE_BUNDLE_
+     * @param resource The name of the resource - can be a file, class, or URL
+     * @param locale The locale that the given resource will correspond to
+     * @param context The screen rendering context
+     * @return Map containing all entries in The ResourceBundle
+     */
+    public static Map<String, Object> getResourceBundleMap(String resource, Locale locale, Map<String, Object> context) {
+        return new ResourceBundleMapWrapper(getResourceBundle(resource, locale), context);
+    }
+
     /** Returns the specified resource/properties file.<p>Note that this method
      * will return a Properties instance for the specified locale <em>only</em> -
      * if you need <a href="http://www.w3.org/International/">I18n</a> properties, then use

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java?rev=674387&r1=674386&r2=674387&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java Sun Jul  6 20:21:18 2008
@@ -28,7 +28,7 @@
 import java.util.Set;
 
 import org.ofbiz.base.util.UtilProperties;
-
+import org.ofbiz.base.util.string.FlexibleStringExpander;
 
 /**
  * Generic ResourceBundle Map Wrapper, given ResourceBundle allows it to be used as a Map
@@ -38,6 +38,7 @@
     
     protected MapStack<String> rbmwStack;
     protected ResourceBundle initialResourceBundle;
+    protected Map<String, Object> context;
 
     protected ResourceBundleMapWrapper() {
         rbmwStack = MapStack.create();
@@ -51,8 +52,7 @@
         this.rbmwStack = MapStack.create(initialInternalRbmWrapper);
     }
     
-    /**
-     * When creating new from a ResourceBundle the one passed to the constructor should be the most specific or local ResourceBundle, with more common ones pushed onto the stack progressively.
+    /** When creating new from a ResourceBundle the one passed to the constructor should be the most specific or local ResourceBundle, with more common ones pushed onto the stack progressively.
      */
     public ResourceBundleMapWrapper(ResourceBundle initialResourceBundle) {
         if (initialResourceBundle == null) {
@@ -62,6 +62,17 @@
         this.rbmwStack = MapStack.create(new InternalRbmWrapper(initialResourceBundle));
     }
     
+    /** When creating new from a ResourceBundle the one passed to the constructor should be the most specific or local ResourceBundle, with more common ones pushed onto the stack progressively.
+     */
+    public ResourceBundleMapWrapper(ResourceBundle initialResourceBundle, Map<String, Object> context) {
+        if (initialResourceBundle == null) {
+            throw new IllegalArgumentException("Cannot create ResourceBundleMapWrapper with a null initial ResourceBundle.");
+        }
+        this.initialResourceBundle = initialResourceBundle;
+        this.rbmwStack = MapStack.create(new InternalRbmWrapper(initialResourceBundle));
+        this.context = context;
+    }
+    
     /** Puts ResourceBundle on the BOTTOM of the stack (bottom meaning will be overriden by higher layers on the stack, ie everything else already there) */
     public void addBottomResourceBundle(ResourceBundle topResourceBundle) {
         this.rbmwStack.addToBottom(new InternalRbmWrapper(topResourceBundle));
@@ -107,6 +118,11 @@
         Object value = this.rbmwStack.get(arg0);
         if (value == null) {
             value = arg0;
+        } else {
+            String str = (String) value;
+            if (str.contains("${") && context != null) {
+                return FlexibleStringExpander.expandString(str, context);
+            }
         }
         return value;
     }
@@ -114,7 +130,7 @@
         return this.rbmwStack.isEmpty();
     }
     public Set<String> keySet() {
-        return this.keySet();
+        return this.rbmwStack.keySet();
     }
     public Object put(String key, Object value) {
         return this.rbmwStack.put(key, value);

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java?rev=674387&r1=674386&r2=674387&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java Sun Jul  6 20:21:18 2008
@@ -25,8 +25,8 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
-import java.util.regex.PatternSyntaxException;
 import java.util.TimeZone;
+import java.util.regex.PatternSyntaxException;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSession;
@@ -47,8 +47,8 @@
 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
 import org.ofbiz.base.util.collections.ResourceBundleMapWrapper;
 import org.ofbiz.base.util.string.FlexibleStringExpander;
-import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.finder.ByAndFinder;
 import org.ofbiz.entity.finder.ByConditionFinder;
 import org.ofbiz.entity.finder.EntityFinderUtil;
@@ -300,7 +300,7 @@
             
             ResourceBundleMapWrapper existingPropMap = (ResourceBundleMapWrapper) this.mapNameAcsr.get(context);
             if (existingPropMap == null) {
-                this.mapNameAcsr.put(context, UtilProperties.getResourceBundleMap(resource, locale));
+                this.mapNameAcsr.put(context, UtilProperties.getResourceBundleMap(resource, locale, context));
             } else {
                 existingPropMap.addBottomResourceBundle(resource);
             }
@@ -310,7 +310,7 @@
                 if (globalCtx != null) {
                     ResourceBundleMapWrapper globalExistingPropMap = (ResourceBundleMapWrapper) this.mapNameAcsr.get(globalCtx);
                     if (globalExistingPropMap == null) {
-                        this.mapNameAcsr.put(globalCtx, UtilProperties.getResourceBundleMap(resource, locale));
+                        this.mapNameAcsr.put(globalCtx, UtilProperties.getResourceBundleMap(resource, locale, context));
                     } else {
                         // is it the same object? if not add it in here too...
                         if (existingPropMap != globalExistingPropMap) {