ICU-3889 Only look for resources that are the same type as the root resource.
X-SVN-Rev: 18456
This commit is contained in:
parent
3879460320
commit
7dab5ba98b
@ -357,7 +357,64 @@ public abstract class UResourceBundle extends ResourceBundle{
|
|||||||
|
|
||||||
private static final ResourceCacheKey cacheKey = new ResourceCacheKey();
|
private static final ResourceCacheKey cacheKey = new ResourceCacheKey();
|
||||||
|
|
||||||
|
private static final int ROOT_MISSING = 0;
|
||||||
|
private static final int ROOT_ICU = 1;
|
||||||
|
private static final int ROOT_JAVA = 2;
|
||||||
|
|
||||||
|
private static SoftReference ROOT_CACHE;
|
||||||
|
|
||||||
|
private static int getRootType(String baseName, ClassLoader root)
|
||||||
|
{
|
||||||
|
Map m = null;
|
||||||
|
Integer rootType;
|
||||||
|
|
||||||
|
if (ROOT_CACHE != null) {
|
||||||
|
m = (Map) ROOT_CACHE.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m == null) {
|
||||||
|
m = new HashMap();
|
||||||
|
ROOT_CACHE = new SoftReference(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
rootType = (Integer) m.get(baseName);
|
||||||
|
|
||||||
|
if (rootType == null) {
|
||||||
|
String rootLocale = (baseName.indexOf('.')==-1) ? "root" : "";
|
||||||
|
UResourceBundle b = instantiateICUResource(baseName, rootLocale, root);
|
||||||
|
int rt = ROOT_ICU;
|
||||||
|
|
||||||
|
if (b == null) {
|
||||||
|
rt = ROOT_JAVA;
|
||||||
|
|
||||||
|
try {
|
||||||
|
b = new ResourceBundleWrapper(baseName, rootLocale, root);
|
||||||
|
} catch (MissingResourceException mre) {
|
||||||
|
rt = ROOT_MISSING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rootType = new Integer(rt);
|
||||||
|
m.put(baseName, rootType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootType.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setRootType(String baseName, int rootType)
|
||||||
|
{
|
||||||
|
Integer rt = new Integer(rootType);
|
||||||
|
Map m = null;
|
||||||
|
|
||||||
|
if (ROOT_CACHE != null) {
|
||||||
|
m = (Map) ROOT_CACHE.get();
|
||||||
|
} else {
|
||||||
|
m = new HashMap();
|
||||||
|
ROOT_CACHE = new SoftReference(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
m.put(baseName, rt);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a new resource bundle for the give base name, locale and class loader.
|
* Loads a new resource bundle for the give base name, locale and class loader.
|
||||||
@ -372,33 +429,52 @@ public abstract class UResourceBundle extends ResourceBundle{
|
|||||||
* @draft ICU 3.0
|
* @draft ICU 3.0
|
||||||
* @deprecated This is a draft API and might change in a future release of ICU.
|
* @deprecated This is a draft API and might change in a future release of ICU.
|
||||||
*/
|
*/
|
||||||
protected static synchronized UResourceBundle instantiateBundle(String baseName, String localeName, ClassLoader root, boolean disableFallback){
|
protected static synchronized UResourceBundle instantiateBundle(String baseName, String localeName, ClassLoader root, boolean disableFallback)
|
||||||
// first try to create an ICUResourceBundle
|
{
|
||||||
// the expectation is that most client using
|
|
||||||
// this interface will open an *.res file
|
|
||||||
UResourceBundle b = null;
|
UResourceBundle b = null;
|
||||||
if(disableFallback){
|
int rootType = getRootType(baseName, root);
|
||||||
ULocale defaultLocale = ULocale.getDefault();
|
|
||||||
String fullName = ICUResourceBundleReader.getFullName(baseName, localeName);
|
switch (rootType)
|
||||||
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
{
|
||||||
b = loadFromCache(cacheKey);
|
case ROOT_ICU:
|
||||||
if(b==null){
|
if(disableFallback) {
|
||||||
b = ICUResourceBundle.createBundle(baseName, localeName, root);
|
ULocale defaultLocale = ULocale.getDefault();
|
||||||
|
String fullName = ICUResourceBundleReader.getFullName(baseName, localeName);
|
||||||
|
|
||||||
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
||||||
addToCache(cacheKey, b);
|
b = loadFromCache(cacheKey);
|
||||||
|
|
||||||
|
if (b == null) {
|
||||||
|
b = ICUResourceBundle.createBundle(baseName, localeName, root);
|
||||||
|
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
||||||
|
addToCache(cacheKey, b);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
b = instantiateICUResource(baseName, localeName, root);
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
b = instantiateICUResource(baseName,localeName,root);
|
return b;
|
||||||
|
|
||||||
|
case ROOT_JAVA:
|
||||||
|
return new ResourceBundleWrapper(baseName, localeName, root);
|
||||||
|
|
||||||
|
default:
|
||||||
|
b = instantiateICUResource(baseName, localeName, root);
|
||||||
|
|
||||||
|
if (b == null) {
|
||||||
|
b = new ResourceBundleWrapper(baseName, localeName, root);
|
||||||
|
|
||||||
|
if (b == null){
|
||||||
|
throw new MissingResourceException("Could not find the bundle ", baseName, localeName);
|
||||||
|
} else {
|
||||||
|
setRootType(baseName, ROOT_JAVA);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setRootType(baseName, ROOT_ICU);
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
if(b==null){
|
|
||||||
// we can't find an *.res file .. so fallback to
|
|
||||||
// Java ResourceBundle loadeing
|
|
||||||
b = new ResourceBundleWrapper(baseName, localeName, root);
|
|
||||||
}
|
|
||||||
if(b==null){
|
|
||||||
throw new MissingResourceException("Could not find the bundle ", baseName,localeName );
|
|
||||||
}
|
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -418,12 +494,13 @@ public abstract class UResourceBundle extends ResourceBundle{
|
|||||||
* @deprecated This is a draft API and might change in a future release of ICU.
|
* @deprecated This is a draft API and might change in a future release of ICU.
|
||||||
*/
|
*/
|
||||||
// recursively build bundle
|
// recursively build bundle
|
||||||
protected static UResourceBundle instantiateICUResource(String baseName,String localeID, ClassLoader root){
|
protected static UResourceBundle instantiateICUResource(String baseName, String localeID, ClassLoader root){
|
||||||
ULocale defaultLocale = ULocale.getDefault();
|
ULocale defaultLocale = ULocale.getDefault();
|
||||||
String localeName = ULocale.getBaseName(localeID);
|
String localeName = ULocale.getBaseName(localeID);
|
||||||
String fullName = ICUResourceBundleReader.getFullName(baseName, localeName);
|
String fullName = ICUResourceBundleReader.getFullName(baseName, localeName);
|
||||||
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
||||||
UResourceBundle b = loadFromCache(cacheKey);
|
UResourceBundle b = loadFromCache(cacheKey);
|
||||||
|
|
||||||
// here we assume that java type resource bundle organization
|
// here we assume that java type resource bundle organization
|
||||||
// is required then the base name contains '.' else
|
// is required then the base name contains '.' else
|
||||||
// the resource organization is of ICU type
|
// the resource organization is of ICU type
|
||||||
@ -433,12 +510,14 @@ public abstract class UResourceBundle extends ResourceBundle{
|
|||||||
//
|
//
|
||||||
final String rootLocale = (baseName.indexOf('.')==-1) ? "root" : "";
|
final String rootLocale = (baseName.indexOf('.')==-1) ? "root" : "";
|
||||||
final String defaultID = ULocale.getDefault().toString();
|
final String defaultID = ULocale.getDefault().toString();
|
||||||
|
|
||||||
if(localeName.equals("")){
|
if(localeName.equals("")){
|
||||||
localeName = rootLocale;
|
localeName = rootLocale;
|
||||||
}
|
}
|
||||||
if (b == null) {
|
if (b == null) {
|
||||||
b = ICUResourceBundle.createBundle(baseName, localeName, root);
|
b = ICUResourceBundle.createBundle(baseName, localeName, root);
|
||||||
if(b==null){
|
|
||||||
|
if(b == null){
|
||||||
int i = localeName.lastIndexOf('_');
|
int i = localeName.lastIndexOf('_');
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
String temp = localeName.substring(0, i);
|
String temp = localeName.substring(0, i);
|
||||||
@ -460,16 +539,19 @@ public abstract class UResourceBundle extends ResourceBundle{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
UResourceBundle parent = null;
|
||||||
localeName = b.getLocaleID();
|
localeName = b.getLocaleID();
|
||||||
int i = localeName.lastIndexOf('_');
|
int i = localeName.lastIndexOf('_');
|
||||||
|
|
||||||
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
||||||
addToCache(cacheKey, b);
|
addToCache(cacheKey, b);
|
||||||
UResourceBundle parent = null;
|
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
parent = instantiateICUResource(baseName, localeName.substring(0, i), root);
|
parent = instantiateICUResource(baseName, localeName.substring(0, i), root);
|
||||||
}else{
|
}else{
|
||||||
parent = ICUResourceBundle.createBundle(baseName, rootLocale, root);
|
parent = ICUResourceBundle.createBundle(baseName, rootLocale, root);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!b.equals(parent)){
|
if(!b.equals(parent)){
|
||||||
b.setParent(parent);
|
b.setParent(parent);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user