diff --git a/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java b/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java
index 95a9b7ed05..bda950b379 100644
--- a/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java
+++ b/framework/base/src/base/org/ofbiz/base/util/UtilProperties.java
@@ -20,6 +20,8 @@ package org.ofbiz.base.util;
import java.net.URL;
import java.text.MessageFormat;
+import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -31,8 +33,13 @@ import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javolution.util.FastMap;
import javolution.util.FastSet;
+import org.ofbiz.base.location.FlexibleLocation;
import org.ofbiz.base.util.collections.FlexibleProperties;
import org.ofbiz.base.util.collections.ResourceBundleMapWrapper;
import org.ofbiz.base.util.string.FlexibleStringExpander;
@@ -123,21 +130,9 @@ public class UtilProperties implements java.io.Serializable {
public static String getPropertyValue(String resource, String name) {
if (resource == null || resource.length() <= 0) return "";
if (name == null || name.length() <= 0) return "";
- FlexibleProperties properties = resourceCache.get(resource);
+ Properties properties = getProperties(resource);
if (properties == null) {
- try {
- URL url = UtilURL.fromResource(resource);
-
- if (url == null) return "";
- properties = FlexibleProperties.makeFlexibleProperties(url);
- resourceCache.put(resource, properties);
- } catch (MissingResourceException e) {
- Debug.log(e.getMessage(), module);
- }
- }
- if (properties == null) {
- Debug.log("[UtilProperties.getPropertyValue] could not find resource: " + resource, module);
return "";
}
@@ -186,12 +181,12 @@ public class UtilProperties implements java.io.Serializable {
public static Properties getProperties(URL url) {
if (url == null)
return null;
- FlexibleProperties properties = resourceCache.get(url.toString());
+ FlexibleProperties properties = urlCache.get(url.toString());
if (properties == null) {
try {
properties = FlexibleProperties.makeFlexibleProperties(url);
- resourceCache.put(url.toString(), properties);
+ urlCache.put(url.toString(), properties);
} catch (MissingResourceException e) {
Debug.log(e.getMessage(), module);
}
@@ -266,18 +261,9 @@ public class UtilProperties implements java.io.Serializable {
public static String getPropertyValue(URL url, String name) {
if (url == null) return "";
if (name == null || name.length() <= 0) return "";
- FlexibleProperties properties = urlCache.get(url.toString());
+ Properties properties = getProperties(url);
if (properties == null) {
- try {
- properties = FlexibleProperties.makeFlexibleProperties(url);
- urlCache.put(url.toString(), properties);
- } catch (MissingResourceException e) {
- Debug.log(e.getMessage(), module);
- }
- }
- if (properties == null) {
- Debug.log("[UtilProperties.getPropertyValue] could not find resource: " + url, module);
return null;
}
@@ -303,18 +289,9 @@ public class UtilProperties implements java.io.Serializable {
if (url == null) return "";
if (name == null || name.length() <= 0) return "";
- FlexibleProperties properties = urlCache.get(url.toString());
+ Properties properties = getProperties(url);
if (properties == null) {
- try {
- properties = FlexibleProperties.makeFlexibleProperties(url);
- urlCache.put(url.toString(), properties);
- } catch (MissingResourceException e) {
- Debug.log(e.getMessage(), module);
- }
- }
- if (properties == null) {
- Debug.log("[UtilProperties.getPropertyValue] could not find resource: " + url, module);
return null;
}
@@ -344,22 +321,9 @@ public class UtilProperties implements java.io.Serializable {
public static void setPropertyValue(String resource, String name, String value) {
if (resource == null || resource.length() <= 0) return;
if (name == null || name.length() <= 0) return;
- FlexibleProperties properties = (FlexibleProperties) resourceCache.get(resource);
+ Properties properties = getProperties(resource);
if (properties == null) {
- try {
- URL url = UtilURL.fromResource(resource);
-
- if (url == null) return;
- properties = FlexibleProperties.makeFlexibleProperties(url);
- resourceCache.put(resource, properties);
- } catch (MissingResourceException e) {
- Debug.log(e.getMessage(), module);
- }
- }
-
- if (properties == null) {
- Debug.log("[UtilProperties.setPropertyValue] could not find resource: " + resource, module);
return;
}
@@ -539,6 +503,9 @@ public class UtilProperties implements java.io.Serializable {
}
bundleMap = new ResourceBundleMapWrapper.InternalRbmWrapper(bundle);
if (bundleMap != null) {
+ // TODO: Make this smarter by checking the Locale of the ResourceBundle -
+ // there might be an instance of this bundle already in the cache.
+ // See http://java.sun.com/j2se/1.4.2/docs/api/java/util/ResourceBundle.html#getLocale()
bundleLocaleCache.put(resourceCacheKey, bundleMap);
}
}
@@ -555,7 +522,7 @@ public class UtilProperties implements java.io.Serializable {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
ResourceBundle bundle = null;
try {
- bundle = ResourceBundle.getBundle(resource, locale, loader);
+ bundle = XmlResourceBundle.getBundle(resource, locale, loader);
} catch (MissingResourceException e) {
String resourceFullName = resource + "_" + locale.toString();
if (!resourceNotFoundMessagesShown.contains(resourceFullName)) {
@@ -640,4 +607,152 @@ public class UtilProperties implements java.io.Serializable {
return properties;
}
+
+ /**
+ * Custom ResourceBundle class. This class reads XML properties files and supports
+ * the OFBiz component:// location protocol.
The format of the XML
+ * properties file is:
+ * <resource>
+ * where "locale 1", "locale 2" are valid Locale strings.
+ * <property key="key">
+ * <value xml:lang="locale 1">Some value</value>
+ * <value xml:lang="locale 2">Some value</value>
+ * ...
+ * </property>
+ * ...
+ * </resource>
This method override behaves differently than the
+ * ResourceBundle method. The method calls ResourceBundle.getBundle(...) first
+ * - to preserve the original behavior. If null is returned, then the method
+ * attempts to get an XML resource. The resource search starts with the
+ * specified locale, then the system locale, and finally the locale specified
+ * in the general.properties locale.properties.fallback property.