Java Code Examples for java.util.ResourceBundle#getObject()
The following examples show how to use
java.util.ResourceBundle#getObject() .
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: NLS.java From lucene-solr with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: ComponentOrientation.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 3
Source File: LocaleResources.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * 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; }
Example 4
Source File: ComponentOrientation.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * 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; }
Example 5
Source File: ResourceBundles.java From big-c with Apache License 2.0 | 5 votes |
/** * 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; }
Example 6
Source File: UIDefaults.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 7
Source File: UIDefaults.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 8
Source File: UIDefaults.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 9
Source File: UIDefaults.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 10
Source File: MapUtils.java From Penetration_Testing_POC with Apache License 2.0 | 5 votes |
/** * 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; }
Example 11
Source File: UIDefaults.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 12
Source File: ResourceBundles.java From hadoop with Apache License 2.0 | 5 votes |
/** * 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; }
Example 13
Source File: UIDefaults.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * 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; }
Example 14
Source File: DateTimeTextProvider.java From jdk8u60 with GNU General Public License v2.0 | 3 votes |
/** * 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; }
Example 15
Source File: DateTimeTextProvider.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 3 votes |
/** * 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; }
Example 16
Source File: DateTimeTextProvider.java From JDKSourceCode1.8 with MIT License | 3 votes |
/** * 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; }
Example 17
Source File: DateTimeTextProvider.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * 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; }
Example 18
Source File: DateTimeTextProvider.java From openjdk-8-source with GNU General Public License v2.0 | 3 votes |
/** * 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; }
Example 19
Source File: DateTimeTextProvider.java From openjdk-8 with GNU General Public License v2.0 | 3 votes |
/** * 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; }
Example 20
Source File: LocaleData.java From mpxj with GNU Lesser General Public License v2.1 | 2 votes |
/** * 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)); }