public class NbBundle extends Object
ResourceBundle
to handle branding, and interacts
better with class loaders in a module system.
Example usage:
package com.mycom;
public class Foo {
public String getDisplayName() {
return NbBundle.getMessage
(Foo.class, "Foo.displayName");
}
}
will in German locale look for the key Foo.displayName
in
com/mycom/Bundle_de.properties
and then com/mycom/Bundle.properties
(in that order).
Usually however it is easiest to use NbBundle.Messages
.Modifier and Type | Class and Description |
---|---|
static interface |
NbBundle.ClassLoaderFinder
Deprecated.
Useless.
|
static interface |
NbBundle.Messages
Creates a helper class with static definitions of bundle keys.
|
Constructor and Description |
---|
NbBundle()
Deprecated.
There is no reason to instantiate or subclass this class.
All methods in it are static.
|
Modifier and Type | Method and Description |
---|---|
static String |
getBranding()
Get the current branding token.
|
static ResourceBundle |
getBundle(Class<?> clazz)
Get a resource bundle in the same package as the provided class,
with the default locale/branding and the class' own classloader.
|
static ResourceBundle |
getBundle(String baseName)
Get a resource bundle with the default class loader and locale/branding.
|
static ResourceBundle |
getBundle(String baseName,
Locale locale)
Get a resource bundle with the default class loader and branding.
|
static ResourceBundle |
getBundle(String baseName,
Locale locale,
ClassLoader loader)
Get a resource bundle the hard way.
|
static URL |
getLocalizedFile(String baseName,
String ext)
Deprecated.
Use the
nbresloc URL protocol instead. This method does a poor
job of handling resources such as /some.dir/res.txt or
/some/res.txt.sample. |
static URL |
getLocalizedFile(String baseName,
String ext,
Locale locale)
Deprecated.
Use the
nbresloc URL protocol instead. This method does a poor
job of handling resources such as /some.dir/res.txt or
/some/res.txt.sample. |
static URL |
getLocalizedFile(String baseName,
String ext,
Locale locale,
ClassLoader loader)
Deprecated.
Use the
nbresloc URL protocol instead. This method does a poor
job of handling resources such as /some.dir/res.txt or
/some/res.txt.sample. |
static String |
getLocalizedValue(Attributes attr,
Attributes.Name key)
Find a localized and/or branded value in a JAR manifest in the default system locale.
|
static String |
getLocalizedValue(Attributes attr,
Attributes.Name key,
Locale locale)
Find a localized and/or branded value in a JAR manifest.
|
static <T> T |
getLocalizedValue(Map<String,T> table,
String key)
Find a localized and/or branded value for a given key in the default system locale.
|
static <T> T |
getLocalizedValue(Map<String,T> table,
String key,
Locale locale)
Find a localized and/or branded value for a given key and locale.
|
static Iterator<String> |
getLocalizingSuffixes()
Get a list of all suffixes used to search for localized/branded resources.
|
static String |
getMessage(Class<?> clazz,
String resName)
Finds a localized and/or branded string in a bundle.
|
static String |
getMessage(Class<?> clazz,
String resName,
Object param1)
Finds a localized and/or branded string in a bundle and formats the message
by passing requested parameters.
|
static String |
getMessage(Class<?> clazz,
String resName,
Object[] arr)
Finds a localized and/or branded string in a bundle and formats the message
by passing requested parameters.
|
static String |
getMessage(Class<?> clazz,
String resName,
Object param1,
Object param2)
Finds a localized and/or branded string in a bundle and formats the message
by passing requested parameters.
|
static String |
getMessage(Class<?> clazz,
String resName,
Object param1,
Object param2,
Object param3)
Finds a localized and/or branded string in a bundle and formats the message
by passing requested parameters.
|
static String |
getMessage(Class<?> clazz,
String resName,
Object param1,
Object param2,
Object param3,
Object param4,
Object... params)
Finds a localized and/or branded string in a bundle and formats the message
by passing requested parameters.
|
static void |
setBranding(String bt)
Set the current branding token.
|
static void |
setClassLoaderFinder(NbBundle.ClassLoaderFinder loaderFinder)
Deprecated.
Useless.
|
@Deprecated public NbBundle()
public static String getBranding()
null
for nonepublic static void setBranding(String bt) throws IllegalArgumentException
[a-z][a-z0-9]*(_[a-z][a-z0-9]*)*
This is normally only called by NetBeans startup code and unit tests.
Currently the branding may be specified by passing the --branding
command-line option to the launcher.
bt
- the new branding, or null
to clearIllegalArgumentException
- if in an incorrect format@Deprecated public static URL getLocalizedFile(String baseName, String ext) throws MissingResourceException
nbresloc
URL protocol instead. This method does a poor
job of handling resources such as /some.dir/res.txt or
/some/res.txt.sample.Note that use of this call is similar to using the URL protocol nbresloc
(which may in fact be implemented using the fuller form of the method).
The extension may be null, in which case no final dot will be appended. If it is the empty string, the resource will end in a dot.
baseName
- base name of file, as dot-separated path (e.g. some.dir.File
)ext
- extension of file (or null
)MissingResourceException
- if not found@Deprecated public static URL getLocalizedFile(String baseName, String ext, Locale locale) throws MissingResourceException
nbresloc
URL protocol instead. This method does a poor
job of handling resources such as /some.dir/res.txt or
/some/res.txt.sample.baseName
- base name of file, as dot-separated path (e.g. some.dir.File
)ext
- extension of file (or null
)locale
- locale of fileMissingResourceException
- if not found@Deprecated public static URL getLocalizedFile(String baseName, String ext, Locale locale, ClassLoader loader) throws MissingResourceException
nbresloc
URL protocol instead. This method does a poor
job of handling resources such as /some.dir/res.txt or
/some/res.txt.sample.baseName
- base name of file, as dot-separated path (e.g. some.dir.File
)ext
- extension of file (or null
)locale
- locale of fileloader
- class loader to useMissingResourceException
- if not foundpublic static <T> T getLocalizedValue(Map<String,T> table, String key, Locale locale)
findLocalizedValue (hashTable, "keyName", new Locale ("cs_CZ"))
This would return the first non-null
value obtained from the following tests:
hashTable.get ("keyName_cs_CZ")
hashTable.get ("keyName_cs")
hashTable.get ("keyName")
table
- mapping from localized strings to objectskey
- the key to look forlocale
- the locale to usenull
if no key matchespublic static <T> T getLocalizedValue(Map<String,T> table, String key)
table
- mapping from localized strings to objectskey
- the key to look fornull
if no key matchesNbBundle.getLocalizedValue(Map,String,Locale)
public static String getLocalizedValue(Attributes attr, Attributes.Name key, Locale locale)
attr
- the manifest attributeskey
- the key to look for (case-insensitive)locale
- the locale to usenull
public static String getLocalizedValue(Attributes attr, Attributes.Name key)
attr
- the manifest attributeskey
- the key to look for (case-insensitive)null
public static ResourceBundle getBundle(String baseName) throws MissingResourceException
NbBundle.getBundle(Class)
is generally
safer when used from a module as this method relies on the module's
classloader to currently be part of the system classloader. NetBeans
does add enabled modules to this classloader, however calls to
this variant of the method made in ModuleInstall.validate,
or made soon after a module is uninstalled (due to background threads)
could fail unexpectedly.baseName
- bundle basenameMissingResourceException
- if the bundle does not existpublic static ResourceBundle getBundle(Class<?> clazz) throws MissingResourceException
NbBundle.getMessage(Class,String)
or one of the other overloads taking message formats.clazz
- the class to take the package name fromMissingResourceException
- if the bundle does not existpublic static ResourceBundle getBundle(String baseName, Locale locale) throws MissingResourceException
baseName
- bundle basenamelocale
- the locale to use (but still uses default branding
)MissingResourceException
- if the bundle does not existpublic static ResourceBundle getBundle(String baseName, Locale locale, ClassLoader loader) throws MissingResourceException
baseName
- bundle basenamelocale
- the locale to use (but still uses default branding
)loader
- the class loader to useMissingResourceException
- if the bundle does not existpublic static String getMessage(Class<?> clazz, String resName) throws MissingResourceException
clazz
- the class to use to locate the bundle (see NbBundle.getBundle(Class)
for details)resName
- name of the resource to look forMissingResourceException
- if either the bundle or the string cannot be foundpublic static String getMessage(Class<?> clazz, String resName, Object param1) throws MissingResourceException
clazz
- the class to use to locate the bundle (see NbBundle.getBundle(Class)
for details)resName
- name of the resource to look forparam1
- the argument to use when formatting the messageMissingResourceException
- if either the bundle or the string cannot be foundMessageFormat.format(String,Object[])
public static String getMessage(Class<?> clazz, String resName, Object param1, Object param2) throws MissingResourceException
clazz
- the class to use to locate the bundle (see NbBundle.getBundle(Class)
for details)resName
- name of the resource to look forparam1
- the argument to use when formatting the messageparam2
- the second argument to use for formattingMissingResourceException
- if either the bundle or the string cannot be foundMessageFormat.format(String,Object[])
public static String getMessage(Class<?> clazz, String resName, Object param1, Object param2, Object param3) throws MissingResourceException
clazz
- the class to use to locate the bundle (see NbBundle.getBundle(Class)
for details)resName
- name of the resource to look forparam1
- the argument to use when formatting the messageparam2
- the second argument to use for formattingparam3
- the third argument to use for formattingMissingResourceException
- if either the bundle or the string cannot be foundMessageFormat.format(String,Object[])
public static String getMessage(Class<?> clazz, String resName, Object param1, Object param2, Object param3, Object param4, Object... params) throws MissingResourceException
clazz
- the class to use to locate the bundle (see NbBundle.getBundle(Class)
for details)resName
- name of the resource to look forparam1
- the argument to use when formatting the messageparam2
- the second argument to use for formattingparam3
- the third argument to use for formattingparam4
- the fourth argument to use for formattingparams
- fifth, sixth, ... arguments as neededMissingResourceException
- if either the bundle or the string cannot be foundMessageFormat.format(String,Object[])
public static String getMessage(Class<?> clazz, String resName, Object[] arr) throws MissingResourceException
clazz
- the class to use to locate the bundle (see NbBundle.getBundle(Class)
for details)resName
- name of the resource to look forarr
- array of parameters to use for formatting the messageMissingResourceException
- if either the bundle or the string cannot be foundMessageFormat.format(String,Object[])
public static Iterator<String> getLocalizingSuffixes()
NbBundle
methods use as the search order.
For example, when NbBundle.getBranding()
returns branding
and the default locale is German, you might get a sequence such as:
String
@Deprecated public static void setClassLoaderFinder(NbBundle.ClassLoaderFinder loaderFinder)
loaderFinder
- ignored