public class NbBundle
extends java.lang.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 | Description |
|---|---|---|
static interface |
NbBundle.ClassLoaderFinder |
Deprecated.
Useless.
|
static interface |
NbBundle.Messages |
Creates a helper class with static definitions of bundle keys.
|
| Constructor | Description |
|---|---|
NbBundle() |
Deprecated.
There is no reason to instantiate or subclass this class.
All methods in it are static.
|
| Modifier and Type | Method | Description |
|---|---|---|
static java.lang.String |
getBranding() |
Get the current branding token.
|
static java.util.ResourceBundle |
getBundle(java.lang.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 java.util.ResourceBundle |
getBundle(java.lang.String baseName) |
Get a resource bundle with the default class loader and locale/branding.
|
static java.util.ResourceBundle |
getBundle(java.lang.String baseName,
java.util.Locale locale) |
Get a resource bundle with the default class loader and branding.
|
static java.util.ResourceBundle |
getBundle(java.lang.String baseName,
java.util.Locale locale,
java.lang.ClassLoader loader) |
Get a resource bundle the hard way.
|
static java.net.URL |
getLocalizedFile(java.lang.String baseName,
java.lang.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 java.net.URL |
getLocalizedFile(java.lang.String baseName,
java.lang.String ext,
java.util.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 java.net.URL |
getLocalizedFile(java.lang.String baseName,
java.lang.String ext,
java.util.Locale locale,
java.lang.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 java.lang.String |
getLocalizedValue(java.util.jar.Attributes attr,
java.util.jar.Attributes.Name key) |
Find a localized and/or branded value in a JAR manifest in the default system locale.
|
static java.lang.String |
getLocalizedValue(java.util.jar.Attributes attr,
java.util.jar.Attributes.Name key,
java.util.Locale locale) |
Find a localized and/or branded value in a JAR manifest.
|
static <T> T |
getLocalizedValue(java.util.Map<java.lang.String,T> table,
java.lang.String key) |
Find a localized and/or branded value for a given key in the default system locale.
|
static <T> T |
getLocalizedValue(java.util.Map<java.lang.String,T> table,
java.lang.String key,
java.util.Locale locale) |
Find a localized and/or branded value for a given key and locale.
|
static java.util.Iterator<java.lang.String> |
getLocalizingSuffixes() |
Get a list of all suffixes used to search for localized/branded resources.
|
static java.lang.String |
getMessage(java.lang.Class<?> clazz,
java.lang.String resName) |
Finds a localized and/or branded string in a bundle.
|
static java.lang.String |
getMessage(java.lang.Class<?> clazz,
java.lang.String resName,
java.lang.Object param1) |
Finds a localized and/or branded string in a bundle and formats the message
by passing requested parameters.
|
static java.lang.String |
getMessage(java.lang.Class<?> clazz,
java.lang.String resName,
java.lang.Object[] arr) |
Finds a localized and/or branded string in a bundle and formats the message
by passing requested parameters.
|
static java.lang.String |
getMessage(java.lang.Class<?> clazz,
java.lang.String resName,
java.lang.Object param1,
java.lang.Object param2) |
Finds a localized and/or branded string in a bundle and formats the message
by passing requested parameters.
|
static java.lang.String |
getMessage(java.lang.Class<?> clazz,
java.lang.String resName,
java.lang.Object param1,
java.lang.Object param2,
java.lang.Object param3) |
Finds a localized and/or branded string in a bundle and formats the message
by passing requested parameters.
|
static java.lang.String |
getMessage(java.lang.Class<?> clazz,
java.lang.String resName,
java.lang.Object param1,
java.lang.Object param2,
java.lang.Object param3,
java.lang.Object param4,
java.lang.Object... params) |
Finds a localized and/or branded string in a bundle and formats the message
by passing requested parameters.
|
static void |
setBranding(java.lang.String bt) |
Set the current branding token.
|
static void |
setClassLoaderFinder(NbBundle.ClassLoaderFinder loaderFinder) |
Deprecated.
Useless.
|
@Deprecated public NbBundle()
public static java.lang.String getBranding()
null for nonepublic static void setBranding(java.lang.String bt)
throws java.lang.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 clearjava.lang.IllegalArgumentException - if in an incorrect format@Deprecated
public static java.net.URL getLocalizedFile(java.lang.String baseName,
java.lang.String ext)
throws java.util.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)java.util.MissingResourceException - if not found@Deprecated
public static java.net.URL getLocalizedFile(java.lang.String baseName,
java.lang.String ext,
java.util.Locale locale)
throws java.util.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 filejava.util.MissingResourceException - if not found@Deprecated
public static java.net.URL getLocalizedFile(java.lang.String baseName,
java.lang.String ext,
java.util.Locale locale,
java.lang.ClassLoader loader)
throws java.util.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 usejava.util.MissingResourceException - if not foundpublic static <T> T getLocalizedValue(java.util.Map<java.lang.String,T> table,
java.lang.String key,
java.util.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(java.util.Map<java.lang.String,T> table,
java.lang.String key)
table - mapping from localized strings to objectskey - the key to look fornull if no key matchesgetLocalizedValue(Map,String,Locale)public static java.lang.String getLocalizedValue(java.util.jar.Attributes attr,
java.util.jar.Attributes.Name key,
java.util.Locale locale)
attr - the manifest attributeskey - the key to look for (case-insensitive)locale - the locale to usenullpublic static java.lang.String getLocalizedValue(java.util.jar.Attributes attr,
java.util.jar.Attributes.Name key)
attr - the manifest attributeskey - the key to look for (case-insensitive)nullpublic static java.util.ResourceBundle getBundle(java.lang.String baseName)
throws java.util.MissingResourceException
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 basenamejava.util.MissingResourceException - if the bundle does not existpublic static java.util.ResourceBundle getBundle(java.lang.Class<?> clazz)
throws java.util.MissingResourceException
getMessage(Class,String)
or one of the other overloads taking message formats.clazz - the class to take the package name fromjava.util.MissingResourceException - if the bundle does not existpublic static java.util.ResourceBundle getBundle(java.lang.String baseName,
java.util.Locale locale)
throws java.util.MissingResourceException
baseName - bundle basenamelocale - the locale to use (but still uses default branding)java.util.MissingResourceException - if the bundle does not existpublic static java.util.ResourceBundle getBundle(java.lang.String baseName,
java.util.Locale locale,
java.lang.ClassLoader loader)
throws java.util.MissingResourceException
baseName - bundle basenamelocale - the locale to use (but still uses default branding)loader - the class loader to usejava.util.MissingResourceException - if the bundle does not existpublic static java.lang.String getMessage(java.lang.Class<?> clazz,
java.lang.String resName)
throws java.util.MissingResourceException
clazz - the class to use to locate the bundle (see getBundle(Class) for details)resName - name of the resource to look forjava.util.MissingResourceException - if either the bundle or the string cannot be foundpublic static java.lang.String getMessage(java.lang.Class<?> clazz,
java.lang.String resName,
java.lang.Object param1)
throws java.util.MissingResourceException
clazz - the class to use to locate the bundle (see getBundle(Class) for details)resName - name of the resource to look forparam1 - the argument to use when formatting the messagejava.util.MissingResourceException - if either the bundle or the string cannot be foundMessageFormat.format(String,Object[])public static java.lang.String getMessage(java.lang.Class<?> clazz,
java.lang.String resName,
java.lang.Object param1,
java.lang.Object param2)
throws java.util.MissingResourceException
clazz - the class to use to locate the bundle (see 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 formattingjava.util.MissingResourceException - if either the bundle or the string cannot be foundMessageFormat.format(String,Object[])public static java.lang.String getMessage(java.lang.Class<?> clazz,
java.lang.String resName,
java.lang.Object param1,
java.lang.Object param2,
java.lang.Object param3)
throws java.util.MissingResourceException
clazz - the class to use to locate the bundle (see 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 formattingjava.util.MissingResourceException - if either the bundle or the string cannot be foundMessageFormat.format(String,Object[])public static java.lang.String getMessage(java.lang.Class<?> clazz,
java.lang.String resName,
java.lang.Object param1,
java.lang.Object param2,
java.lang.Object param3,
java.lang.Object param4,
java.lang.Object... params)
throws java.util.MissingResourceException
clazz - the class to use to locate the bundle (see 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 neededjava.util.MissingResourceException - if either the bundle or the string cannot be foundMessageFormat.format(String,Object[])public static java.lang.String getMessage(java.lang.Class<?> clazz,
java.lang.String resName,
java.lang.Object[] arr)
throws java.util.MissingResourceException
clazz - the class to use to locate the bundle (see getBundle(Class) for details)resName - name of the resource to look forarr - array of parameters to use for formatting the messagejava.util.MissingResourceException - if either the bundle or the string cannot be foundMessageFormat.format(String,Object[])public static java.util.Iterator<java.lang.String> getLocalizingSuffixes()
NbBundle methods use as the search order.
For example, when 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 - ignoredBuilt on April 24 2018. | Portions Copyright 1997-2018 Oracle. All rights reserved.