use of android.icu.impl.ICUResourceBundle in project j2objc by google.
the class ICUResourceBundleTest method TestGetWithFallback.
@Test
public void TestGetWithFallback() {
/*
UResourceBundle bundle =(UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN");
String key = bundle.getStringWithFallback("Keys/collation");
if(!key.equals("COLLATION")){
errln("Did not get the expected result from getStringWithFallback method.");
}
String type = bundle.getStringWithFallback("Types/collation/direct");
if(!type.equals("DIRECT")){
errln("Did not get the expected result form getStringWithFallback method.");
}
*/
ICUResourceBundle bundle = null;
bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "fr_FR");
ICUResourceBundle b1 = bundle.getWithFallback("calendar");
String defaultCal = b1.getStringWithFallback("default");
if (!defaultCal.equals("gregorian")) {
errln("Did not get the expected default calendar string: Expected: gregorian, Got: " + defaultCal);
}
ICUResourceBundle b2 = b1.getWithFallback(defaultCal);
ICUResourceBundle b3 = b2.getWithFallback("monthNames");
ICUResourceBundle b4 = b3.getWithFallback("format");
ICUResourceBundle b5 = b4.getWithFallback("narrow");
if (b5.getSize() != 12) {
errln("Did not get the expected size for the monthNames");
}
}
use of android.icu.impl.ICUResourceBundle in project j2objc by google.
the class DisplayNameTest method getCodes.
/**
* Hack to get code list
* @return
*/
private static String[] getCodes(ULocale locale, String tableName) {
// TODO remove Ugly Hack
// get stuff
ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(locale);
ICUResourceBundle table = bundle.getWithFallback(tableName);
// copy into array
ArrayList stuff = new ArrayList();
for (Enumeration keys = table.getKeys(); keys.hasMoreElements(); ) {
stuff.add(keys.nextElement());
}
String[] result = new String[stuff.size()];
return (String[]) stuff.toArray(result);
// return new String[] {"Latn", "Cyrl"};
}
use of android.icu.impl.ICUResourceBundle in project j2objc by google.
the class DisplayNameTest method getZoneString.
private String getZoneString(ULocale locale, String olsonID, int item) {
Map data = (Map) zoneData.get(locale);
if (data == null) {
data = new HashMap();
if (SHOW_ALL)
System.out.println();
if (SHOW_ALL)
System.out.println("zones for " + locale);
ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(locale);
ICUResourceBundle table = bundle.getWithFallback("zoneStrings");
for (int i = 0; i < table.getSize(); ++i) {
UResourceBundle stringSet = table.get(i);
// ICUResourceBundle stringSet = table.getWithFallback(String.valueOf(i));
String key = stringSet.getString(0);
if (SHOW_ALL)
System.out.println("key: " + key);
ArrayList list = new ArrayList();
for (int j = 1; j < stringSet.getSize(); ++j) {
String entry = stringSet.getString(j);
if (SHOW_ALL)
System.out.println(" entry: " + entry);
list.add(entry);
}
data.put(key, list.toArray(new String[list.size()]));
}
zoneData.put(locale, data);
}
String[] strings = (String[]) data.get(olsonID);
if (strings == null || item >= strings.length)
return olsonID;
return strings[item];
}
use of android.icu.impl.ICUResourceBundle in project j2objc by google.
the class BreakIteratorFactory method createBreakInstance.
private static BreakIterator createBreakInstance(ULocale locale, int kind) {
RuleBasedBreakIterator iter = null;
ICUResourceBundle rb = ICUResourceBundle.getBundleInstance(ICUData.ICU_BRKITR_BASE_NAME, locale, ICUResourceBundle.OpenType.LOCALE_ROOT);
//
// Get the binary rules.
//
ByteBuffer bytes = null;
String typeKeyExt = null;
if (kind == BreakIterator.KIND_LINE) {
String lbKeyValue = locale.getKeywordValue("lb");
if (lbKeyValue != null && (lbKeyValue.equals("strict") || lbKeyValue.equals("normal") || lbKeyValue.equals("loose"))) {
typeKeyExt = "_" + lbKeyValue;
}
}
try {
String typeKey = (typeKeyExt == null) ? KIND_NAMES[kind] : KIND_NAMES[kind] + typeKeyExt;
String brkfname = rb.getStringWithFallback("boundaries/" + typeKey);
String rulesFileName = ICUData.ICU_BRKITR_NAME + '/' + brkfname;
bytes = ICUBinary.getData(rulesFileName);
} catch (Exception e) {
throw new MissingResourceException(e.toString(), "", "");
}
//
try {
iter = RuleBasedBreakIterator.getInstanceFromCompiledRules(bytes);
} catch (IOException e) {
// Shouldn't be possible to get here.
// If it happens, the compiled rules are probably corrupted in some way.
Assert.fail(e);
}
// TODO: Determine valid and actual locale correctly.
ULocale uloc = ULocale.forLocale(rb.getLocale());
iter.setLocale(uloc, uloc);
iter.setBreakType(kind);
// filtered break
if (kind == BreakIterator.KIND_SENTENCE) {
final String ssKeyword = locale.getKeywordValue("ss");
if (ssKeyword != null && ssKeyword.equals("standard")) {
final ULocale base = new ULocale(locale.getBaseName());
return FilteredBreakIteratorBuilder.getInstance(base).wrapIteratorWithFilter(iter);
}
}
return iter;
}
use of android.icu.impl.ICUResourceBundle in project j2objc by google.
the class UResourceBundle method keySet.
/**
* Returns a Set of all keys contained in this ResourceBundle and its parent bundles.
* @return a Set of all keys contained in this ResourceBundle and its parent bundles,
* which is empty if this is not a bundle or a table resource
* @deprecated This API is ICU internal only.
* @hide draft / provisional / internal are hidden on Android
*/
@Override
@Deprecated
public Set<String> keySet() {
// TODO: Java 6 ResourceBundle has keySet() which calls handleKeySet()
// and caches the results.
// When we upgrade to Java 6, we still need to check for isTopLevelResource().
// Keep the else branch as is. The if body should just return super.keySet().
// Remove then-redundant caching of the keys.
Set<String> keys = null;
ICUResourceBundle icurb = null;
if (isTopLevelResource() && this instanceof ICUResourceBundle) {
// We do not cache the top-level keys in this base class so that
// not every string/int/binary... resource has to have a keys cache field.
icurb = (ICUResourceBundle) this;
keys = icurb.getTopLevelKeySet();
}
if (keys == null) {
if (isTopLevelResource()) {
TreeSet<String> newKeySet;
if (parent == null) {
newKeySet = new TreeSet<String>();
} else if (parent instanceof UResourceBundle) {
newKeySet = new TreeSet<String>(((UResourceBundle) parent).keySet());
} else {
// TODO: Java 6 ResourceBundle has keySet(); use it when we upgrade to Java 6
// and remove this else branch.
newKeySet = new TreeSet<String>();
Enumeration<String> parentKeys = parent.getKeys();
while (parentKeys.hasMoreElements()) {
newKeySet.add(parentKeys.nextElement());
}
}
newKeySet.addAll(handleKeySet());
keys = Collections.unmodifiableSet(newKeySet);
if (icurb != null) {
icurb.setTopLevelKeySet(keys);
}
} else {
return handleKeySet();
}
}
return keys;
}
Aggregations