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

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

源代码1 项目: Bytecoder   文件: LocaleResources.java
/**
 * Returns the compact number format patterns.
 * @param formatStyle the style for formatting a number
 * @return an array of compact number patterns
 */
@SuppressWarnings("unchecked")
public String[] getCNPatterns(NumberFormat.Style formatStyle) {

    Objects.requireNonNull(formatStyle);
    String[] compactNumberPatterns = null;
    removeEmptyReferences();
    String width = (formatStyle == NumberFormat.Style.LONG) ? "long" : "short";
    String cacheKey = width + "." + COMPACT_NUMBER_PATTERNS_CACHEKEY;
    ResourceReference data = cache.get(cacheKey);
    if (data == null || ((compactNumberPatterns
            = (String[]) data.get()) == null)) {
        ResourceBundle resource = localeData.getNumberFormatData(locale);
        compactNumberPatterns = (String[]) resource
                .getObject(width + ".CompactNumberPatterns");
        cache.put(cacheKey, new ResourceReference(cacheKey,
                (Object) compactNumberPatterns, referenceQueue));
    }
    return compactNumberPatterns;
}
 
源代码2 项目: lucene-solr   文件: NLS.java
private static Object getResourceBundleObject(String messageKey, Locale locale) {

    // slow resource checking
    // need to loop thru all registered resource bundles
    for (Iterator<String> it = bundles.keySet().iterator(); it.hasNext();) {
      Class<? extends NLS> clazz = bundles.get(it.next());
      ResourceBundle resourceBundle = ResourceBundle.getBundle(clazz.getName(),
          locale);
      if (resourceBundle != null) {
        try {
          Object obj = resourceBundle.getObject(messageKey);
          if (obj != null)
            return obj;
        } catch (MissingResourceException e) {
          // just continue it might be on the next resource bundle
        }
      }
    }
    // if resource is not found
    return null;
  }
 
源代码3 项目: TencentKona-8   文件: ComponentOrientation.java
/**
 * Returns the orientation appropriate for the given ResourceBundle's
 * localization.  Three approaches are tried, in the following order:
 * <ol>
 * <li>Retrieve a ComponentOrientation object from the ResourceBundle
 *      using the string "Orientation" as the key.
 * <li>Use the ResourceBundle.getLocale to determine the bundle's
 *      locale, then return the orientation for that locale.
 * <li>Return the default locale's orientation.
 * </ol>
 *
 * @deprecated As of J2SE 1.4, use {@link #getOrientation(java.util.Locale)}.
 */
@Deprecated
public static ComponentOrientation getOrientation(ResourceBundle bdl)
{
    ComponentOrientation result = null;

    try {
        result = (ComponentOrientation)bdl.getObject("Orientation");
    }
    catch (Exception e) {
    }

    if (result == null) {
        result = getOrientation(bdl.getLocale());
    }
    if (result == null) {
        result = getOrientation(Locale.getDefault());
    }
    return result;
}
 
源代码4 项目: Bytecoder   文件: ComponentOrientation.java
/**
 * Returns the orientation appropriate for the given ResourceBundle's
 * localization.  Three approaches are tried, in the following order:
 * <ol>
 * <li>Retrieve a ComponentOrientation object from the ResourceBundle
 *      using the string "Orientation" as the key.
 * <li>Use the ResourceBundle.getLocale to determine the bundle's
 *      locale, then return the orientation for that locale.
 * <li>Return the default locale's orientation.
 * </ol>
 *
 * @param  bdl the bundle to use
 * @return the orientation
 * @deprecated As of J2SE 1.4, use {@link #getOrientation(java.util.Locale)}.
 */
@Deprecated
public static ComponentOrientation getOrientation(ResourceBundle bdl)
{
    ComponentOrientation result = null;

    try {
        result = (ComponentOrientation)bdl.getObject("Orientation");
    }
    catch (Exception e) {
    }

    if (result == null) {
        result = getOrientation(bdl.getLocale());
    }
    if (result == null) {
        result = getOrientation(Locale.getDefault());
    }
    return result;
}
 
源代码5 项目: dragonwell8_jdk   文件: UIDefaults.java
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
                ResourceBundle b;
                if (c != null) {
                    b = ResourceBundle.getBundle(bundleName, l, c);
                } else {
                    b = ResourceBundle.getBundle(bundleName, l,
                            ClassLoader.getSystemClassLoader());
                }
                Enumeration keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = (String)keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
源代码6 项目: jdk8u-dev-jdk   文件: UIDefaults.java
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
                ResourceBundle b;
                if (c != null) {
                    b = ResourceBundle.getBundle(bundleName, l, c);
                } else {
                    b = ResourceBundle.getBundle(bundleName, l);
                }
                Enumeration keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = (String)keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
源代码7 项目: openjdk-jdk8u-backup   文件: UIDefaults.java
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
                ResourceBundle b;
                if (c != null) {
                    b = ResourceBundle.getBundle(bundleName, l, c);
                } else {
                    b = ResourceBundle.getBundle(bundleName, l,
                            ClassLoader.getSystemClassLoader());
                }
                Enumeration keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = (String)keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
源代码8 项目: Penetration_Testing_POC   文件: MapUtils.java
/**
 * Creates a new HashMap using data copied from a ResourceBundle.
 * 
 * @param resourceBundle  the resource bundle to convert, may not be null
 * @return the hashmap containing the data
 * @throws NullPointerException if the bundle is null
 */
public static Map toMap(final ResourceBundle resourceBundle) {
    Enumeration enumeration = resourceBundle.getKeys();
    Map map = new HashMap();

    while (enumeration.hasMoreElements()) {
        String key = (String) enumeration.nextElement();
        Object value = resourceBundle.getObject(key);
        map.put(key, value);
    }
    
    return map;
}
 
源代码9 项目: hadoop   文件: ResourceBundles.java
/**
 * Get a resource given bundle name and key
 * @param <T> type of the resource
 * @param bundleName name of the resource bundle
 * @param key to lookup the resource
 * @param suffix for the key to lookup
 * @param defaultValue of the resource
 * @return the resource or the defaultValue
 * @throws ClassCastException if the resource found doesn't match T
 */
@SuppressWarnings("unchecked")
public static synchronized <T> T getValue(String bundleName, String key,
                                          String suffix, T defaultValue) {
  T value;
  try {
    ResourceBundle bundle = getBundle(bundleName);
    value = (T) bundle.getObject(getLookupKey(key, suffix));
  }
  catch (Exception e) {
    return defaultValue;
  }
  return value;
}
 
源代码10 项目: Bytecoder   文件: UIDefaults.java
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                ResourceBundle b;
                if (isDesktopResourceBundle(bundleName)) {
                    // load resource bundle from java.desktop module
                    b = ResourceBundle.getBundle(bundleName, l, UIDefaults.class.getModule());
                } else {
                    b = ResourceBundle.getBundle(bundleName, l, ClassLoader.getSystemClassLoader());
                }
                Enumeration<String> keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
源代码11 项目: jdk8u-jdk   文件: UIDefaults.java
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
                ResourceBundle b;
                if (c != null) {
                    b = ResourceBundle.getBundle(bundleName, l, c);
                } else {
                    b = ResourceBundle.getBundle(bundleName, l);
                }
                Enumeration keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = (String)keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
源代码12 项目: openjdk-8-source   文件: UIDefaults.java
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
                ResourceBundle b;
                if (c != null) {
                    b = ResourceBundle.getBundle(bundleName, l, c);
                } else {
                    b = ResourceBundle.getBundle(bundleName, l);
                }
                Enumeration keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = (String)keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
源代码13 项目: big-c   文件: ResourceBundles.java
/**
 * Get a resource given bundle name and key
 * @param <T> type of the resource
 * @param bundleName name of the resource bundle
 * @param key to lookup the resource
 * @param suffix for the key to lookup
 * @param defaultValue of the resource
 * @return the resource or the defaultValue
 * @throws ClassCastException if the resource found doesn't match T
 */
@SuppressWarnings("unchecked")
public static synchronized <T> T getValue(String bundleName, String key,
                                          String suffix, T defaultValue) {
  T value;
  try {
    ResourceBundle bundle = getBundle(bundleName);
    value = (T) bundle.getObject(getLookupKey(key, suffix));
  }
  catch (Exception e) {
    return defaultValue;
  }
  return value;
}
 
源代码14 项目: openjdk-8   文件: 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;
}
 
源代码15 项目: openjdk-8-source   文件: 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;
}
 
源代码16 项目: dragonwell8_jdk   文件: 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;
}
 
源代码17 项目: jdk8u60   文件: 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;
}
 
源代码18 项目: JDKSourceCode1.8   文件: 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;
}
 
源代码19 项目: jdk8u-dev-jdk   文件: 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;
}
 
源代码20 项目: mpxj   文件: LocaleData.java
/**
 * Convenience method for retrieving an Object resource.
 *
 * @param locale locale identifier
 * @param key resource key
 * @return resource value
 */
public static final Object getObject(Locale locale, String key)
{
   ResourceBundle bundle = ResourceBundle.getBundle(LocaleData.class.getName(), locale);
   return (bundle.getObject(key));
}