Class BundleUtil
java.lang.Object
com.inductiveautomation.ignition.common.BundleUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classBundleUtil.BundleGroupClassLoaderexists so that getResource*() calls can be intercepted and directed togetLangPackLoader()and the wrappedClassLoaderbefore going to the systemClassLoaderif necessary.protected class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ClassLoaderprotected com.inductiveautomation.ignition.common.BundleUtil.BundleGroupprotected ClassLoaderprotected org.apache.log4j.Loggerprotected List<com.inductiveautomation.ignition.common.BundleUtil.ReplaceToken>protected ConcurrentMap<String,com.inductiveautomation.ignition.common.BundleUtil.BundleGroup> -
Method Summary
Modifier and TypeMethodDescriptionvoidShortcut for adding a resource bundle for a specific class whose prefix is the simple classname.voidAdds a bundle that is located next to a class with a custom prefix.voidaddBundle(String prefix, ClassLoader owner, String bundleName) Adds a new prefixed sub-bundle with the given classloader.voidaddCommonBundle(String bundleName) Adds a new bundle to the common (non-prefixed) bundle.voidaddExternalLookupLocations(List<URL> locations) Registers locations that will be consulted for translation packs.voidaddReplacement(String key, String value) Adds a new key, value pair that will be used as a replacement token for all bundle strings.voidaddSupportedLocales(Collection<Locale> locales) protected StringapplyReplacements(String source) static BundleUtilget()booleangetBoolean(String keyName) getDefinedString(Locale locale, String keyName) Returns the raw translated text, after replacements have been made, but without applying any formatting values.intchargetMnemonic(String keyName, char fallBack) Returns a single char that defines a keyboard shortcut, defined in an externalized file.protected StringgetRawString(Locale locale, String key) Looks up the raw key from the local resource bundles.Looks up the resource string associated with the given keyname.getStringLenient(String keyName) Returns the resource string associated with the given keyname, if any.getStringLenient(String keyName, Object... formatArgs) getStringLenient(Locale locale, String keyName, Object... formatArgs) Provides a list of the locales that are currently supported/selectable.getVersion(String prefix) Shortcut for creating a Version from property resources.getVersionString(String module) Returns the full version string, like "3.1.1 (build 1557)"getVersionStringShort(String module) Returns the version string like 1.5.2static StringStatic shorthand forBundleUtil.get().getStringLenient(key, args)static StringbooleanisKeyPresent(String keyName) static booleanTests to see if this is a white-labeled build of Ignitionprotected voidvoidregisterBaseClassLoader(ClassLoader loader) voidremoveBundle(Class<?> clazz) Equiv to removeBundle(clazz.getSimpleName(), clazz.getName().replace('.', '/'));voidremoveBundle(String prefix) Removes all bundles added under the given prefixvoidremoveBundle(String prefix, String bundleName) Removes all the specific bundle that was added under the given prefix and the given bundle name.booleanremoveReplacement(String key) Removes the replacement with this key.protected voidupdateLanguagePackLoader(ClassLoader loader)
-
Field Details
-
baseLoader
-
langPackLoader
-
commonGroup
protected com.inductiveautomation.ignition.common.BundleUtil.BundleGroup commonGroup -
subGroups
protected ConcurrentMap<String,com.inductiveautomation.ignition.common.BundleUtil.BundleGroup> subGroups -
replacements
-
versionCache
-
log
protected org.apache.log4j.Logger log
-
-
Method Details
-
get
-
i18n
Static shorthand forBundleUtil.get().getStringLenient(key, args) -
i18n
-
isWhiteLabeled
public static boolean isWhiteLabeled()Tests to see if this is a white-labeled build of Ignition -
addExternalLookupLocations
Registers locations that will be consulted for translation packs. The URLs must be to jar files or directories. -
refreshClassLoaders
protected void refreshClassLoaders() -
updateLanguagePackLoader
-
registerBaseClassLoader
-
getSupportedLocales
Provides a list of the locales that are currently supported/selectable. -
addSupportedLocales
-
getLangPackLoader
-
addReplacement
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
Removes the replacement with this key.- Returns:
trueif the key was found.
-
addBundle
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
Equiv to removeBundle(clazz.getSimpleName(), clazz.getName().replace('.', '/')); -
removeBundle
Removes all bundles added under the given prefix -
removeBundle
Removes all the specific bundle that was added under the given prefix and the given bundle name. -
addBundle
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
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
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
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
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
-
getStringLenient
-
getString
Looks up the resource string associated with the given keyname. If no resource string is found, null is returned. -
getString
-
getString
-
getString
-
getDefinedString
Returns the raw translated text, after replacements have been made, but without applying any formatting values. -
isKeyPresent
-
getRawString
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
-
getColor
-
getBoolean
-
getInt
-
getCompanyName
-
getGatewayName
-
getClientName
-
getDesignerName
-
getPlatformName
-
getVersion
Shortcut for creating a Version from property resources. Given the prefix, uses the keyPREFIX.versionwhich should be valid according toVersion.parse(String) -
getPlatformVersion
-
getPlatformVersionString
-
getVersionString
Returns the full version string, like "3.1.1 (build 1557)" -
getVersionStringShort
Returns the version string like 1.5.2
-