Class Localizer

java.lang.Object
org.ka2ddo.yaac.util.Localizer

public class Localizer extends Object
This class wraps all the business logic for searching ResourceBundles for localized text messages for display on the UI and in reports. This will be used to phase out dependencies on the YAAC main class (where these methods were originally located) from code packages that do not depend on being in the YAAC application.
Author:
Andrew Pavlin, KA2DDO
  • Constructor Details

    • Localizer

      public Localizer()
  • Method Details

    • setContextClassLoader

      public static void setContextClassLoader(ClassLoader cl)
      Update the ClassLoader hierarchy that will be used to look for ResourceBundle property files. This should be called by any code that dynamically loads additional jar files into the Java virtual machine after the jar file this class comes from.
      Parameters:
      cl - ClassLoader to be the most complete set available
    • getMsgBundle

      public static ResourceBundle getMsgBundle()
      Get the appropriate locale-specific message bundle for YAAC.
      Returns:
      a ResourceBundle that is the most locale-specific possible for the runtime environment
    • getMsgBundle

      public static ResourceBundle getMsgBundle(String altBundleName)
      Get the appropriate locale-specific variant of some message bundle in one or more of the provided plugins.
      Parameters:
      altBundleName - String base name of the ResourceBundle to search for
      Returns:
      a ResourceBundle that is the most locale-specific possible for the runtime environment
    • getMsg

      public static String getMsg(String tagName) throws MissingResourceException
      Get the appropriate localized String corresponding to a ResourceBundle tag name in a specific ResourceBundle. If the tagName String contains a colon ':', this is the delimiter between the ResourceBundle name and the name of the resource within the bundle; otherwise, the entire tagName string is considered to be the name of the resource within the default bundle.
      Parameters:
      tagName - String name to look up
      Returns:
      localized String corresponding to the tag, or NoSuchResourceException if the if the tag cannot be found
      Throws:
      MissingResourceException - if the tag cannot be found
    • getMsgNoException

      public static String getMsgNoException(String tagName) throws MissingResourceException
      Get the appropriate localized String corresponding to a ResourceBundle tag name in a specific ResourceBundle. If the tagName String contains a colon ':', this is the delimiter between the ResourceBundle name and the name of the resource within the bundle; otherwise, the entire tagName string is considered to be the name of the resource within the default bundle.
      Parameters:
      tagName - String name to look up
      Returns:
      localized String corresponding to the tag, or null if the if the tag cannot be found
      Throws:
      MissingResourceException - if the ResourceBundle cannot be found
    • getMsg

      public static String getMsg(String bundleBaseName, String tagName) throws MissingResourceException
      Get the appropriate localized String corresponding to a ResourceBundle tag name in a specific ResourceBundle.
      Parameters:
      bundleBaseName - String name of bundle containing the tag
      tagName - String name to look up
      Returns:
      localized String corresponding to the tag, or NoSuchResourceException if the if the tag cannot be found
      Throws:
      MissingResourceException - if the bundle or tag cannot be found