backed out previous checkin

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2413 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-02-16 14:42:36 +00:00
parent 776d837c16
commit 3c9f4d77e2
2 changed files with 9 additions and 34 deletions

View File

@@ -482,7 +482,7 @@ public class Application
{
locale = Locale.getDefault();
}
bundle = ResourceBundleWrapper.findSharedResourceBundle(MESSAGE_BUNDLE, locale);
bundle = ResourceBundleWrapper.getResourceBundle(MESSAGE_BUNDLE, locale);
session.setAttribute(MESSAGE_BUNDLE, bundle);
}
@@ -512,7 +512,7 @@ public class Application
{
locale = Locale.getDefault();
}
bundle = ResourceBundleWrapper.findSharedResourceBundle(MESSAGE_BUNDLE, locale);
bundle = ResourceBundleWrapper.getResourceBundle(MESSAGE_BUNDLE, locale);
session.put(MESSAGE_BUNDLE, bundle);
}

View File

@@ -17,9 +17,7 @@
package org.alfresco.web.app;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
@@ -30,9 +28,6 @@ import org.apache.log4j.Priority;
/**
* Wrapper around Alfresco Resource Bundle objects. Used to catch and handle missing
* resource exception to help identify missing I18N strings in client apps.
* <p>
* Also provides a factory method to get/create a shared instance to a named resource
* bundle for a particular locale.
*
* @author Kevin Roast
*/
@@ -42,8 +37,6 @@ public final class ResourceBundleWrapper extends ResourceBundle
private ResourceBundle delegate;
private static Map<String, ResourceBundle> cache = new HashMap<String, ResourceBundle>();
/**
* Constructor
*
@@ -81,40 +74,22 @@ public final class ResourceBundleWrapper extends ResourceBundle
}
/**
* Factory method to get/create a shared instance to a named resource bundle for a
* particular locale. A static cache of language bundles is used to save memory, as each
* bundle consumes >300K per user and they are read only objects.
* Factory method to get a named wrapped resource bundle for a particular locale.
*
* @param name Bundle name
* @param locale Locale to retrieve bundle for
*
* @return Shared ResourceBundle instance for specified locale
* @return Wrapped ResourceBundle instance for specified locale
*/
public static ResourceBundle findSharedResourceBundle(String name, Locale locale)
public static ResourceBundle getResourceBundle(String name, Locale locale)
{
String key = name + '_' + locale;
ResourceBundle bundle = cache.get(key);
ResourceBundle bundle = ResourceBundle.getBundle(name, locale);
if (bundle == null)
{
// we can safely use a weak synchronization point here - i.e. it doesn't actually matter
// if more than one thread loads and caches the same bundle if a race condition occurs
synchronized (cache)
{
bundle = ResourceBundle.getBundle(name, locale);
if (bundle == null)
{
throw new AlfrescoRuntimeException("Unable to load Alfresco messages bundle: " + name);
}
// apply our wrapper to catch MissingResourceException
bundle = new ResourceBundleWrapper(bundle);
// cache the bundle for later use
cache.put(key, bundle);
}
throw new AlfrescoRuntimeException("Unable to load Alfresco messages bundle: " + name);
}
return bundle;
// apply our wrapper to catch MissingResourceException
return new ResourceBundleWrapper(bundle);
}
}