Class ObjectBundle

java.lang.Object
io.sf.jclf.util.locale.ObjectBundle

public class ObjectBundle extends Object
Map of localized objects.

The objects have been initialized with the contents of the files following the schema:

   baseName.ext, baseName.locale.ext
 
  • Constructor Details

    • ObjectBundle

      public ObjectBundle(String path, ResourceFactory rf) throws IOException
      All subclasses constructors MUST call loadDefaultFile().
      Parameters:
      path - Path to default file, optionally including an extension. Separates the extension assuming a '.' as separator.
      rf - the resource factory.
      Throws:
      IOException - if there is a problem loading the default locale file.
    • ObjectBundle

      public ObjectBundle(String baseName, String ext, ResourceFactory rf) throws IOException
      Parameters:
      baseName - Path to default file, without the extension.
      ext - the extension (can be null if none)
      rf - the resource factory.
      Throws:
      IOException - if there is a problem loading the default locale file.
  • Method Details

    • getExtension

      public String getExtension()
      Get the extension associated to this bundle.
      Returns:
      the extension, or null if none.
    • getLastModified

      public long getLastModified()
      Get the last time the resource factory was last modified.
      Returns:
      the last time (in milliseconds) the resource factory was last modified.
    • get

      public Object get()
      Get the object for the default locale.
      Returns:
      Object for the default locale.
    • getBest

      public Object getBest(Locale locale)
      Get the best object associated to the given locale.
      Parameters:
      locale - the locale.
      Returns:
      the object associated to the locale, or the one for the default locale if the object could not be loaded for the given locale.
    • get

      public Object get(Locale locale)
      Get the object associated to the given locale.
      Parameters:
      locale - the locale.
      Returns:
      the object associated to the locale, or null if the object could not be loaded.
    • getBestLocale

      public Locale getBestLocale(Locale[] loc)
      Gets the locale with the best support from those in loc
      Parameters:
      loc - the array with the accepted locales.
      Returns:
      the best locale from loc, or the default one if the best cannot be found.
    • getBestLocale

      public Locale getBestLocale(Enumeration<Locale> locales)
      Gets the locale with the best support from those in loc
      Parameters:
      locales - the Enumeration with the accepted locales.
      Returns:
      the best locale from locales, or the default one if the best cannot be found.
    • loadDefaultFile

      protected void loadDefaultFile() throws IOException
      Throws:
      IOException
    • getDefaultLocale

      public Locale getDefaultLocale()
      Get the default locale. If no default locale was explicitly set, the system's default locale will be returned.
      Returns:
      the default locale.
    • setDefaultLocale

      public void setDefaultLocale(Locale locale)
      Set the default locale.
      Parameters:
      locale - the locale.
    • getBaseName

      public String getBaseName()
      Get the base name of the resource managed by this bundle.

      If the resource filenames are for example like 'foo_en_US.txt', this method will return 'foo', and getExtension 'txt'.

      Returns:
      the base name.
    • toString

      public String toString()
      Overrides:
      toString in class Object