ICU-3440 ulocale wrap up, minor tweaks to UResourceBundle/ICUResourceBundle

X-SVN-Rev: 15193
This commit is contained in:
Doug Felt 2004-05-07 18:13:39 +00:00
parent 9f8f3ace99
commit 14e67686dd
6 changed files with 712 additions and 700 deletions

View File

@ -40,10 +40,8 @@ public class CollationMiscTest extends TestFmwk{
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,locale);
if (rb != null) {
try {
String collkey
= (String)rb.getObjectWithFallback("collations/default");
Object elements
= rb.getObjectWithFallback("collations/" + collkey);
String collkey = rb.getStringWithFallback("collations/default");
ICUResourceBundle elements = rb.getWithFallback("collations/" + collkey);
if (elements != null) {
return true;
}
@ -1588,10 +1586,8 @@ public class CollationMiscTest extends TestFmwk{
Locale l = locale[i];
try {
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_COLLATION_BASE_NAME,l);
String collkey
= (String)rb.getObjectWithFallback("collations/default");
ICUResourceBundle elements
= (ICUResourceBundle)rb.getObjectWithFallback("collations/" + collkey);
String collkey = rb.getStringWithFallback("collations/default");
ICUResourceBundle elements = rb.getWithFallback("collations/" + collkey);
if (elements == null) {
continue;
}
@ -2031,4 +2027,4 @@ public class CollationMiscTest extends TestFmwk{
}
}
}
}

View File

@ -530,15 +530,15 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
}
public void TestGetObjectWithFallback(){
public void TestGetWithFallback(){
ICUResourceBundle bundle =(ICUResourceBundle) UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,"te_IN");
String key = (String) bundle.getObjectWithFallback("Keys/collation");
String key = bundle.getStringWithFallback("Keys/collation");
if(!key.equals("COLLATION")){
errln("Did not get the expected result from getObjectWithFallback method.");
errln("Did not get the expected result from getStringWithFallback method.");
}
String type = (String) bundle.getObjectWithFallback("Types/collation/direct");
String type = bundle.getStringWithFallback("Types/collation/direct");
if(!type.equals("DIRECT")){
errln("Did not get the expected result form getObjectWithFallback method.");
errln("Did not get the expected result form getStringWithFallback method.");
}
try{
@ -546,9 +546,9 @@ public final class ICUResourceBundleTest extends TestFmwk {
if(!bundle.getULocale().equals("de")){
errln("did not get the expected bundle");
}
key = (String) bundle.getObjectWithFallback("collations/collation/default");
key = bundle.getStringWithFallback("collations/collation/default");
if(!key.equals("phonebook")){
errln("Did not get the expected result from getObjectWithFallback method.");
errln("Did not get the expected result from getStringWithFallback method.");
}
}catch(MissingResourceException ex){
@ -557,9 +557,9 @@ public final class ICUResourceBundleTest extends TestFmwk {
bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(UResourceBundle.ICU_COLLATION_BASE_NAME,"fr_FR");
key = (String) bundle.getObjectWithFallback("collations/default");
key = bundle.getStringWithFallback("collations/default");
if(!key.equals("standard")){
errln("Did not get the expected result from getObjectWithFallback method.");
errln("Did not get the expected result from getStringWithFallback method.");
}
}

View File

@ -447,22 +447,20 @@ public class ICUResourceBundle extends UResourceBundle{
* }
* If the value of "default" key needs to be accessed, then do:
* <code>
* ResourceBundle bundle = new ResourceBundle(getLocaleFromString("de__PHONEBOOK"));
* Object result = null;
* UResourceBundle bundle = UResourceBundle.getBundleInstance("de__PHONEBOOK");
* ICUResourceBundle result = null;
* if(bundle instanceof ICUListResourceBundle){
* result = ((ICUListResourceBundle) bundle).getObjectWithFallback("collations/default");
* result = ((ICUListResourceBundle) bundle).getWithFallback("collations/default");
* }
* </code>
* @param path The path to the required resource key
* @return Object represented by the key
* @return resource represented by the key
* @exception MissingResourceException
*/
public Object getObjectWithFallback(String path)
throws MissingResourceException{
public ICUResourceBundle getWithFallback(String path) throws MissingResourceException {
ICUResourceBundle result = null;
ICUResourceBundle actualBundle = this;
// now recuse to pick up sub levels of the items
result = findResourceWithFallback(path, actualBundle);
@ -473,11 +471,14 @@ public class ICUResourceBundle extends UResourceBundle{
path,
key);
}
if(result.getType()==STRING){
return result.getString();
}
return result;
}
// will throw type mismatch exception if the resource is not a string
public String getStringWithFallback(String path) throws MissingResourceException {
return getWithFallback(path).getString();
}
private ICUResourceBundle findResourceWithFallback(String path, ICUResourceBundle actualBundle) {
ICUResourceBundle sub = null;
while (actualBundle != null) {

View File

@ -1619,13 +1619,11 @@ public final class RuleBasedCollator extends Collator
try {
// TODO: this is to be updated after the key word search
// is implemented.
Object collkey
= rb.getObjectWithFallback("collations/default");
String collkey = rb.getStringWithFallback("collations/default");
// collations/default will always give a string back
// keyword for the real collation data
// if "collations/collkey" will return null if collkey == null
ICUResourceBundle elements
= (ICUResourceBundle)rb.getObjectWithFallback("collations/" + collkey);
ICUResourceBundle elements = rb.getWithFallback("collations/" + collkey);
if (elements != null) {
// TODO: Determine actual & valid locale correctly
ULocale uloc = rb.getULocale();

File diff suppressed because it is too large Load Diff

View File

@ -149,10 +149,11 @@ public abstract class UResourceBundle extends ResourceBundle{
*
* @draft ICU 3.0
*/
public static final ResourceBundle getBundleInstance(String baseName){
public static final UResourceBundle getBundleInstance(String baseName){
return getBundleInstance( baseName, ULocale.getDefault().toString(), ICU_DATA_CLASS_LOADER );
}
public static final ResourceBundle getBundleInstance(String baseName, Locale locale){
public static final UResourceBundle getBundleInstance(String baseName, Locale locale){
return getBundleInstance(baseName, new ULocale(locale));
}