Class RefResourceBundle

java.lang.Object
com.apgar.common.lib.properties.RefResourceBundle

public class RefResourceBundle extends Object
This class provides access to localized resource files. It allows loading properties files and retrieving values based on keys.

Key functionalities include:

  • Loading properties files for different locales.
  • Retrieving values associated with keys.
  • Formatting strings with dynamic parameters.
Author:
APGAR Consulting
  • Constructor Details

    • RefResourceBundle

      public RefResourceBundle(String pName, Locale pLocale)
      Loads the global properties file.
      Parameters:
      pName - the name of the properties file (without the file extension).
      pLocale - the locale for which the properties are loaded.
    • RefResourceBundle

      public RefResourceBundle(String pName, String pMasterDataRefITP)
      Loads a specific properties file.
      Parameters:
      pName - the name of the properties file (without the file extension)
      pMasterDataRefITP - the path to the master data directory
    • RefResourceBundle

      public RefResourceBundle(String pName, Locale pLocale, String pMasterData)
      Loads a specific localized properties file.
      Parameters:
      pName - the name of the properties file (without the file extension)
      pLocale - the locale for which the properties are loaded
      pMasterData - the path to the master data directory
  • Method Details

    • getKeys

      public Enumeration<String> getKeys()
      Retrieves all keys in the resource bundle.
      Returns:
      an enumeration of all keys in the resource bundle
    • getString

      public String getString(String pKey)
      Returns the value corresponding to the specified key. If the key is not found, the method returns the key itself.
      Parameters:
      pKey - the properties key to look up
      Returns:
      the value associated with the specified key, or the key if not found
    • getString

      public String getString(String pString, String[] pParams)
      Returns a formatted string corresponding to the specified key, replacing placeholders with provided parameters.
      Parameters:
      pString - the key of the properties to look up
      pParams - an array of strings to replace placeholders in the value
      Returns:
      the formatted string with parameters replaced
    • getString

      public String getString(String pString, String pParam)
      Returns a formatted string corresponding to the specified key, replacing the placeholder with the provided single parameter.
      Parameters:
      pString - the key of the properties to look up
      pParam - the string to replace the placeholder in the value
      Returns:
      the formatted string with the parameter replaced
    • getStringWithDefault

      public String getStringWithDefault(String pKey, String pDefaultValue)
      Returns the value associated with the specified key, or a default value if the key is not found.
      Parameters:
      pKey - the properties key to look up
      pDefaultValue - the value to return if the key is not found
      Returns:
      the value associated with the specified key, or the default value
    • getErrorMessageBundle

      public static RefResourceBundle getErrorMessageBundle(Locale pLocale)
      Retrieves the error message resource bundle based on the specified locale.
      Parameters:
      pLocale - the locale for which to load the error messages
      Returns:
      a RefResourceBundle containing error messages for the specified locale
    • getErrorMessageBundle

      public static RefResourceBundle getErrorMessageBundle()
      Retrieves the default error message resource bundle.
      Returns:
      a RefResourceBundle containing default error messages
    • getTextBundle

      public static RefResourceBundle getTextBundle(Locale pLocale, String pMasterData)
      Retrieves the text resource bundle for display based on the specified locale and master data.
      Parameters:
      pLocale - the locale for which to load the display texts
      pMasterData - the path to the master data directory
      Returns:
      a RefResourceBundle containing display texts for the specified locale
    • getTextBundle

      public static RefResourceBundle getTextBundle(Locale pLocale)
      Retrieves the text resource bundle for display based on the specified locale.
      Parameters:
      pLocale - the locale for which to load the display texts
      Returns:
      a RefResourceBundle containing display texts for the specified locale
    • getTextBundle

      public static RefResourceBundle getTextBundle()
      Retrieves the default text resource bundle for display.
      Returns:
      a RefResourceBundle containing default display texts
    • getLocale

      public static Locale getLocale(String language)
      Returns a complete Locale object based on the specified language.

      Limitations: Limitations: This method only supports English ("en") and French ("fr").

      Parameters:
      language - the language code (e.g., "en" for English)
      Returns:
      a Locale object corresponding to the specified language; if the input is null or an unsupported language, the default Locale (French) is returned.