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

The following examples show how to use com.ibm.icu.util.UResourceBundle#getType() . 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: ZoneMeta.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Given an ID and the top-level resource of the zoneinfo resource,
 * open the appropriate resource for the given time zone.
 * Dereference links if necessary.
 * @param top the top level resource of the zoneinfo resource or null.
 * @param id zone id
 * @return the corresponding zone resource or null if not found
 */
public static UResourceBundle openOlsonResource(UResourceBundle top, String id)
{
    UResourceBundle res = null;
    int zoneIdx = getZoneIndex(id);
    if (zoneIdx >= 0) {
        try {
            if (top == null) {
                top = UResourceBundle.getBundleInstance(
                        ICUData.ICU_BASE_NAME, ZONEINFORESNAME, ICUResourceBundle.ICU_DATA_CLASS_LOADER);
            }
            UResourceBundle zones = top.get(kZONES);
            UResourceBundle zone = zones.get(zoneIdx);
            if (zone.getType() == UResourceBundle.INT) {
                // resolve link
                zone = zones.get(zone.getInt());
            }
            res = zone;
        } catch (MissingResourceException e) {
            res = null;
        }
    }
    return res;
}
 
Example 2
Source File: CalendarData.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
public String[] getDateTimePatterns(){
    ICUResourceBundle bundle = get("DateTimePatterns");
    ArrayList<String> list = new ArrayList<String>();
    UResourceBundleIterator iter = bundle.getIterator();
    while (iter.hasNext()) {
        UResourceBundle patResource = iter.next();
        int resourceType = patResource.getType();
        switch (resourceType) {
            case UResourceBundle.STRING:
                list.add(patResource.getString());
                break;
            case UResourceBundle.ARRAY:
                String[] items = patResource.getStringArray();
                list.add(items[0]);
                break;
        }
    }

    return list.toArray(new String[list.size()]);
}
 
Example 3
Source File: CalendarData.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
public String[] getOverrides(){
    ICUResourceBundle bundle = get("DateTimePatterns");
    ArrayList<String> list = new ArrayList<String>();
    UResourceBundleIterator iter = bundle.getIterator();
    while (iter.hasNext()) {
        UResourceBundle patResource = iter.next();
        int resourceType = patResource.getType();
        switch (resourceType) {
            case UResourceBundle.STRING:
                list.add(null);
                break;
            case UResourceBundle.ARRAY:
                String[] items = patResource.getStringArray();
                list.add(items[1]);
                break;
        }
    }
    return list.toArray(new String[list.size()]);
}
 
Example 4
Source File: ZoneMeta.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Return the canonical id for this tzid defined by CLDR, which might be
 * the id itself. If the given tzid is not known, return null.
 * 
 * Note: This internal API supports all known system IDs and "Etc/Unknown" (which is
 * NOT a system ID).
 */
public static String getCanonicalCLDRID(String tzid) {
    String canonical = CANONICAL_ID_CACHE.get(tzid);
    if (canonical == null) {
        canonical = findCLDRCanonicalID(tzid);
        if (canonical == null) {
            // Resolve Olson link and try it again if necessary
            try {
                int zoneIdx = getZoneIndex(tzid);
                if (zoneIdx >= 0) {
                    UResourceBundle top = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME,
                            ZONEINFORESNAME, ICUResourceBundle.ICU_DATA_CLASS_LOADER);
                    UResourceBundle zones = top.get(kZONES);
                    UResourceBundle zone = zones.get(zoneIdx);
                    if (zone.getType() == UResourceBundle.INT) {
                        // It's a link - resolve link and lookup
                        tzid = getZoneID(zone.getInt());
                        canonical = findCLDRCanonicalID(tzid);
                    }
                    if (canonical == null) {
                        canonical = tzid;
                    }
                }
            } catch (MissingResourceException e) {
                // fall through
            }
        }
        if (canonical != null) {
            CANONICAL_ID_CACHE.put(tzid, canonical);
        }
    }
    return canonical;
}