Class ResourceBundleSupport
java.lang.Object
org.pentaho.reporting.libraries.base.util.ResourceBundleSupport
- Direct Known Subclasses:
Messages
An utility class to ease up using property-file resource bundles.
The class support references within the resource bundle set to minimize the occurence of duplicate keys. References
are given in the format:
a.key.name=@referenced.keyA lookup to a key in an other resource bundle should be written by
a.key.name=@@resourcebundle_name@referenced.key
- Author:
- Thomas Morgner
-
Constructor Summary
ConstructorDescriptionResourceBundleSupport
(Locale locale, String baseName, ClassLoader classLoader) Creates a new instance.ResourceBundleSupport
(Locale locale, ResourceBundle resourceBundle, ClassLoader classLoader) Creates a new instance.ResourceBundleSupport
(Locale locale, ResourceBundle resourceBundle, String baseName, ClassLoader classLoader) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptioncreateMenu
(String keyPrefix) Returns a JMenu created from a resource bundle definition.formatMessage
(String key, Object parameter) Formats the message stored in the resource bundle (using a MessageFormat).formatMessage
(String key, Object[] parameters) Formats the message stored in the resource bundle (using a MessageFormat).formatMessage
(String key, Object par1, Object par2) Formats the message stored in the resource bundle (using a MessageFormat).Returns an unscaled icon.Returns an scaled icon suitable for buttons or menus.getKeyStroke
(String key) Returns the keystroke stored at the given resourcebundle key.getKeyStroke
(String key, int mask) Returns the keystroke stored at the given resourcebundle key.Returns the current locale for this resource bundle.getMnemonic
(String key) Returns the mnemonic stored at the given resourcebundle key.Returns the keystroke stored at the given resourcebundle key.getOptionalKeyStroke
(String key, int mask) Returns the keystroke stored at the given resourcebundle key.Returns the mnemonic stored at the given resourcebundle key.getOptionalString
(String key) protected final String
The base name of the resource bundle.getResourceURL
(String key) Returns a URL pointing to a resource located in the classpath.protected String
internalGetString
(String key) Performs the lookup for the given key.strictString
(String key) Gets a string for the given key from this resource bundle or one of its parents.
-
Constructor Details
-
ResourceBundleSupport
Creates a new instance.- Parameters:
locale
- the locale that should be used to load the resource-bundle.baseName
- the base name of the resource bundle, a fully qualified class nameclassLoader
- the class-loader from where to load resources.
-
ResourceBundleSupport
public ResourceBundleSupport(Locale locale, ResourceBundle resourceBundle, String baseName, ClassLoader classLoader) Creates a new instance.- Parameters:
locale
- the locale for which this resource bundle is created.resourceBundle
- the resourcebundlebaseName
- the base name of the resource bundle, a fully qualified class nameclassLoader
- the class-loader from where to load resources.
-
ResourceBundleSupport
Creates a new instance.- Parameters:
locale
- the locale for which the resource bundle is created.resourceBundle
- the resourcebundleclassLoader
- the class-loader from where to load resources.
-
-
Method Details
-
getResourceBase
The base name of the resource bundle.- Returns:
- the resource bundle's name.
-
strictString
Gets a string for the given key from this resource bundle or one of its parents. If the key is a link, the link is resolved and the referenced string is returned instead.- Parameters:
key
- the key for the desired string- Returns:
- the string for the given key
- Throws:
NullPointerException
- ifkey
isnull
MissingResourceException
- if no object for the given key can be foundClassCastException
- if the object found for the given key is not a string
-
internalGetString
Performs the lookup for the given key. If the key points to a link the link is resolved and that key is looked up instead.- Parameters:
key
- the key for the string- Returns:
- the string for the given key
-
getIcon
Returns an scaled icon suitable for buttons or menus.- Parameters:
key
- the name of the resource bundle keylarge
- true, if the image should be scaled to 24x24, or false for 16x16- Returns:
- the icon.
-
getIcon
Returns an unscaled icon.- Parameters:
key
- the name of the resource bundle key- Returns:
- the icon.
-
getMnemonic
Returns the mnemonic stored at the given resourcebundle key. The mnemonic should be either the symbolic name of one of the KeyEvent.VK_* constants (without the 'VK_') or the character for that key. For the enter key, the resource bundle would therefore either contain "ENTER" or "\n".a.resourcebundle.key=ENTER an.other.resourcebundle.key=\n
- Parameters:
key
- the resourcebundle key- Returns:
- the mnemonic
-
getOptionalMnemonic
Returns the mnemonic stored at the given resourcebundle key. The mnemonic should be either the symbolic name of one of the KeyEvent.VK_* constants (without the 'VK_') or the character for that key. For the enter key, the resource bundle would therefore either contain "ENTER" or "\n".a.resourcebundle.key=ENTER an.other.resourcebundle.key=\n
- Parameters:
key
- the resourcebundle key- Returns:
- the mnemonic or null, if the mnemonic is not defined.
-
getKeyStroke
Returns the keystroke stored at the given resourcebundle key. The keystroke will be composed of a simple key press and the plattform's MenuKeyMask. The keystrokes character key should be either the symbolic name of one of the KeyEvent.VK_* constants or the character for that key. For the 'A' key, the resource bundle would therefore either contain "VK_A" or "a".a.resourcebundle.key=VK_A an.other.resourcebundle.key=a
- Parameters:
key
- the resourcebundle key- Returns:
- the keystroke
- See Also:
-
getOptionalKeyStroke
Returns the keystroke stored at the given resourcebundle key. The keystroke will be composed of a simple key press and a keystroke mask pattern. The pattern should be specified via the words "shift", "alt", "ctrl", "meta" or "menu". Menu should be used to reference the platform specific menu shortcut. For the sake of safety, menu should only be combined with "shift" and/or "alt" for menu keystrokes. The keystrokes character key should be either the symbolic name of one of the KeyEvent.VK_* constants or the character for that key. For the 'A' key, the resource bundle would therefore either contain "VK_A" or "a".a.resourcebundle.key=VK_A an.other.resourcebundle.key=a
- Parameters:
key
- the resourcebundle key- Returns:
- the keystroke
- See Also:
-
getKeyStroke
Returns the keystroke stored at the given resourcebundle key. The keystroke will be composed of a simple key press and the given KeyMask. If the KeyMask is zero, a plain Keystroke is returned. The keystrokes character key should be either the symbolic name of one of the KeyEvent.VK_* constants or the character for that key. For the 'A' key, the resource bundle would therefore either contain "VK_A" or "a".a.resourcebundle.key=VK_A an.other.resourcebundle.key=a
- Parameters:
key
- the resourcebundle keymask
- the key-moifier mask to be used to create the keystroke.- Returns:
- the keystroke that has been generated.
- See Also:
-
getOptionalKeyStroke
Returns the keystroke stored at the given resourcebundle key. The keystroke will be composed of a simple key press and the given KeyMask. If the KeyMask is zero, a plain Keystroke is returned. The keystrokes character key should be either the symbolic name of one of the KeyEvent.VK_* constants or the character for that key. For the 'A' key, the resource bundle would therefore either contain "VK_A" or "a".a.resourcebundle.key=VK_A an.other.resourcebundle.key=a
- Parameters:
key
- the resourcebundle keymask
- the key-moifier mask to be used to create the keystroke.- Returns:
- the keystroke or null if the key is not defined.
- See Also:
-
createMenu
Returns a JMenu created from a resource bundle definition. The menu definition consists of two keys, the name of the menu and the mnemonic for that menu. Both keys share a common prefix, which is extended by ".name" for the name of the menu and ".mnemonic" for the mnemonic.# define the file menu menu.file.name=File menu.file.mnemonic=F
The menu definition above can be used to create the menu by callingcreateMenu ("menu.file")
.- Parameters:
keyPrefix
- the common prefix for that menu- Returns:
- the created menu
-
getResourceURL
Returns a URL pointing to a resource located in the classpath. The resource is looked up using the given key. Example: The load a file named 'logo.gif' which is stored in a java package named 'org.jfree.resources':mainmenu.logo=org/jfree/resources/logo.gif
The URL for that file can be queried with:getResource("mainmenu.logo");
.- Parameters:
key
- the key for the resource- Returns:
- the resource URL
-
formatMessage
Formats the message stored in the resource bundle (using a MessageFormat).- Parameters:
key
- the resourcebundle keyparameter
- the parameter for the message- Returns:
- the formated string
-
formatMessage
Formats the message stored in the resource bundle (using a MessageFormat).- Parameters:
key
- the resourcebundle keypar1
- the first parameter for the messagepar2
- the second parameter for the message- Returns:
- the formated string
-
formatMessage
Formats the message stored in the resource bundle (using a MessageFormat).- Parameters:
key
- the resourcebundle keyparameters
- the parameter collection for the message- Returns:
- the formated string
-
getString
-
getString
-
getOptionalString
-
getString
-
getString
-
getLocale
Returns the current locale for this resource bundle.- Returns:
- the locale.
-