Class BundleUtil

java.lang.Object
com.inductiveautomation.ignition.common.BundleUtil

public class BundleUtil extends Object
  • Field Details

    • baseLoader

      protected ClassLoader baseLoader
    • langPackLoader

      protected ClassLoader langPackLoader
    • commonGroup

      protected com.inductiveautomation.ignition.common.BundleUtil.BundleGroup commonGroup
    • subGroups

      protected ConcurrentMap<String,com.inductiveautomation.ignition.common.BundleUtil.BundleGroup> subGroups
    • replacements

      protected List<com.inductiveautomation.ignition.common.BundleUtil.ReplaceToken> replacements
    • versionCache

      protected Map<String,Version> versionCache
    • log

      protected org.apache.log4j.Logger log
  • Method Details

    • get

      public static BundleUtil get()
    • i18n

      public static String i18n(String key, Object... args)
      Static shorthand for BundleUtil.get().getStringLenient(key, args)
    • i18n

      public static String i18n(Locale locale, String key, Object... args)
    • isWhiteLabeled

      public static boolean isWhiteLabeled()
      Tests to see if this is a white-labeled build of Ignition
    • addExternalLookupLocations

      public void addExternalLookupLocations(List<URL> locations)
      Registers locations that will be consulted for translation packs. The URLs must be to jar files or directories.
    • refreshClassLoaders

      protected void refreshClassLoaders()
    • updateLanguagePackLoader

      protected void updateLanguagePackLoader(ClassLoader loader)
    • registerBaseClassLoader

      public void registerBaseClassLoader(ClassLoader loader)
    • getSupportedLocales

      public List<Locale> getSupportedLocales()
      Provides a list of the locales that are currently supported/selectable.
    • addSupportedLocales

      public void addSupportedLocales(Collection<Locale> locales)
    • getLangPackLoader

      public ClassLoader getLangPackLoader()
    • addReplacement

      public void addReplacement(String key, String value)
      Adds a new key, value pair that will be used as a replacement token for all bundle strings. For example, if one added: addReplacement("COMPANY","Acme SuperSCADA");
      then the following resource key:
      mymod.aboutblurb=Brought to you by ${COMPANY}
      would expand to:
      Brought to you by Acme SuperSCADA
    • removeReplacement

      public boolean removeReplacement(String key)
      Removes the replacement with this key.
      Returns:
      true if the key was found.
    • addBundle

      public void addBundle(String prefix, ClassLoader owner, String bundleName)
      Adds a new prefixed sub-bundle with the given classloader. The prefix will be used to retrieve all the keys in the bundle. For example, if you bundle is like:

       Confirm=Are You Sure
       HelpText=Eek!
       

      And you add the bundle like:

       addBundle("MyModule", loader, "com/acme/product/PropFile");
       

      Then you'd get the key like this:

       BundleUtil.get().getString("MyModule.Confirm");
       
    • removeBundle

      public void removeBundle(Class<?> clazz)
      Equiv to removeBundle(clazz.getSimpleName(), clazz.getName().replace('.', '/'));
    • removeBundle

      public void removeBundle(String prefix)
      Removes all bundles added under the given prefix
    • removeBundle

      public void removeBundle(String prefix, String bundleName)
      Removes all the specific bundle that was added under the given prefix and the given bundle name.
    • addBundle

      public void addBundle(Class<?> clazz)
      Shortcut for adding a resource bundle for a specific class whose prefix is the simple classname.

      For example, if you had com.example.MyClass, then you would put a resource file at com/example/MyClass.properties and you would access properties via "MyClass.Keyname"

      Equivalent to:

       addBundle(clazz.getSimpleName(), clazz.getClassLoader(), clazz.getName().replace('.', '/'));
       
    • addBundle

      public void addBundle(String prefix, Class<?> clazz, String bundleName)
      Adds a bundle that is located next to a class with a custom prefix. For example, if you had com.example.MyClass, and a resource file such as com/example/strings.properties, a call such as addBundle("mymod", MyClass.class, "strings"); would let you would access the properties via "mymod.Keyname"
    • addCommonBundle

      public void addCommonBundle(String bundleName)
      Adds a new bundle to the common (non-prefixed) bundle. Only will work if the bundle can be loaded by the classloader that loaded the BundleUtil itself. Will not work for module-supplied bundles.
    • getMnemonic

      public char getMnemonic(String keyName, char fallBack)
      Returns a single char that defines a keyboard shortcut, defined in an externalized file. Takes a fallback return value in case the entry isn't found.
    • getStringLenient

      public String getStringLenient(String keyName)
      Returns the resource string associated with the given keyname, if any. If no resource string is found, the keyname itself is returned, but with question marks around it, like "MyKey?".
    • getStringLenient

      public String getStringLenient(String keyName, Object... formatArgs)
    • getStringLenient

      public String getStringLenient(Locale locale, String keyName, Object... formatArgs)
    • getString

      public String getString(String keyName)
      Looks up the resource string associated with the given keyname. If no resource string is found, null is returned.
    • getString

      public String getString(String keyName, Object... formatArgs)
    • getString

      public String getString(Locale locale, String keyName)
    • getString

      public String getString(Locale locale, String keyName, Object... formatArgs)
    • getDefinedString

      public String getDefinedString(Locale locale, String keyName)
      Returns the raw translated text, after replacements have been made, but without applying any formatting values.
    • isKeyPresent

      public boolean isKeyPresent(String keyName)
    • getRawString

      protected String getRawString(Locale locale, String key)
      Looks up the raw key from the local resource bundles. Returns null if nothing is found. Does not apply replacements or deal with formatting arguments
    • applyReplacements

      protected String applyReplacements(String source)
    • getColor

      public Color getColor(String keyName, Color defaultColor)
    • getBoolean

      public boolean getBoolean(String keyName)
    • getInt

      public int getInt(String keyName)
    • getCompanyName

      public String getCompanyName()
    • getGatewayName

      public String getGatewayName()
    • getClientName

      public String getClientName()
    • getDesignerName

      public String getDesignerName()
    • getPlatformName

      public String getPlatformName()
    • getVersion

      public Version getVersion(String prefix)
      Shortcut for creating a Version from property resources. Given the prefix, uses the key PREFIX.version which should be valid according to Version.parse(String)
    • getPlatformVersion

      public Version getPlatformVersion()
    • getPlatformVersionString

      public String getPlatformVersionString()
    • getVersionString

      public String getVersionString(String module)
      Returns the full version string, like "3.1.1 (build 1557)"
    • getVersionStringShort

      public String getVersionStringShort(String module)
      Returns the version string like 1.5.2