java.util.ResourceBundle#containsKey ( )源码实例Demo

下面列出了java.util.ResourceBundle#containsKey ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u-dev-jdk   文件: LocaleResources.java
String[] getJavaTimeNames(String key) {
    String[] names = null;
    String cacheKey = CALENDAR_NAMES + key;

    removeEmptyReferences();
    ResourceReference data = cache.get(cacheKey);

    if (data == null || ((names = (String[]) data.get()) == null)) {
        ResourceBundle rb = getJavaTimeFormatData();
        if (rb.containsKey(key)) {
            names = rb.getStringArray(key);
            cache.put(cacheKey,
                      new ResourceReference(cacheKey, (Object) names, referenceQueue));
        }
    }

    return names;
}
 
源代码2 项目: jdk8u_jdk   文件: LocaleResources.java
int getCalendarData(String key) {
    Integer caldata;
    String cacheKey = CALENDAR_DATA  + key;

    removeEmptyReferences();

    ResourceReference data = cache.get(cacheKey);
    if (data == null || ((caldata = (Integer) data.get()) == null)) {
        ResourceBundle rb = localeData.getCalendarData(locale);
        if (rb.containsKey(key)) {
            caldata = Integer.parseInt(rb.getString(key));
        } else {
            caldata = 0;
        }

        cache.put(cacheKey,
                  new ResourceReference(cacheKey, (Object) caldata, referenceQueue));
    }

    return caldata;
}
 
源代码3 项目: scipio-erp   文件: SeoCatalogUrlWorker.java
/**
 * Tries to create an instance from a property message.
 * <p>
 * FIXME?: there must be a better way than current loop with exception on missing locale...
 */
public static LocalizedName getNormalizedFromProperties(String resource, String name, Locale defaultLocale) {
    Map<String, String> localeValueMap = new HashMap<>();
    for(Locale locale: UtilMisc.availableLocales()) {
        ResourceBundle bundle = null;
        try {
            bundle = UtilProperties.getResourceBundle(resource, locale);
        } catch(Exception e) {
            continue; // when locale is not there, throws IllegalArgumentException
        }
        if (bundle == null || !bundle.containsKey(name)) continue;
        String value = bundle.getString(name);
        if (value == null) continue;
        value = value.trim();
        if (value.isEmpty()) continue;
        localeValueMap.put(locale.toString(), value);
    }
    return new LocalizedName(localeValueMap, defaultLocale);
}
 
源代码4 项目: openemm   文件: ShowNavigationTag.java
private void prepareNavigationDataFromExtensionPoints(ResourceBundle resourceBundle) throws Exception {
	if (!resourceBundle.containsKey("navigation.plugin") || !resourceBundle.containsKey("navigation.extensionpoint")) {
		return;
	}

	//getting data from navigation.property file for the extension point
	String plugin = resourceBundle.getString("navigation.plugin");
	String extensionPoint = resourceBundle.getString("navigation.extensionpoint");

	ExtensionSystem extensionSystem = ExtensionUtils.getExtensionSystem(pageContext.getServletContext());
	if(extensionSystem != null) {
		Collection<Extension> extensions = extensionSystem.getActiveExtensions(plugin, extensionPoint);
		for (Extension extensionItem : extensions) {
			String resourceName = extensionItem.getParameter("navigation-bundle").valueAsString();

			ResourceBundle extensionBundle = extensionSystem.getPluginResourceBundle(extensionItem.getDeclaringPluginDescriptor().getId(), resourceName);
			prepareNavigationDataFromResourceBundle(extensionBundle, extensionItem.getDeclaringPluginDescriptor().getId(), extensionItem.getId());
		}
	} else {
		logger.warn("No active Navigation extensions for plugin '" + plugin + "' defined");
	}
}
 
源代码5 项目: openjdk-8   文件: LocaleResources.java
int getCalendarData(String key) {
    Integer caldata;
    String cacheKey = CALENDAR_DATA  + key;

    removeEmptyReferences();

    ResourceReference data = cache.get(cacheKey);
    if (data == null || ((caldata = (Integer) data.get()) == null)) {
        ResourceBundle rb = localeData.getCalendarData(locale);
        if (rb.containsKey(key)) {
            caldata = Integer.parseInt(rb.getString(key));
        } else {
            caldata = 0;
        }

        cache.put(cacheKey,
                  new ResourceReference(cacheKey, (Object) caldata, referenceQueue));
    }

    return caldata;
}
 
源代码6 项目: Bytecoder   文件: LocaleResources.java
String[] getCalendarNames(String key) {
    String[] names = null;
    String cacheKey = CALENDAR_NAMES + key;

    removeEmptyReferences();
    ResourceReference data = cache.get(cacheKey);

    if (data == null || ((names = (String[]) data.get()) == null)) {
        ResourceBundle rb = localeData.getDateFormatData(locale);
        if (rb.containsKey(key)) {
            names = rb.getStringArray(key);
            cache.put(cacheKey,
                      new ResourceReference(cacheKey, (Object) names, referenceQueue));
        }
    }

    return names;
}
 
源代码7 项目: dragonwell8_jdk   文件: LocaleResources.java
public String getCollationData() {
    String key = "Rule";
    String coldata = "";

    removeEmptyReferences();
    ResourceReference data = cache.get(COLLATION_DATA_CACHEKEY);
    if (data == null || ((coldata = (String) data.get()) == null)) {
        ResourceBundle rb = localeData.getCollationData(locale);
        if (rb.containsKey(key)) {
            coldata = rb.getString(key);
        }
        cache.put(COLLATION_DATA_CACHEKEY,
                  new ResourceReference(COLLATION_DATA_CACHEKEY, (Object) coldata, referenceQueue));
    }

    return coldata;
}
 
源代码8 项目: openjdk-8-source   文件: LocaleResources.java
String[] getJavaTimeNames(String key) {
    String[] names = null;
    String cacheKey = CALENDAR_NAMES + key;

    removeEmptyReferences();
    ResourceReference data = cache.get(cacheKey);

    if (data == null || ((names = (String[]) data.get()) == null)) {
        ResourceBundle rb = getJavaTimeFormatData();
        if (rb.containsKey(key)) {
            names = rb.getStringArray(key);
            cache.put(cacheKey,
                      new ResourceReference(cacheKey, (Object) names, referenceQueue));
        }
    }

    return names;
}
 
源代码9 项目: openjdk-jdk8u   文件: LocaleResources.java
String[] getCalendarNames(String key) {
    String[] names = null;
    String cacheKey = CALENDAR_NAMES + key;

    removeEmptyReferences();
    ResourceReference data = cache.get(cacheKey);

    if (data == null || ((names = (String[]) data.get()) == null)) {
        ResourceBundle rb = localeData.getDateFormatData(locale);
        if (rb.containsKey(key)) {
            names = rb.getStringArray(key);
            cache.put(cacheKey,
                      new ResourceReference(cacheKey, (Object) names, referenceQueue));
        }
    }

    return names;
}
 
源代码10 项目: jdk8u60   文件: LocaleResources.java
public String getCollationData() {
    String key = "Rule";
    String coldata = "";

    removeEmptyReferences();
    ResourceReference data = cache.get(COLLATION_DATA_CACHEKEY);
    if (data == null || ((coldata = (String) data.get()) == null)) {
        ResourceBundle rb = localeData.getCollationData(locale);
        if (rb.containsKey(key)) {
            coldata = rb.getString(key);
        }
        cache.put(COLLATION_DATA_CACHEKEY,
                  new ResourceReference(COLLATION_DATA_CACHEKEY, (Object) coldata, referenceQueue));
    }

    return coldata;
}
 
源代码11 项目: hottub   文件: WeekFields.java
@Override
public String getDisplayName(Locale locale) {
    Objects.requireNonNull(locale, "locale");
    if (rangeUnit == YEARS) {  // only have values for week-of-year
        LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
                .getLocaleResources(locale);
        ResourceBundle rb = lr.getJavaTimeFormatData();
        return rb.containsKey("field.week") ? rb.getString("field.week") : name;
    }
    return name;
}
 
源代码12 项目: openjdk-jdk8u   文件: WeekFields.java
@Override
public String getDisplayName(Locale locale) {
    Objects.requireNonNull(locale, "locale");
    if (rangeUnit == YEARS) {  // only have values for week-of-year
        LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
                .getLocaleResources(locale);
        ResourceBundle rb = lr.getJavaTimeFormatData();
        return rb.containsKey("field.week") ? rb.getString("field.week") : name;
    }
    return name;
}
 
源代码13 项目: openemm   文件: I18NResourceBundle.java
public String getMessage(String key, Locale locale) throws Exception {
	ResourceBundle languageBundle = getMessageBundle( locale.getLanguage() + "_" + locale.getCountry());		
	if( languageBundle != null && languageBundle.containsKey( key))
		return languageBundle.getString( key);
	
	languageBundle = getMessageBundle( locale.getLanguage());
	if( languageBundle != null && languageBundle.containsKey( key))
		return languageBundle.getString( key);

	languageBundle = getMessageBundle( "");
	if( languageBundle != null && languageBundle.containsKey( key))
		return languageBundle.getString( key);
	
	return null;
}
 
源代码14 项目: jdk8u-jdk   文件: WeekFields.java
@Override
public String getDisplayName(Locale locale) {
    Objects.requireNonNull(locale, "locale");
    if (rangeUnit == YEARS) {  // only have values for week-of-year
        LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
                .getLocaleResources(locale);
        ResourceBundle rb = lr.getJavaTimeFormatData();
        return rb.containsKey("field.week") ? rb.getString("field.week") : name;
    }
    return name;
}
 
源代码15 项目: jdk8u-jdk   文件: IsoFields.java
@Override
public String getDisplayName(Locale locale) {
    Objects.requireNonNull(locale, "locale");
    LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
                                .getLocaleResources(locale);
    ResourceBundle rb = lr.getJavaTimeFormatData();
    return rb.containsKey("field.week") ? rb.getString("field.week") : toString();
}
 
源代码16 项目: openjdk-jdk8u   文件: DateFormatSymbols.java
/**
 * Initializes this DateFormatSymbols with the locale data. This method uses
 * a cached DateFormatSymbols instance for the given locale if available. If
 * there's no cached one, this method creates an uninitialized instance and
 * populates its fields from the resource bundle for the locale, and caches
 * the instance. Note: zoneStrings isn't initialized in this method.
 */
private void initializeData(Locale locale) {
    SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
    DateFormatSymbols dfs;
    if (ref == null || (dfs = ref.get()) == null) {
        if (ref != null) {
            // Remove the empty SoftReference
            cachedInstances.remove(locale, ref);
        }
        dfs = new DateFormatSymbols(false);

        // Initialize the fields from the ResourceBundle for locale.
        LocaleProviderAdapter adapter
            = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
        // Avoid any potential recursions
        if (!(adapter instanceof ResourceBundleBasedAdapter)) {
            adapter = LocaleProviderAdapter.getResourceBundleBased();
        }
        ResourceBundle resource
            = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale);

        dfs.locale = locale;
        // JRE and CLDR use different keys
        // JRE: Eras, short.Eras and narrow.Eras
        // CLDR: long.Eras, Eras and narrow.Eras
        if (resource.containsKey("Eras")) {
            dfs.eras = resource.getStringArray("Eras");
        } else if (resource.containsKey("long.Eras")) {
            dfs.eras = resource.getStringArray("long.Eras");
        } else if (resource.containsKey("short.Eras")) {
            dfs.eras = resource.getStringArray("short.Eras");
        }
        dfs.months = resource.getStringArray("MonthNames");
        dfs.shortMonths = resource.getStringArray("MonthAbbreviations");
        dfs.ampms = resource.getStringArray("AmPmMarkers");
        dfs.localPatternChars = resource.getString("DateTimePatternChars");

        // Day of week names are stored in a 1-based array.
        dfs.weekdays = toOneBasedArray(resource.getStringArray("DayNames"));
        dfs.shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations"));

        // Put dfs in the cache
        ref = new SoftReference<>(dfs);
        SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref);
        if (x != null) {
            DateFormatSymbols y = x.get();
            if (y == null) {
                // Replace the empty SoftReference with ref.
                cachedInstances.replace(locale, x, ref);
            } else {
                ref = x;
                dfs = y;
            }
        }
        // If the bundle's locale isn't the target locale, put another cache
        // entry for the bundle's locale.
        Locale bundleLocale = resource.getLocale();
        if (!bundleLocale.equals(locale)) {
            SoftReference<DateFormatSymbols> z
                = cachedInstances.putIfAbsent(bundleLocale, ref);
            if (z != null && z.get() == null) {
                cachedInstances.replace(bundleLocale, z, ref);
            }
        }
    }

    // Copy the field values from dfs to this instance.
    copyMembers(dfs, this);
}
 
源代码17 项目: dragonwell8_jdk   文件: DateFormatSymbols.java
/**
 * Initializes this DateFormatSymbols with the locale data. This method uses
 * a cached DateFormatSymbols instance for the given locale if available. If
 * there's no cached one, this method creates an uninitialized instance and
 * populates its fields from the resource bundle for the locale, and caches
 * the instance. Note: zoneStrings isn't initialized in this method.
 */
private void initializeData(Locale locale) {
    SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
    DateFormatSymbols dfs;
    if (ref == null || (dfs = ref.get()) == null) {
        if (ref != null) {
            // Remove the empty SoftReference
            cachedInstances.remove(locale, ref);
        }
        dfs = new DateFormatSymbols(false);

        // Initialize the fields from the ResourceBundle for locale.
        LocaleProviderAdapter adapter
            = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
        // Avoid any potential recursions
        if (!(adapter instanceof ResourceBundleBasedAdapter)) {
            adapter = LocaleProviderAdapter.getResourceBundleBased();
        }
        ResourceBundle resource
            = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale);

        dfs.locale = locale;
        // JRE and CLDR use different keys
        // JRE: Eras, short.Eras and narrow.Eras
        // CLDR: long.Eras, Eras and narrow.Eras
        if (resource.containsKey("Eras")) {
            dfs.eras = resource.getStringArray("Eras");
        } else if (resource.containsKey("long.Eras")) {
            dfs.eras = resource.getStringArray("long.Eras");
        } else if (resource.containsKey("short.Eras")) {
            dfs.eras = resource.getStringArray("short.Eras");
        }
        dfs.months = resource.getStringArray("MonthNames");
        dfs.shortMonths = resource.getStringArray("MonthAbbreviations");
        dfs.ampms = resource.getStringArray("AmPmMarkers");
        dfs.localPatternChars = resource.getString("DateTimePatternChars");

        // Day of week names are stored in a 1-based array.
        dfs.weekdays = toOneBasedArray(resource.getStringArray("DayNames"));
        dfs.shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations"));

        // Put dfs in the cache
        ref = new SoftReference<>(dfs);
        SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref);
        if (x != null) {
            DateFormatSymbols y = x.get();
            if (y == null) {
                // Replace the empty SoftReference with ref.
                cachedInstances.replace(locale, x, ref);
            } else {
                ref = x;
                dfs = y;
            }
        }
        // If the bundle's locale isn't the target locale, put another cache
        // entry for the bundle's locale.
        Locale bundleLocale = resource.getLocale();
        if (!bundleLocale.equals(locale)) {
            SoftReference<DateFormatSymbols> z
                = cachedInstances.putIfAbsent(bundleLocale, ref);
            if (z != null && z.get() == null) {
                cachedInstances.replace(bundleLocale, z, ref);
            }
        }
    }

    // Copy the field values from dfs to this instance.
    copyMembers(dfs, this);
}
 
源代码18 项目: sldeditor   文件: Localisation.java
/**
 * Gets the string for the supplied class and key.
 *
 * @param clazz the class to get the strings for
 * @param key the key
 * @return the string
 */
public static String getString(Class<?> clazz, String key) {

    String baseName = null;
    String className;

    if((key != null) && key.startsWith(COMMON_PREFIX))
    {
        baseName = DEFAULT_BASE_NAME;
        className = "SLDEditor";
    }
    else
    {
        String fullPackageName = clazz.getPackage().getName();
        String[] packages = fullPackageName.split("\\.");

        if(packages.length == 2)
        {
            baseName = DEFAULT_BASE_NAME;
        }
        else
        {
            baseName = packages[2];
        }

        className = clazz.getSimpleName();
    }

    ResourceBundle resourceBundle = getInstance().getResourceBundle(String.format("%s/%s/%s", RESOURCE_FOLDER, baseName, className));

    if((resourceBundle == null) || (key == null))
    {
        return key;
    }
    else
    {
        if(resourceBundle.containsKey(key))
        {
            return resourceBundle.getString(key);
        }
        else
        {
            return key;
        }
    }
}
 
/**
 * Efficiently retrieve the String value for the specified key,
 * or return {@code null} if not found.
 * <p>As of 4.2, the default implementation checks {@code containsKey}
 * before it attempts to call {@code getString} (which would require
 * catching {@code MissingResourceException} for key not found).
 * <p>Can be overridden in subclasses.
 * @param bundle the ResourceBundle to perform the lookup in
 * @param key the key to look up
 * @return the associated value, or {@code null} if none
 * @since 4.2
 * @see ResourceBundle#getString(String)
 * @see ResourceBundle#containsKey(String)
 */
@Nullable
protected String getStringOrNull(ResourceBundle bundle, String key) {
	if (bundle.containsKey(key)) {
		try {
			return bundle.getString(key);
		}
		catch (MissingResourceException ex){
			// Assume key not found for some other reason
			// -> do NOT throw the exception to allow for checking parent message source.
		}
	}
	return null;
}
 
源代码20 项目: openjdk-jdk8u   文件: DateTimeTextProvider.java
/**
 * Returns the localized resource of the given key and locale, or null
 * if no localized resource is available.
 *
 * @param key  the key of the localized resource, not null
 * @param locale  the locale, not null
 * @return the localized resource, or null if not available
 * @throws NullPointerException if key or locale is null
 */
@SuppressWarnings("unchecked")
static <T> T getLocalizedResource(String key, Locale locale) {
    LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
                                .getLocaleResources(locale);
    ResourceBundle rb = lr.getJavaTimeFormatData();
    return rb.containsKey(key) ? (T) rb.getObject(key) : null;
}