Class BundleUtil
- java.lang.Object
-
- com.inductiveautomation.ignition.common.BundleUtil
-
public class BundleUtil extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classBundleUtil.BundleGroupClassLoaderBundleUtil.BundleGroupClassLoaderexists so that getResource*() calls can be intercepted and directed togetLangPackLoader()and the wrappedClassLoaderbefore going to the systemClassLoaderif necessary.protected classBundleUtil.KeyTracker
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ClassLoaderbaseLoaderprotected com.inductiveautomation.ignition.common.BundleUtil.BundleGroupcommonGroupprotected java.lang.ClassLoaderlangPackLoaderprotected org.apache.log4j.Loggerlogprotected java.util.List<com.inductiveautomation.ignition.common.BundleUtil.ReplaceToken>replacementsprotected java.util.concurrent.ConcurrentMap<java.lang.String,com.inductiveautomation.ignition.common.BundleUtil.BundleGroup>subGroupsprotected java.util.Map<java.lang.String,Version>versionCache
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBundle(java.lang.Class<?> clazz)Shortcut for adding a resource bundle for a specific class whose prefix is the simple classname.voidaddBundle(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.voidaddBundle(java.lang.String prefix, java.lang.ClassLoader owner, java.lang.String bundleName)Adds a new prefixed sub-bundle with the given classloader.voidaddCommonBundle(java.lang.String bundleName)Adds a new bundle to the common (non-prefixed) bundle.voidaddExternalLookupLocations(java.util.List<java.net.URL> locations)Registers locations that will be consulted for translation packs.voidaddReplacement(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.voidaddSupportedLocales(java.util.Collection<java.util.Locale> locales)protected java.lang.StringapplyReplacements(java.lang.String source)static BundleUtilget()booleangetBoolean(java.lang.String keyName)java.lang.StringgetClientName()java.awt.ColorgetColor(java.lang.String keyName, java.awt.Color defaultColor)java.lang.StringgetCompanyName()java.lang.StringgetDefinedString(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.StringgetDesignerName()java.lang.StringgetGatewayName()intgetInt(java.lang.String keyName)java.lang.ClassLoadergetLangPackLoader()chargetMnemonic(java.lang.String keyName, char fallBack)Returns a single char that defines a keyboard shortcut, defined in an externalized file.java.lang.StringgetPlatformName()VersiongetPlatformVersion()java.lang.StringgetPlatformVersionString()protected java.lang.StringgetRawString(java.util.Locale locale, java.lang.String key)Looks up the raw key from the local resource bundles.java.lang.StringgetString(java.lang.String keyName)Looks up the resource string associated with the given keyname.java.lang.StringgetString(java.lang.String keyName, java.lang.Object... formatArgs)java.lang.StringgetString(java.util.Locale locale, java.lang.String keyName)java.lang.StringgetString(java.util.Locale locale, java.lang.String keyName, java.lang.Object... formatArgs)java.lang.StringgetStringLenient(java.lang.String keyName)Returns the resource string associated with the given keyname, if any.java.lang.StringgetStringLenient(java.lang.String keyName, java.lang.Object... formatArgs)java.lang.StringgetStringLenient(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.VersiongetVersion(java.lang.String prefix)Shortcut for creating a Version from property resources.java.lang.StringgetVersionString(java.lang.String module)Returns the full version string, like "3.1.1 (build 1557)"java.lang.StringgetVersionStringShort(java.lang.String module)Returns the version string like 1.5.2static java.lang.Stringi18n(java.lang.String key, java.lang.Object... args)Static shorthand forBundleUtil.get().getStringLenient(key, args)static java.lang.Stringi18n(java.util.Locale locale, java.lang.String key, java.lang.Object... args)booleanisKeyPresent(java.lang.String keyName)static booleanisWhiteLabeled()Tests to see if this is a white-labeled build of Ignitionprotected voidrefreshClassLoaders()voidregisterBaseClassLoader(java.lang.ClassLoader loader)voidremoveBundle(java.lang.Class<?> clazz)Equiv to removeBundle(clazz.getSimpleName(), clazz.getName().replace('.', '/'));voidremoveBundle(java.lang.String prefix)Removes all bundles added under the given prefixvoidremoveBundle(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.booleanremoveReplacement(java.lang.String key)Removes the replacement with this key.protected voidupdateLanguagePackLoader(java.lang.ClassLoader loader)
-
-
-
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
-
get
public static BundleUtil get()
-
i18n
public static java.lang.String i18n(java.lang.String key, java.lang.Object... args)Static shorthand forBundleUtil.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:
trueif 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 atcom/example/MyClass.propertiesand 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 hadcom.example.MyClass, and a resource file such ascom/example/strings.properties, a call such asaddBundle("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 keyPREFIX.versionwhich should be valid according toVersion.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
-
-