Class PropertyBundle

java.lang.Object
org.zkoss.util.resource.PropertyBundle

public class PropertyBundle extends Object
The property bundle.

It is similar to java.util.ResourceBundle, but they differ as follows.

  • It uses Maps.load(Map, InputStream) to load the properties. Thus, It is capable to handle UTF-16 and UTF-8 (but not ISO-8859-1).
  • The locator could be any object as long as it implements InputStream getResourceAsStream(String).
  • It supports only property files.
  • The getBundle method returns null if the resource not found, while ResourceBundle throws MissingResourceException.

Instances of PropertyBundle are cached, so the performance is good. However, it implies the property file mapped by the giving class loader, name and locale is immutable. In other words, if you update the content of a property file, it might not be reflected to getString unless it is cleared out of the cache.

Thread safe.

Author:
tomyeh
  • Constructor Details

    • PropertyBundle

      protected PropertyBundle(String baseName, Locale locale, Locator locator, boolean caseInsensitive)
      Constructor.
      Parameters:
      caseInsensitive - whether the key used to access the map is case-insensitive. If true, all keys are converted to lower cases.
  • Method Details

    • getBundle

      public static final PropertyBundle getBundle(String baseName, Locale locale, Locator locator, boolean caseInsensitive)
      Gets a resource bundle using the specified base name, locale, and locator.
      Parameters:
      locator - the locator (never null). See Locators.getDefault().
      caseInsensitive - whether the key used to access the map is case-insensitive. If true, all keys are converted to lower cases.
      Returns:
      the bundle; null if not found
    • getBundle

      public static final PropertyBundle getBundle(String baseName, Locale locale, Locator locator)
      Gets a resource bundle using the specified base name, locale, and locator.
    • getBundle

      public static final PropertyBundle getBundle(String baseName, Locale locale, boolean caseInsensitive)
      Gets a resource bundle using the specified base name, locale, and the default locator, Locators.getDefault().
      Parameters:
      caseInsensitive - whether the key used to access the map is case-insensitive. If true, all keys are converted to lower cases.
      Returns:
      the bundle; null if not found
    • getBundle

      public static final PropertyBundle getBundle(String baseName, Locale locale)
      Gets a resource bundle using the specified base name, locale, and the default locator, Locators.getDefault().
    • getProperty

      public final String getProperty(String key)
      Returns the property for the given key from this resource bundle or one of its parents.
    • getProperties

      public final Map<String,String> getProperties()
      Returns a map of all properties, (String key , String value).
    • getLocale

      public final Locale getLocale()
      Returns the locale of the bundle, or null if it is the default. Note: it is value might not be the same as the locale being passed to the constructor, because the constructor will do some fallback.