com.ibm.icu.util.UResourceBundle Java Examples

The following examples show how to use com.ibm.icu.util.UResourceBundle. 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: ICUResourceBundleReader.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
Array getArray(int res) {
    int type=RES_GET_TYPE(res);
    if(!URES_IS_ARRAY(type)) {
        return null;
    }
    int offset=RES_GET_OFFSET(res);
    if(offset == 0) {
        return EMPTY_ARRAY;
    }
    Object value = resourceCache.get(res);
    if(value != null) {
        return (Array)value;
    }
    Array array = (type == UResourceBundle.ARRAY) ?
            new Array32(this, offset) : new Array16(this, offset);
    return (Array)resourceCache.putIfAbsent(res, array, 0);
}
 
Example #2
Source File: ICUResourceBundle.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
private static final void addLocaleIDsFromIndexBundle(String baseName,
        ClassLoader root, Set<String> locales) {
    ICUResourceBundle bundle;
    try {
        bundle = (ICUResourceBundle) UResourceBundle.instantiateBundle(baseName, ICU_RESOURCE_INDEX, root, true);
        bundle = (ICUResourceBundle) bundle.get(INSTALLED_LOCALES);
    } catch (MissingResourceException e) {
        if (DEBUG) {
            System.out.println("couldn't find " + baseName + '/' + ICU_RESOURCE_INDEX + ".res");
            Thread.dumpStack();
        }
        return;
    }
    UResourceBundleIterator iter = bundle.getIterator();
    iter.reset();
    while (iter.hasNext()) {
        String locstr = iter.next(). getKey();
        locales.add(locstr);
    }
}
 
Example #3
Source File: ICUResourceBundle.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
private static final void addLocaleIDsFromIndexBundle(String baseName,
        ClassLoader root, Set<String> locales) {
    ICUResourceBundle bundle;
    try {
        bundle = (ICUResourceBundle) UResourceBundle.instantiateBundle(baseName, ICU_RESOURCE_INDEX, root, true);
        bundle = (ICUResourceBundle) bundle.get(INSTALLED_LOCALES);
    } catch (MissingResourceException e) {
        if (DEBUG) {
            System.out.println("couldn't find " + baseName + '/' + ICU_RESOURCE_INDEX + ".res");
            Thread.dumpStack();
        }
        return;
    }
    UResourceBundleIterator iter = bundle.getIterator();
    iter.reset();
    while (iter.hasNext()) {
        String locstr = iter.next(). getKey();
        locales.add(locstr);
    }
}
 
Example #4
Source File: ICUResourceBundle.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
private static final ULocale[] createULocaleList(String baseName,
        ClassLoader root) {
    // the canned list is a subset of all the available .res files, the idea
    // is we don't export them
    // all. gotta be a better way to do this, since to add a locale you have
    // to update this list,
    // and it's embedded in our binary resources.
    ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.instantiateBundle(baseName, ICU_RESOURCE_INDEX, root, true);

    bundle = (ICUResourceBundle)bundle.get(INSTALLED_LOCALES);
    int length = bundle.getSize();
    int i = 0;
    ULocale[] locales = new ULocale[length];
    UResourceBundleIterator iter = bundle.getIterator();
    iter.reset();
    while (iter.hasNext()) {
        String locstr = iter.next().getKey();
        if (locstr.equals("root")) {
            locales[i++] = ULocale.ROOT;
        } else {
            locales[i++] = new ULocale(locstr);
        }
    }
    bundle = null;
    return locales;
}
 
Example #5
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 #6
Source File: KeyTypeData.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/** Reads:
typeInfo{
    deprecated{
        co{
            direct{"true"}
        }
        tz{
            camtr{"true"}
        }
    }
}
     */
    private static void getTypeInfo(UResourceBundle typeInfoRes) {
        Map<String,Set<String>> _deprecatedKeyTypes = new LinkedHashMap<String,Set<String>>();
        for (UResourceBundleIterator keyInfoIt = typeInfoRes.getIterator(); keyInfoIt.hasNext();) {
            UResourceBundle keyInfoEntry = keyInfoIt.next();
            String key = keyInfoEntry.getKey();
            TypeInfoType typeInfo = TypeInfoType.valueOf(key);
            for (UResourceBundleIterator keyInfoIt2 = keyInfoEntry.getIterator(); keyInfoIt2.hasNext();) {
                UResourceBundle keyInfoEntry2 = keyInfoIt2.next();
                String key2 = keyInfoEntry2.getKey();
                Set<String> _deprecatedTypes = new LinkedHashSet<String>();
                for (UResourceBundleIterator keyInfoIt3 = keyInfoEntry2.getIterator(); keyInfoIt3.hasNext();) {
                    UResourceBundle keyInfoEntry3 = keyInfoIt3.next();
                    String key3 = keyInfoEntry3.getKey();
                    switch (typeInfo) { // allow for expansion
                    case deprecated:
                        _deprecatedTypes.add(key3);
                        break;
                    }
                }
                _deprecatedKeyTypes.put(key2, Collections.unmodifiableSet(_deprecatedTypes));
            }
        }
        DEPRECATED_KEY_TYPES = Collections.unmodifiableMap(_deprecatedKeyTypes);
    }
 
Example #7
Source File: EngineException.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Set locale.
 * 
 * @param locale
 */
static public void setULocale( ULocale locale )
{
	if ( locale == null )
	{
		return;
	}
	UResourceBundle rb = (UResourceBundle) threadLocal.get( );
	if ( rb != null )
	{
		ULocale rbLocale = rb.getULocale( );
		if ( locale.equals( rbLocale ) )
		{
			return;
		}
	}
	rb = getResourceBundle(locale);
	threadLocal.set( rb );
}
 
Example #8
Source File: ICUResourceBundle.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
private static ICUResourceBundle getBundle(ICUResourceBundleReader reader,
                                           String baseName, String localeID,
                                           ClassLoader loader) {
    ICUResourceBundleImpl.ResourceTable rootTable;
    int rootRes = reader.getRootResource();
    if(ICUResourceBundleReader.URES_IS_TABLE(ICUResourceBundleReader.RES_GET_TYPE(rootRes))) {
        WholeBundle wb = new WholeBundle(baseName, localeID, loader, reader);
        rootTable = new ICUResourceBundleImpl.ResourceTable(wb, rootRes);
    } else {
        throw new IllegalStateException("Invalid format error");
    }
    String aliasString = rootTable.findString("%%ALIAS");
    if(aliasString != null) {
        return (ICUResourceBundle)UResourceBundle.getBundleInstance(baseName, aliasString);
    } else {
        return rootTable;
    }
}
 
Example #9
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 #10
Source File: Collator.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
@Override
public void put(UResource.Key key, UResource.Value value, boolean noFallback) {
    UResource.Table collations = value.getTable();
    for (int i = 0; collations.getKeyAndValue(i, key, value); ++i) {
        int type = value.getType();
        if (type == UResourceBundle.STRING) {
            if (!hasDefault && key.contentEquals("default")) {
                String defcoll = value.getString();
                if (!defcoll.isEmpty()) {
                    values.remove(defcoll);
                    values.addFirst(defcoll);
                    hasDefault = true;
                }
            }
        } else if (type == UResourceBundle.TABLE && !key.startsWith("private-")) {
            String collkey = key.toString();
            if (!values.contains(collkey)) {
                values.add(collkey);
            }
        }
    }
}
 
Example #11
Source File: ICUResourceBundle.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
ICUResourceBundle get(String aKey, HashMap<String, String> aliasesVisited, UResourceBundle requested) {
    ICUResourceBundle obj = (ICUResourceBundle)handleGet(aKey, aliasesVisited, requested);
    if (obj == null) {
        obj = getParent();
        if (obj != null) {
            //call the get method to recursively fetch the resource
            obj = obj.get(aKey, aliasesVisited, requested);
        }
        if (obj == null) {
            String fullName = ICUResourceBundleReader.getFullName(getBaseName(), getLocaleID());
            throw new MissingResourceException(
                    "Can't find resource for bundle " + fullName + ", key "
                            + aKey, this.getClass().getName(), aKey);
        }
    }
    return obj;
}
 
Example #12
Source File: ICUResourceBundleReader.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
int[] getIntVector(int res) {
    int offset=RES_GET_OFFSET(res);
    int length;
    if(RES_GET_TYPE(res)==UResourceBundle.INT_VECTOR) {
        if(offset==0) {
            return emptyInts;
        } else {
            // Not cached: The array would have to be cloned anyway because
            // the cache must not be writable via the returned reference.
            offset=getResourceByteOffset(offset);
            length=getInt(offset);
            return getInts(offset+4, length);
        }
    } else {
        return null;
    }
}
 
Example #13
Source File: ICUResourceBundleReader.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
Array getArray(int res) {
    int type=RES_GET_TYPE(res);
    if(!URES_IS_ARRAY(type)) {
        return null;
    }
    int offset=RES_GET_OFFSET(res);
    if(offset == 0) {
        return EMPTY_ARRAY;
    }
    Object value = resourceCache.get(res);
    if(value != null) {
        return (Array)value;
    }
    Array array = (type == UResourceBundle.ARRAY) ?
            new Array32(this, offset) : new Array16(this, offset);
    return (Array)resourceCache.putIfAbsent(res, array, 0);
}
 
Example #14
Source File: ICUResourceBundle.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
private static ICUResourceBundle getBundle(ICUResourceBundleReader reader,
                                           String baseName, String localeID,
                                           ClassLoader loader) {
    ICUResourceBundleImpl.ResourceTable rootTable;
    int rootRes = reader.getRootResource();
    if(ICUResourceBundleReader.URES_IS_TABLE(ICUResourceBundleReader.RES_GET_TYPE(rootRes))) {
        WholeBundle wb = new WholeBundle(baseName, localeID, loader, reader);
        rootTable = new ICUResourceBundleImpl.ResourceTable(wb, rootRes);
    } else {
        throw new IllegalStateException("Invalid format error");
    }
    String aliasString = rootTable.findString("%%ALIAS");
    if(aliasString != null) {
        return (ICUResourceBundle)UResourceBundle.getBundleInstance(baseName, aliasString);
    } else {
        return rootTable;
    }
}
 
Example #15
Source File: EngineException.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get resource bundle.
 * 
 * @param locale
 * @return resource bundle
 */
protected synchronized static UResourceBundle getResourceBundle(
		ULocale locale )
{
	/* ulocale has overides the hashcode */
	UResourceBundle rb = (UResourceBundle) resourceBundles.get( locale );
	if ( rb == null )
	{
		rb = new EngineResourceHandle( locale ).getUResourceBundle( );
		if ( rb != null )
		{
			resourceBundles.put( locale, rb );
		}
	}
	return rb;
}
 
Example #16
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 #17
Source File: NumberingSystem.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a string array containing a list of the names of numbering systems
 * currently known to ICU.
 * @stable ICU 4.2
 */
public static String [] getAvailableNames() {

        UResourceBundle numberingSystemsInfo = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "numberingSystems");
        UResourceBundle nsCurrent = numberingSystemsInfo.get("numberingSystems");
        UResourceBundle temp;

        String nsName;
        ArrayList<String> output = new ArrayList<String>();
        UResourceBundleIterator it = nsCurrent.getIterator();
        while (it.hasNext()) {
            temp = it.next();
            nsName = temp.getKey();
            output.add(nsName);
        }
        return output.toArray(new String[output.size()]);
}
 
Example #18
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 #19
Source File: ICUResourceBundle.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
ICUResourceBundle get(String aKey, HashMap<String, String> aliasesVisited, UResourceBundle requested) {
    ICUResourceBundle obj = (ICUResourceBundle)handleGet(aKey, aliasesVisited, requested);
    if (obj == null) {
        obj = getParent();
        if (obj != null) {
            //call the get method to recursively fetch the resource
            obj = obj.get(aKey, aliasesVisited, requested);
        }
        if (obj == null) {
            String fullName = ICUResourceBundleReader.getFullName(getBaseName(), getLocaleID());
            throw new MissingResourceException(
                    "Can't find resource for bundle " + fullName + ", key "
                            + aKey, this.getClass().getName(), aKey);
        }
    }
    return obj;
}
 
Example #20
Source File: KeyTypeData.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
/** Reads:
typeInfo{
    deprecated{
        co{
            direct{"true"}
        }
        tz{
            camtr{"true"}
        }
    }
}
     */
    private static void getTypeInfo(UResourceBundle typeInfoRes) {
        Map<String,Set<String>> _deprecatedKeyTypes = new LinkedHashMap<String,Set<String>>();
        for (UResourceBundleIterator keyInfoIt = typeInfoRes.getIterator(); keyInfoIt.hasNext();) {
            UResourceBundle keyInfoEntry = keyInfoIt.next();
            String key = keyInfoEntry.getKey();
            TypeInfoType typeInfo = TypeInfoType.valueOf(key);
            for (UResourceBundleIterator keyInfoIt2 = keyInfoEntry.getIterator(); keyInfoIt2.hasNext();) {
                UResourceBundle keyInfoEntry2 = keyInfoIt2.next();
                String key2 = keyInfoEntry2.getKey();
                Set<String> _deprecatedTypes = new LinkedHashSet<String>();
                for (UResourceBundleIterator keyInfoIt3 = keyInfoEntry2.getIterator(); keyInfoIt3.hasNext();) {
                    UResourceBundle keyInfoEntry3 = keyInfoIt3.next();
                    String key3 = keyInfoEntry3.getKey();
                    switch (typeInfo) { // allow for expansion
                    case deprecated:
                        _deprecatedTypes.add(key3);
                        break;
                    }
                }
                _deprecatedKeyTypes.put(key2, Collections.unmodifiableSet(_deprecatedTypes));
            }
        }
        DEPRECATED_KEY_TYPES = Collections.unmodifiableMap(_deprecatedKeyTypes);
    }
 
Example #21
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 #22
Source File: ICUResourceBundleReader.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
int[] getIntVector(int res) {
    int offset=RES_GET_OFFSET(res);
    int length;
    if(RES_GET_TYPE(res)==UResourceBundle.INT_VECTOR) {
        if(offset==0) {
            return emptyInts;
        } else {
            // Not cached: The array would have to be cloned anyway because
            // the cache must not be writable via the returned reference.
            offset=getResourceByteOffset(offset);
            length=getInt(offset);
            return getInts(offset+4, length);
        }
    } else {
        return null;
    }
}
 
Example #23
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 #24
Source File: AdapterException.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
static UResourceBundle getResourceBundle( )
{
	UResourceBundle rb = (UResourceBundle) threadLocal.get( );
	if ( rb == null )
	{
		return dftRb;
	}
	return rb;
}
 
Example #25
Source File: TimeZoneNamesImpl.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
static Set<String> _getAvailableMetaZoneIDs() {
    if (METAZONE_IDS == null) {
        synchronized (TimeZoneNamesImpl.class) {
            if (METAZONE_IDS == null) {
                UResourceBundle bundle = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "metaZones");
                UResourceBundle mapTimezones = bundle.get("mapTimezones");
                Set<String> keys = mapTimezones.keySet();
                METAZONE_IDS = Collections.unmodifiableSet(keys);
            }
        }
    }
    return METAZONE_IDS;
}
 
Example #26
Source File: ICUResourceBundleReader.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int getInt() {
    if (RES_GET_TYPE(res) != UResourceBundle.INT) {
        throw new UResourceTypeMismatchException("");
    }
    return RES_GET_INT(res);
}
 
Example #27
Source File: ListFormatObject.java    From es6draft with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
private ListFormatter createListFormatter() {
    ULocale locale = ULocale.forLanguageTag(this.locale);
    ICUResourceBundle r = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, locale);
    String resourceStyle = resourceStyle();
    return new ListFormatter(r.getWithFallback("listPattern/" + resourceStyle + "/2").getString(),
            r.getWithFallback("listPattern/" + resourceStyle + "/start").getString(),
            r.getWithFallback("listPattern/" + resourceStyle + "/middle").getString(),
            r.getWithFallback("listPattern/" + resourceStyle + "/end").getString());
}
 
Example #28
Source File: ICUResourceTableAccess.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Utility to fetch locale display data from resource bundle tables.  Convenience
 * wrapper for {@link #getTableString(ICUResourceBundle, String, String, String, String)}.
 */
public static String getTableString(String path, ULocale locale, String tableName,
        String itemName, String defaultValue) {
    ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.
        getBundleInstance(path, locale.getBaseName());
    return getTableString(bundle, tableName, null, itemName, defaultValue);
}
 
Example #29
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;
}
 
Example #30
Source File: ZoneMeta.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
private static synchronized String[] getZoneIDs() {
    if (ZONEIDS == null) {
        try {
            UResourceBundle top = UResourceBundle.getBundleInstance(
                    ICUData.ICU_BASE_NAME, ZONEINFORESNAME, ICUResourceBundle.ICU_DATA_CLASS_LOADER);
            ZONEIDS = top.getStringArray(kNAMES);
        } catch (MissingResourceException ex) {
            // throw away..
        }
    }
    if (ZONEIDS == null) {
        ZONEIDS = new String[0];
    }
    return ZONEIDS;
}