Author: fmeschbe
Date: Tue Apr 5 07:38:51 2011
New Revision: 1088914
URL: http://svn.apache.org/viewvc?rev=1088914&view=rev
Log:
SLING-2047 Use proper parenting of the resource bundles (thus only returning
really known values for the keys instead of returning the key if the value is
missing) and use a pseudo root resource bundle returning the key if the value
is missing
Modified:
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
Modified:
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java?rev=1088914&r1=1088913&r2=1088914&view=diff
==============================================================================
---
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
(original)
+++
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
Tue Apr 5 07:38:51 2011
@@ -96,8 +96,7 @@ public class JcrResourceBundle extends R
@Override
protected Object handleGetObject(String key) {
- Object value = resources.get(key);
- return (value == null) ? key : value;
+ return resources.get(key);
}
private HashMap<String, Object> loadFully(
Modified:
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java?rev=1088914&r1=1088913&r2=1088914&view=diff
==============================================================================
---
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
(original)
+++
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
Tue Apr 5 07:38:51 2011
@@ -99,6 +99,12 @@ public class JcrResourceBundleProvider i
*/
private final Map<String, Map<Locale, ResourceBundle>> resourceBundleCache
= new HashMap<String, Map<Locale, ResourceBundle>>();
+ /**
+ * Return root resource bundle as created on-demand by
+ * {@link #getRootResourceBundle()}.
+ */
+ private ResourceBundle rootResourceBundle;
+
// ---------- ResourceBundleProvider
---------------------------------------
/**
@@ -272,6 +278,8 @@ public class JcrResourceBundleProvider i
Locale parentLocale = getParentLocale(locale);
if (parentLocale != null) {
bundle.setParent(getResourceBundleInternal(baseName,
parentLocale));
+ } else {
+ bundle.setParent(getRootResourceBundle());
}
return bundle;
@@ -306,6 +314,24 @@ public class JcrResourceBundleProvider i
}
/**
+ * Returns a ResourceBundle which is used as the root resource bundle, that
+ * is the ultimate parent:
+ * <ul>
+ * <li><code>getLocale()</code> returns Locale("", "", "")</li>
+ * <li><code>handleGetObject(String key)</code> returns the
<code>key</code></li>
+ * <li><code>getKeys()</code> returns an empty enumeration.
+ * </ul>
+ *
+ * @return The root resource bundle
+ */
+ private ResourceBundle getRootResourceBundle() {
+ if (rootResourceBundle == null) {
+ rootResourceBundle = new RootResourceBundle();
+ }
+ return rootResourceBundle;
+ }
+
+ /**
* Returns the resource resolver to access messages. This method logs into
* the repository and registers with the observation manager if not already
* done so. If unable to connect to the repository, <code>null</code> is