ICU-3480 fix bugs found while updating the locale data

X-SVN-Rev: 14230
This commit is contained in:
Ram Viswanadha 2003-12-31 21:23:41 +00:00
parent 450d73e833
commit 7c4b0cdef2
2 changed files with 50 additions and 10 deletions

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/ICUListResourceBundle.java,v $
* $Date: 2003/11/21 00:23:35 $
* $Revision: 1.17 $
* $Date: 2003/12/31 21:23:41 $
* $Revision: 1.18 $
*
*******************************************************************************
*/
@ -158,7 +158,7 @@ public class ICUListResourceBundle extends ListResourceBundle {
return data;
}
private static char[] readToEOS(InputStreamReader stream) {
private static char[] readToEOS(InputStreamReader stream)throws Exception {
ArrayList vec = new ArrayList();
int count = 0;
int pos = 0;
@ -178,7 +178,7 @@ public class ICUListResourceBundle extends ListResourceBundle {
} while (pos < length);
}
catch (IOException e) {
e.printStackTrace();
throw e;
}
vec.add(buffer);
count += pos;
@ -260,7 +260,7 @@ public class ICUListResourceBundle extends ListResourceBundle {
public ResourceString(String name){
resName=name;
}
public Object getResource(Object obj){
public Object getResource(Object obj) throws Exception{
if(expanded==null){
// Resource strings are always UTF-8
InputStream stream = obj.getClass().getResourceAsStream(resName);
@ -316,7 +316,12 @@ public class ICUListResourceBundle extends ListResourceBundle {
//if not we donot guarantee that this will work
int j = className.lastIndexOf(".");
packageName=className.substring(0,j);
bundleName=className.substring(j+1,className.indexOf("_"));
int underScoreIndex = className.indexOf("_");
if(underScoreIndex>=0){
bundleName=className.substring(j+1,className.indexOf("_"));
}else{
bundleName = className.substring(j+1,className.length());
}
keyPath=pathToResource.substring(i+1);
if(i!=-1){
@ -324,14 +329,24 @@ public class ICUListResourceBundle extends ListResourceBundle {
}else{
locale=keyPath;
keyPath=parentKey;
className=packageName+"."+bundleName+"_"+locale;
if(locale==null || locale.equals("root")){
className=packageName+"."+bundleName;
}else{
className=packageName+"."+bundleName+"_"+ locale;
}
}
}
ResourceBundle bundle = null;
// getResourceBundle guarantees that the CLASSPATH will be searched
// for loading the resource with name <bundleName>_<localeName>.class
bundle = ICULocaleData.getResourceBundle(packageName,bundleName,locale);
if(locale==null || locale.equals("root")){
bundle = ICULocaleData.getResourceBundle(packageName,bundleName,"");
}else{
bundle = ICULocaleData.getResourceBundle(packageName,bundleName,locale);
}
return findResource(bundle, className, parentKey, index, keyPath, visited);

View File

@ -193,11 +193,13 @@ public class ICULocaleData {
if (b == null) {
ResourceBundle parent = null;
int i = name.lastIndexOf('_');
final Locale rootLocale = new Locale("", "", "");
if (i != -1) {
parent = instantiate(name.substring(0, i));
}
try {
final Locale rootLocale = new Locale("", "", "");
Locale locale = rootLocale;
i = name.indexOf('_');
if (i != -1) {
@ -208,6 +210,8 @@ public class ICULocaleData {
Class cls = ICULocaleData.class.getClassLoader().loadClass(name);
if (ICUListResourceBundle.class.isAssignableFrom(cls)) {
ICUListResourceBundle bx = (ICUListResourceBundle)cls.newInstance();
if (parent != null) {
bx.setParentX(parent);
}
@ -221,6 +225,22 @@ public class ICULocaleData {
addToCache(name, b);
}
catch (ClassNotFoundException e) {
int j = name.indexOf('_');
int k = name.lastIndexOf('_');
// if a bogus locale is passed then the parent should be
// the default locale not the root locale!
if(k==j && j!=-1){
String locName = name.substring(j+1,name.length());
String defaultName = Locale.getDefault().toString();
if(!locName.equals(rootLocale.toString()) &&
defaultName.indexOf(locName)==-1){
String bundle = name.substring(0,j);
parent = instantiate(bundle+"_"+defaultName);
}
}
b = parent;
}
catch (Exception e) {
@ -237,7 +257,12 @@ public class ICULocaleData {
* class path?
*/
private synchronized static ResourceBundle instantiateBundle(String name, Locale l) {
return instantiate(name + "_" + l);
String s = l.toString();
if(s.length()!=0){
return instantiate(name + "_" + l);
}else{
return instantiate(name);
}
// ResourceBundle rb = ResourceBundle.getBundle(name, l);
// try {
// Class cls = ICULocaleData.class.getClassLoader().loadClass(name + "_" + l);