Java Code Examples for com.ibm.icu.util.UResourceBundle#getString()

The following examples show how to use com.ibm.icu.util.UResourceBundle#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NumberingSystem.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: ZoneMeta.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Return the region code for this tzid.
 * If tzid is not a system zone ID, this method returns null.
 */
public static String getRegion(String tzid) {
    String region = REGION_CACHE.get(tzid);
    if (region == null) {
        int zoneIdx = getZoneIndex(tzid);
        if (zoneIdx >= 0) {
            try {
                UResourceBundle top = UResourceBundle.getBundleInstance(
                        ICUData.ICU_BASE_NAME, ZONEINFORESNAME, ICUResourceBundle.ICU_DATA_CLASS_LOADER);
                UResourceBundle regions = top.get(kREGIONS);
                if (zoneIdx < regions.getSize()) {
                    region = regions.getString(zoneIdx);
                }
            } catch (MissingResourceException e) {
                // throw away
            }
            if (region != null) {
                REGION_CACHE.put(tzid, region);
            }
        }
    }
    return region;
}
 
Example 3
Source File: ZoneMeta.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
private static String getShortIDFromCanonical(String canonicalID) {
    String shortID = null;
    String tzidKey = canonicalID.replace('/', ':');

    try {
        // First, try check if the given ID is canonical
        UResourceBundle keyTypeData = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME,
                "keyTypeData", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
        UResourceBundle typeMap = keyTypeData.get("typeMap");
        UResourceBundle typeKeys = typeMap.get("timezone");
        shortID = typeKeys.getString(tzidKey);
    } catch (MissingResourceException e) {
        // fall through
    }

    return shortID;
}
 
Example 4
Source File: KeyTypeData.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/** Reads
keyInfo{
    deprecated{
        kh{"true"}
        vt{"true"}
    }
    valueType{
        ca{"incremental"}
        kr{"multiple"}
        vt{"multiple"}
        x0{"any"}
    }
}
     */
    private static void getKeyInfo(UResourceBundle keyInfoRes) {
        Set<String> _deprecatedKeys = new LinkedHashSet<String>();
        Map<String, ValueType> _valueTypes = new LinkedHashMap<String, ValueType>();
        for (UResourceBundleIterator keyInfoIt = keyInfoRes.getIterator(); keyInfoIt.hasNext();) {
            UResourceBundle keyInfoEntry = keyInfoIt.next();
            String key = keyInfoEntry.getKey();
            KeyInfoType keyInfo = KeyInfoType.valueOf(key);
            for (UResourceBundleIterator keyInfoIt2 = keyInfoEntry.getIterator(); keyInfoIt2.hasNext();) {
                UResourceBundle keyInfoEntry2 = keyInfoIt2.next();
                String key2 = keyInfoEntry2.getKey();
                String value2 = keyInfoEntry2.getString();
                switch (keyInfo) {
                case deprecated:
                    _deprecatedKeys.add(key2);
                    break;
                case valueType:
                    _valueTypes.put(key2, ValueType.valueOf(value2));
                    break;
                }
            }
        }
        DEPRECATED_KEYS = Collections.unmodifiableSet(_deprecatedKeys);
        VALUE_TYPES = Collections.unmodifiableMap(_valueTypes);
    }
 
Example 5
Source File: KeyTypeData.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
/** Reads
keyInfo{
    deprecated{
        kh{"true"}
        vt{"true"}
    }
    valueType{
        ca{"incremental"}
        h0{"single"}
        kr{"multiple"}
        vt{"multiple"}
        x0{"any"}
    }
}
     */
    private static void getKeyInfo(UResourceBundle keyInfoRes) {
        Set<String> _deprecatedKeys = new LinkedHashSet<String>();
        Map<String, ValueType> _valueTypes = new LinkedHashMap<String, ValueType>();
        for (UResourceBundleIterator keyInfoIt = keyInfoRes.getIterator(); keyInfoIt.hasNext();) {
            UResourceBundle keyInfoEntry = keyInfoIt.next();
            String key = keyInfoEntry.getKey();
            KeyInfoType keyInfo = KeyInfoType.valueOf(key);
            for (UResourceBundleIterator keyInfoIt2 = keyInfoEntry.getIterator(); keyInfoIt2.hasNext();) {
                UResourceBundle keyInfoEntry2 = keyInfoIt2.next();
                String key2 = keyInfoEntry2.getKey();
                String value2 = keyInfoEntry2.getString();
                switch (keyInfo) {
                case deprecated:
                    _deprecatedKeys.add(key2);
                    break;
                case valueType:
                    _valueTypes.put(key2, ValueType.valueOf(value2));
                    break;
                }
            }
        }
        DEPRECATED_KEYS = Collections.unmodifiableSet(_deprecatedKeys);
        VALUE_TYPES = Collections.unmodifiableMap(_valueTypes);
    }
 
Example 6
Source File: TimeZoneNamesImpl.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
@Override
protected List<MZMapEntry> createInstance(String key, String data) {
    List<MZMapEntry> mzMaps = null;

    UResourceBundle bundle = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "metaZones");
    UResourceBundle metazoneInfoBundle = bundle.get("metazoneInfo");

    String tzkey = data.replace('/', ':');
    try {
        UResourceBundle zoneBundle = metazoneInfoBundle.get(tzkey);

        mzMaps = new ArrayList<MZMapEntry>(zoneBundle.getSize());
        for (int idx = 0; idx < zoneBundle.getSize(); idx++) {
            UResourceBundle mz = zoneBundle.get(idx);
            String mzid = mz.getString(0);
            String fromStr = "1970-01-01 00:00";
            String toStr = "9999-12-31 23:59";
            if (mz.getSize() == 3) {
                fromStr = mz.getString(1);
                toStr = mz.getString(2);
            }
            long from, to;
            from = parseDate(fromStr);
            to = parseDate(toStr);
            mzMaps.add(new MZMapEntry(mzid, from, to));
        }

    } catch (MissingResourceException mre) {
        mzMaps = Collections.emptyList();
    }
    return mzMaps;
}
 
Example 7
Source File: CollationLoader.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
private static void loadRootRules() {
    if (rootRules != null) {
        return;
    }
    synchronized(CollationLoader.class) {
        if (rootRules == null) {
            UResourceBundle rootBundle = UResourceBundle.getBundleInstance(
                    ICUData.ICU_COLLATION_BASE_NAME, ULocale.ROOT);
            rootRules = rootBundle.getString("UCARules");
        }
    }
}
 
Example 8
Source File: CollationLoader.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
static String loadRules(ULocale locale, String collationType) {
    UResourceBundle bundle = UResourceBundle.getBundleInstance(
            ICUData.ICU_COLLATION_BASE_NAME, locale);
    UResourceBundle data = ((ICUResourceBundle)bundle).getWithFallback(
            "collations/" + ASCII.toLowerCase(collationType));
    String rules = data.getString("Sequence");
    return rules;
}
 
Example 9
Source File: ZoneMeta.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
/**
 * Return the canonical country code for this tzid.  If we have none, or if the time zone
 * is not associated with a country or unknown, return null. When the given zone is the
 * primary zone of the country, true is set to isPrimary.
 */
public static String getCanonicalCountry(String tzid, Output<Boolean> isPrimary) {
    isPrimary.value = Boolean.FALSE;

    String country = getRegion(tzid);
    if (country != null && country.equals(kWorld)) {
        return null;
    }

    // Check the cache
    Boolean singleZone = SINGLE_COUNTRY_CACHE.get(tzid);
    if (singleZone == null) {
        Set<String> ids = TimeZone.getAvailableIDs(SystemTimeZoneType.CANONICAL_LOCATION, country, null);
        assert(ids.size() >= 1);
        singleZone = Boolean.valueOf(ids.size() <= 1);
        SINGLE_COUNTRY_CACHE.put(tzid, singleZone);
    }

    if (singleZone) {
        isPrimary.value = Boolean.TRUE;
    } else {
        // Note: We may cache the primary zone map in future.

        // Even a country has multiple zones, one of them might be
        // dominant and treated as a primary zone.
        try {
            UResourceBundle bundle = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "metaZones");
            UResourceBundle primaryZones = bundle.get("primaryZones");
            String primaryZone = primaryZones.getString(country);
            if (tzid.equals(primaryZone)) {
                isPrimary.value = Boolean.TRUE;
            } else {
                // The given ID might not be a canonical ID
                String canonicalID = getCanonicalCLDRID(tzid);
                if (canonicalID != null && canonicalID.equals(primaryZone)) {
                    isPrimary.value = Boolean.TRUE;
                }
            }
        } catch (MissingResourceException e) {
            // ignore
        }
    }

    return country;
}