Class BundleUtil


  • public class BundleUtil
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.ClassLoader baseLoader  
      protected com.inductiveautomation.ignition.common.BundleUtil.BundleGroup commonGroup  
      protected java.lang.ClassLoader langPackLoader  
      protected org.apache.log4j.Logger log  
      protected java.util.List<com.inductiveautomation.ignition.common.BundleUtil.ReplaceToken> replacements  
      protected java.util.concurrent.ConcurrentMap<java.lang.String,​com.inductiveautomation.ignition.common.BundleUtil.BundleGroup> subGroups  
      protected java.util.Map<java.lang.String,​Version> versionCache  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addBundle​(java.lang.Class<?> clazz)
      Shortcut for adding a resource bundle for a specific class whose prefix is the simple classname.
      void addBundle​(java.lang.String prefix, java.lang.Class<?> clazz, java.lang.String bundleName)
      Adds a bundle that is located next to a class with a custom prefix.
      void addBundle​(java.lang.String prefix, java.lang.ClassLoader owner, java.lang.String bundleName)
      Adds a new prefixed sub-bundle with the given classloader.
      void addCommonBundle​(java.lang.String bundleName)
      Adds a new bundle to the common (non-prefixed) bundle.
      void addExternalLookupLocations​(java.util.List<java.net.URL> locations)
      Registers locations that will be consulted for translation packs.
      void addReplacement​(java.lang.String key, java.lang.String value)
      Adds a new key, value pair that will be used as a replacement token for all bundle strings.
      void addSupportedLocales​(java.util.Collection<java.util.Locale> locales)  
      protected java.lang.String applyReplacements​(java.lang.String source)  
      static BundleUtil get()  
      boolean getBoolean​(java.lang.String keyName)  
      java.lang.String getClientName()  
      java.awt.Color getColor​(java.lang.String keyName, java.awt.Color defaultColor)  
      java.lang.String getCompanyName()  
      java.lang.String getDefinedString​(java.util.Locale locale, java.lang.String keyName)
      Returns the raw translated text, after replacements have been made, but without applying any formatting values.
      java.lang.String getDesignerName()  
      java.lang.String getGatewayName()  
      int getInt​(java.lang.String keyName)  
      java.lang.ClassLoader getLangPackLoader()  
      char getMnemonic​(java.lang.String keyName, char fallBack)
      Returns a single char that defines a keyboard shortcut, defined in an externalized file.
      java.lang.String getPlatformName()  
      Version getPlatformVersion()  
      java.lang.String getPlatformVersionString()  
      protected java.lang.String getRawString​(java.util.Locale locale, java.lang.String key)
      Looks up the raw key from the local resource bundles.
      java.lang.String getString​(java.lang.String keyName)
      Looks up the resource string associated with the given keyname.
      java.lang.String getString​(java.lang.String keyName, java.lang.Object... formatArgs)  
      java.lang.String getString​(java.util.Locale locale, java.lang.String keyName)  
      java.lang.String getString​(java.util.Locale locale, java.lang.String keyName, java.lang.Object... formatArgs)  
      java.lang.String getStringLenient​(java.lang.String keyName)
      Returns the resource string associated with the given keyname, if any.
      java.lang.String getStringLenient​(java.lang.String keyName, java.lang.Object... formatArgs)  
      java.lang.String getStringLenient​(java.util.Locale locale, java.lang.String keyName, java.lang.Object... formatArgs)  
      java.util.List<java.util.Locale> getSupportedLocales()
      Provides a list of the locales that are currently supported/selectable.
      Version getVersion​(java.lang.String prefix)
      Shortcut for creating a Version from property resources.
      java.lang.String getVersionString​(java.lang.String module)
      Returns the full version string, like "3.1.1 (build 1557)"
      java.lang.String getVersionStringShort​(java.lang.String module)
      Returns the version string like 1.5.2
      static java.lang.String i18n​(java.lang.String key, java.lang.Object... args)
      Static shorthand for BundleUtil.get().getStringLenient(key, args)
      static java.lang.String i18n​(java.util.Locale locale, java.lang.String key, java.lang.Object... args)  
      boolean isKeyPresent​(java.lang.String keyName)  
      static boolean isWhiteLabeled()
      Tests to see if this is a white-labeled build of Ignition
      protected void refreshClassLoaders()  
      void registerBaseClassLoader​(java.lang.ClassLoader loader)  
      void removeBundle​(java.lang.Class<?> clazz)
      Equiv to removeBundle(clazz.getSimpleName(), clazz.getName().replace('.', '/'));
      void removeBundle​(java.lang.String prefix)
      Removes all bundles added under the given prefix
      void removeBundle​(java.lang.String prefix, java.lang.String bundleName)
      Removes all the specific bundle that was added under the given prefix and the given bundle name.
      boolean removeReplacement​(java.lang.String key)
      Removes the replacement with this key.
      protected void updateLanguagePackLoader​(java.lang.ClassLoader loader)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • baseLoader

        protected java.lang.ClassLoader baseLoader
      • langPackLoader

        protected java.lang.ClassLoader langPackLoader
      • commonGroup

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

        protected java.util.concurrent.ConcurrentMap<java.lang.String,​com.inductiveautomation.ignition.common.BundleUtil.BundleGroup> subGroups
      • replacements

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

        protected java.util.Map<java.lang.String,​Version> versionCache
      • log

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

      • i18n

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

        public static java.lang.String i18n​(java.util.Locale locale,
                                            java.lang.String key,
                                            java.lang.Object... args)
      • isWhiteLabeled

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

        public void addExternalLookupLocations​(java.util.List<java.net.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​(java.lang.ClassLoader loader)
      • registerBaseClassLoader

        public void registerBaseClassLoader​(java.lang.ClassLoader loader)
      • getSupportedLocales

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

        public void addSupportedLocales​(java.util.Collection<java.util.Locale> locales)
      • getLangPackLoader

        public java.lang.ClassLoader getLangPackLoader()
      • addReplacement

        public void addReplacement​(java.lang.String key,
                                   java.lang.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​(java.lang.String key)
        Removes the replacement with this key.
        Returns:
        true if the key was found.
      • addBundle

        public void addBundle​(java.lang.String prefix,
                              java.lang.ClassLoader owner,
                              java.lang.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​(java.lang.Class<?> clazz)
        Equiv to removeBundle(clazz.getSimpleName(), clazz.getName().replace('.', '/'));
      • removeBundle

        public void removeBundle​(java.lang.String prefix)
        Removes all bundles added under the given prefix
      • removeBundle

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

        public void addBundle​(java.lang.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​(java.lang.String prefix,
                              java.lang.Class<?> clazz,
                              java.lang.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​(java.lang.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​(java.lang.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 java.lang.String getStringLenient​(java.lang.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 java.lang.String getStringLenient​(java.lang.String keyName,
                                                 java.lang.Object... formatArgs)
      • getStringLenient

        public java.lang.String getStringLenient​(java.util.Locale locale,
                                                 java.lang.String keyName,
                                                 java.lang.Object... formatArgs)
      • getString

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

        public java.lang.String getString​(java.lang.String keyName,
                                          java.lang.Object... formatArgs)
      • getString

        public java.lang.String getString​(java.util.Locale locale,
                                          java.lang.String keyName)
      • getString

        public java.lang.String getString​(java.util.Locale locale,
                                          java.lang.String keyName,
                                          java.lang.Object... formatArgs)
      • getDefinedString

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

        public boolean isKeyPresent​(java.lang.String keyName)
      • getRawString

        protected java.lang.String getRawString​(java.util.Locale locale,
                                                java.lang.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 java.lang.String applyReplacements​(java.lang.String source)
      • getColor

        public java.awt.Color getColor​(java.lang.String keyName,
                                       java.awt.Color defaultColor)
      • getBoolean

        public boolean getBoolean​(java.lang.String keyName)
      • getInt

        public int getInt​(java.lang.String keyName)
      • getCompanyName

        public java.lang.String getCompanyName()
      • getGatewayName

        public java.lang.String getGatewayName()
      • getClientName

        public java.lang.String getClientName()
      • getDesignerName

        public java.lang.String getDesignerName()
      • getPlatformName

        public java.lang.String getPlatformName()
      • getVersion

        public Version getVersion​(java.lang.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 java.lang.String getPlatformVersionString()
      • getVersionString

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

        public java.lang.String getVersionStringShort​(java.lang.String module)
        Returns the version string like 1.5.2