Class BundleUtil
java.lang.Object
com.inductiveautomation.ignition.common.BundleUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
BundleUtil.BundleGroupClassLoader
exists so that getResource*() calls can be intercepted and directed togetLangPackLoader()
and the wrappedClassLoader
before going to the systemClassLoader
if necessary.protected class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ClassLoader
protected com.inductiveautomation.ignition.common.BundleUtil.BundleGroup
protected ClassLoader
protected org.apache.log4j.Logger
protected List<com.inductiveautomation.ignition.common.BundleUtil.ReplaceToken>
protected ConcurrentMap<String,
com.inductiveautomation.ignition.common.BundleUtil.BundleGroup> -
Method Summary
Modifier and TypeMethodDescriptionvoid
Shortcut for adding a resource bundle for a specific class whose prefix is the simple classname.void
Adds a bundle that is located next to a class with a custom prefix.void
addBundle
(String prefix, ClassLoader owner, String bundleName) Adds a new prefixed sub-bundle with the given classloader.void
addCommonBundle
(String bundleName) Adds a new bundle to the common (non-prefixed) bundle.void
addExternalLookupLocations
(List<URL> locations) Registers locations that will be consulted for translation packs.void
addReplacement
(String key, String value) Adds a new key, value pair that will be used as a replacement token for all bundle strings.void
addSupportedLocales
(Collection<Locale> locales) protected String
applyReplacements
(String source) static BundleUtil
get()
boolean
getBoolean
(String keyName) getDefinedString
(Locale locale, String keyName) Returns the raw translated text, after replacements have been made, but without applying any formatting values.int
char
getMnemonic
(String keyName, char fallBack) Returns a single char that defines a keyboard shortcut, defined in an externalized file.protected String
getRawString
(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 String
Static shorthand forBundleUtil.get().getStringLenient(key, args)
static String
boolean
isKeyPresent
(String keyName) static boolean
Tests to see if this is a white-labeled build of Ignitionprotected void
void
registerBaseClassLoader
(ClassLoader loader) void
removeBundle
(Class<?> clazz) Equiv to removeBundle(clazz.getSimpleName(), clazz.getName().replace('.', '/'));void
removeBundle
(String prefix) Removes all bundles added under the given prefixvoid
removeBundle
(String prefix, String bundleName) Removes all the specific bundle that was added under the given prefix and the given bundle name.boolean
removeReplacement
(String key) Removes the replacement with this key.protected void
updateLanguagePackLoader
(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:
true
if 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.properties
and 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.version
which 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
-