mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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:
@@ -482,7 +482,7 @@ public class Application
|
|||||||
{
|
{
|
||||||
locale = Locale.getDefault();
|
locale = Locale.getDefault();
|
||||||
}
|
}
|
||||||
bundle = ResourceBundleWrapper.findSharedResourceBundle(MESSAGE_BUNDLE, locale);
|
bundle = ResourceBundleWrapper.getResourceBundle(MESSAGE_BUNDLE, locale);
|
||||||
|
|
||||||
session.setAttribute(MESSAGE_BUNDLE, bundle);
|
session.setAttribute(MESSAGE_BUNDLE, bundle);
|
||||||
}
|
}
|
||||||
@@ -512,7 +512,7 @@ public class Application
|
|||||||
{
|
{
|
||||||
locale = Locale.getDefault();
|
locale = Locale.getDefault();
|
||||||
}
|
}
|
||||||
bundle = ResourceBundleWrapper.findSharedResourceBundle(MESSAGE_BUNDLE, locale);
|
bundle = ResourceBundleWrapper.getResourceBundle(MESSAGE_BUNDLE, locale);
|
||||||
|
|
||||||
session.put(MESSAGE_BUNDLE, bundle);
|
session.put(MESSAGE_BUNDLE, bundle);
|
||||||
}
|
}
|
||||||
|
@@ -17,9 +17,7 @@
|
|||||||
package org.alfresco.web.app;
|
package org.alfresco.web.app;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.ResourceBundle;
|
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
|
* Wrapper around Alfresco Resource Bundle objects. Used to catch and handle missing
|
||||||
* resource exception to help identify missing I18N strings in client apps.
|
* 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
|
* @author Kevin Roast
|
||||||
*/
|
*/
|
||||||
@@ -42,8 +37,6 @@ public final class ResourceBundleWrapper extends ResourceBundle
|
|||||||
|
|
||||||
private ResourceBundle delegate;
|
private ResourceBundle delegate;
|
||||||
|
|
||||||
private static Map<String, ResourceBundle> cache = new HashMap<String, ResourceBundle>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* 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
|
* Factory method to get a named wrapped resource bundle for a particular locale.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
* @param name Bundle name
|
* @param name Bundle name
|
||||||
* @param locale Locale to retrieve bundle for
|
* @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 = ResourceBundle.getBundle(name, locale);
|
||||||
|
|
||||||
ResourceBundle bundle = cache.get(key);
|
|
||||||
if (bundle == null)
|
if (bundle == null)
|
||||||
{
|
{
|
||||||
// we can safely use a weak synchronization point here - i.e. it doesn't actually matter
|
throw new AlfrescoRuntimeException("Unable to load Alfresco messages bundle: " + name);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bundle;
|
// apply our wrapper to catch MissingResourceException
|
||||||
|
return new ResourceBundleWrapper(bundle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user