Search in sources :

Example 1 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class ICUResourceBundle method getKeywordValues.

/**
 * Given a tree path and keyword, return a string enumeration of all possible values for that keyword.
 * @param baseName resource specifier
 * @param keyword a particular keyword to consider, must match a top level resource name
 * within the tree. (i.e. "collations")
 * @hide draft / provisional / internal are hidden on Android
 */
public static final String[] getKeywordValues(String baseName, String keyword) {
    Set<String> keywords = new HashSet<String>();
    ULocale[] locales = getAvailEntry(baseName, ICU_DATA_CLASS_LOADER).getULocaleList();
    int i;
    for (i = 0; i < locales.length; i++) {
        try {
            UResourceBundle b = UResourceBundle.getBundleInstance(baseName, locales[i]);
            // downcast to ICUResourceBundle?
            ICUResourceBundle irb = (ICUResourceBundle) (b.getObject(keyword));
            Enumeration<String> e = irb.getKeys();
            while (e.hasMoreElements()) {
                String s = e.nextElement();
                if (!DEFAULT_TAG.equals(s) && !s.startsWith("private-")) {
                    // don't add 'default' items, nor unlisted types
                    keywords.add(s);
                }
            }
        } catch (Throwable t) {
        // System.err.println("Error in - " + new Integer(i).toString()
        // + " - " + t.toString());
        // ignore the err - just skip that resource
        }
    }
    return keywords.toArray(new String[0]);
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) ULocale(android.icu.util.ULocale) HashSet(java.util.HashSet)

Example 2 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class ICUDataVersion method getDataVersion.

/**
 * This function retrieves the data version from icuver and returns a VersionInfo object with that version information.
 *
 * @return Current icu data version
 */
public static VersionInfo getDataVersion() {
    UResourceBundle icudatares = null;
    try {
        icudatares = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, ICUDataVersion.U_ICU_VERSION_BUNDLE, ICUResourceBundle.ICU_DATA_CLASS_LOADER);
        icudatares = icudatares.get(ICUDataVersion.U_ICU_DATA_KEY);
    } catch (MissingResourceException ex) {
        return null;
    }
    return VersionInfo.getInstance(icudatares.getString());
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) MissingResourceException(java.util.MissingResourceException)

Example 3 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class NumberingSystem method lookupInstanceByName.

private static NumberingSystem lookupInstanceByName(String name) {
    int radix;
    boolean isAlgorithmic;
    String description;
    try {
        UResourceBundle numberingSystemsInfo = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "numberingSystems");
        UResourceBundle nsCurrent = numberingSystemsInfo.get("numberingSystems");
        UResourceBundle nsTop = nsCurrent.get(name);
        description = nsTop.getString("desc");
        UResourceBundle nsRadixBundle = nsTop.get("radix");
        UResourceBundle nsAlgBundle = nsTop.get("algorithmic");
        radix = nsRadixBundle.getInt();
        int algorithmic = nsAlgBundle.getInt();
        isAlgorithmic = (algorithmic == 1);
    } catch (MissingResourceException ex) {
        return null;
    }
    return getInstance(name, radix, isAlgorithmic, description);
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) ICUResourceBundle(android.icu.impl.ICUResourceBundle) MissingResourceException(java.util.MissingResourceException)

Example 4 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class ICUResourceBundleTest method TestCLDRStyleAliases.

@Test
public void TestCLDRStyleAliases() {
    String result = null;
    String expected = null;
    String[] expects = new String[] { "", "a41", "a12", "a03", "ar4" };
    logln("Testing CLDR style aliases......\n");
    UResourceBundle rb = UResourceBundle.getBundleInstance("android/icu/dev/data/testdata", "te_IN_REVISED", testLoader);
    ICUResourceBundle alias = (ICUResourceBundle) rb.get("a");
    for (int i = 1; i < 5; i++) {
        String resource = "a" + i;
        UResourceBundle a = (alias).getWithFallback(resource);
        result = a.getString();
        if (result.equals(expected)) {
            errln("CLDR style aliases failed resource with name " + resource + "resource, exp " + expects[i] + " , got " + result);
        }
    }
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) ICUResourceBundle(android.icu.impl.ICUResourceBundle) Test(org.junit.Test)

Example 5 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class ICUResourceBundleTest method TestT6844.

/*
     * UResouceBundle should be able to load a resource bundle even if
     * a similarly named class (only case differences) exists in the
     * same package.  See Ticket#6844
     */
@Test
public void TestT6844() {
    try {
        UResourceBundle rb1 = UResourceBundle.getBundleInstance("android.icu.dev.data.resources.TestMessages", ULocale.getDefault(), testLoader);
        assertEquals("bundleContainer in TestMessages", "TestMessages.class", rb1.getString("bundleContainer"));
        UResourceBundle rb2 = UResourceBundle.getBundleInstance("android.icu.dev.data.resources.testmessages", ULocale.getDefault(), testLoader);
        assertEquals("bundleContainer in testmessages", "testmessages.properties", rb2.getString("bundleContainer"));
    } catch (Throwable t) {
        errln(t.getMessage());
    }
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) Test(org.junit.Test)

Aggregations

UResourceBundle (android.icu.util.UResourceBundle)46 ICUResourceBundle (android.icu.impl.ICUResourceBundle)26 MissingResourceException (java.util.MissingResourceException)24 Test (org.junit.Test)17 ULocale (android.icu.util.ULocale)8 UResourceBundleIterator (android.icu.util.UResourceBundleIterator)6 UResourceTypeMismatchException (android.icu.util.UResourceTypeMismatchException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 SimpleTimeZone (android.icu.util.SimpleTimeZone)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 EnumSet (java.util.EnumSet)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 JavaTimeZone (android.icu.impl.JavaTimeZone)1