Class StoredBundleFactory

java.lang.Object
org.tentackle.common.DefaultBundleFactory
org.tentackle.i18n.StoredBundleFactory
All Implemented Interfaces:
org.tentackle.common.BundleFactory

@Service(org.tentackle.common.BundleFactory.class) public class StoredBundleFactory extends org.tentackle.common.DefaultBundleFactory
Bundle factory that loads the bundles of named modules from the database.

Replaces the DefaultBundleFactory. For each bundle registered via BundleSupport, it loads the StoredBundles of the requested locale and its parent locales, chains them as StoredResourceBundles and appends the property-file bundle as the last resort, unless fallbackToProperties is turned off. The resulting chains are cached until a StoredBundle is modified.
In non-modular applications, all bundles are loaded through the StoredBundleControl handed out by the StoredBundleControlProvider instead.

Without a current Session, or if disabled, the factory behaves like the DefaultBundleFactory. Bundles loaded before the first session became available are discarded as soon as it does, so that the stored bundles take over.

  • Constructor Details

    • StoredBundleFactory

      public StoredBundleFactory()
      Creates the bundle factory.
  • Method Details

    • isEnabled

      public static boolean isEnabled()
      Returns whether loading bundles from the backend is enabled at all.
      Returns:
      true if enabled (default)
    • setEnabled

      public static void setEnabled(boolean enabled)
      Sets whether loading bundles from the backend is enabled at all.

      Applies to the bundles loaded by this factory as well as to those loaded by the StoredBundleControl. Bundles already cached are not affected: set the flag before the first lookup, or invoke BundleFactory.clearCache() afterward.

      Parameters:
      enabled - true if enabled (default)
    • clearCache

      public void clearCache()
      Specified by:
      clearCache in interface org.tentackle.common.BundleFactory
      Overrides:
      clearCache in class org.tentackle.common.DefaultBundleFactory
    • findBundle

      public ResourceBundle findBundle(String baseName, Locale locale)
      Specified by:
      findBundle in interface org.tentackle.common.BundleFactory
      Overrides:
      findBundle in class org.tentackle.common.DefaultBundleFactory
    • findBundle

      public ResourceBundle findBundle(String baseName, Locale locale, ClassLoader loader)
      Specified by:
      findBundle in interface org.tentackle.common.BundleFactory
      Overrides:
      findBundle in class org.tentackle.common.DefaultBundleFactory
    • getBundle

      protected ResourceBundle getBundle(org.tentackle.common.BundleSupport support, Locale locale)
      Overrides:
      getBundle in class org.tentackle.common.DefaultBundleFactory
    • loadStoredBundleChain

      Loads the stored bundle for a key and chains the stored bundles of the parent locales to it.

      Locales without a stored bundle are skipped, both when looking for the bundle itself and when linking its parents, just as ResourceBundle does for its list of candidate locales. A stored Texts_de_DE, for example, gets a stored Texts as its parent if there is no Texts_de.

      Parameters:
      topKey - the key of the requested bundle
      loader - loads the stored bundle for a key, returns null if there is no such bundle
      Returns:
      the bundle with its parents linked, null if nothing is stored for the key or any of its parent locales