Class SmartResourceBundle

java.lang.Object
se.datadosen.util.SmartResourceBundle
All Implemented Interfaces:
java.io.Serializable

public class SmartResourceBundle
extends java.lang.Object
implements java.io.Serializable
Similar to java.util.ResourceBundle, but handles property files containing UTF-8 encoded characters (auto-senses)
See Also:
Serialized Form
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected SmartResourceBundle parent
    The parent bundle of this bundle.
    protected java.util.Map resources  
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected SmartResourceBundle()
    Sole constructor.
  • Method Summary

    Modifier and Type Method Description
    static SmartResourceBundle getBundle​(java.io.File dir, java.lang.String baseName)
    Get resource bundle vs given directory
    static SmartResourceBundle getBundle​(java.io.File dir, java.lang.String baseName, java.util.Locale locale)
    Get resource bundle vs given directory
    static SmartResourceBundle getBundle​(java.lang.Class caller, java.lang.String baseName)
    Get resource bundle vs callers class
    static SmartResourceBundle getBundle​(java.lang.Class callerClass, java.lang.String baseName, java.util.Locale locale)
    Get resource bundle vs callers class
    java.util.Set getKeys()
    Returns an enumeration of the keys.
    java.util.Locale getLocale()
    Returns the locale of this resource bundle.
    java.lang.Object getObject​(java.lang.String key)
    Gets an object for the given key from this resource bundle or one of its parents.
    java.lang.String getString​(java.lang.String key)
    Gets a string for the given key from this resource bundle or one of its parents.
    java.lang.String[] getStringArray​(java.lang.String key)
    Gets a string array for the given key from this resource bundle or one of its parents.
    boolean isTranslated​(java.lang.String key)  
    static void main​(java.lang.String[] args)  
    protected void setParent​(SmartResourceBundle parent)
    Sets the parent bundle of this bundle.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • resources

      protected java.util.Map resources
    • parent

      protected SmartResourceBundle parent
      The parent bundle of this bundle. The parent bundle is searched by getObject when this bundle does not contain a particular resource.
  • Constructor Details

    • SmartResourceBundle

      protected SmartResourceBundle()
      Sole constructor. (For invocation by subclass constructors, typically implicit.)
  • Method Details

    • getString

      public final java.lang.String getString​(java.lang.String key)
      Gets a string for the given key from this resource bundle or one of its parents. Calling this method is equivalent to calling
      (String) getObject(key).
      Parameters:
      key - the key for the desired string
      Returns:
      the string for the given key
    • getStringArray

      public final java.lang.String[] getStringArray​(java.lang.String key)
      Gets a string array for the given key from this resource bundle or one of its parents. Calling this method is equivalent to calling
      (String[]) getObject(key).
      Parameters:
      key - the key for the desired string array
      Returns:
      the string array for the given key
    • isTranslated

      public final boolean isTranslated​(java.lang.String key)
    • getObject

      public final java.lang.Object getObject​(java.lang.String key)
      Gets an object for the given key from this resource bundle or one of its parents. This method first tries to obtain the object from this resource bundle using get. If not successful, and the parent resource bundle is not null, it calls the parent's getObject method. If still not successful, it throws a MissingResourceException.
      Parameters:
      key - the key for the desired object
      Returns:
      the object for the given key
      Throws:
      java.util.MissingResourceException - if no object for the given key can be found
    • getLocale

      public java.util.Locale getLocale()
      Returns the locale of this resource bundle. This method can be used after a call to getBundle() to determine whether the resource bundle returned really corresponds to the requested locale or is a fallback.
      Returns:
      the locale of this resource bundle
    • setParent

      protected void setParent​(SmartResourceBundle parent)
      Sets the parent bundle of this bundle. The parent bundle is searched by getObject when this bundle does not contain a particular resource.
      Parameters:
      parent - this bundle's parent bundle.
    • getBundle

      public static SmartResourceBundle getBundle​(java.io.File dir, java.lang.String baseName)
      Get resource bundle vs given directory
    • getBundle

      public static SmartResourceBundle getBundle​(java.io.File dir, java.lang.String baseName, java.util.Locale locale)
      Get resource bundle vs given directory
    • getBundle

      public static final SmartResourceBundle getBundle​(java.lang.Class caller, java.lang.String baseName)
      Get resource bundle vs callers class
      Since:
      8.1
    • getBundle

      public static final SmartResourceBundle getBundle​(java.lang.Class callerClass, java.lang.String baseName, java.util.Locale locale)
      Get resource bundle vs callers class
      Since:
      8.1
    • getKeys

      public java.util.Set getKeys()
      Returns an enumeration of the keys.
      Returns:
    • main

      public static void main​(java.lang.String[] args)