|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.openide.util.NbBundle
Convenience class permitting easy loading of localized resources of various sorts. Extends the functionality of the default Java resource support, and interacts better with class loaders in a multiple-loader system.
Example usage:
package com.mycom;
public class Foo {
// Search for tag Foo_theMessage in /com/mycom/Bundle.properties:
private static String theMessage =
NbBundle.getMessage
(Foo.class, "Foo_theMessage");
// Might also look in /com/mycom/Bundle_de.properties, etc.
}
Nested Class Summary | |
static interface |
NbBundle.ClassLoaderFinder
Deprecated. Useless. |
Constructor Summary | |
NbBundle()
Deprecated. There is no reason to instantiate or subclass this class. All methods in it are static. |
Method Summary | |
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 and the class' own classloader. |
static ResourceBundle |
getBundle(String baseName)
Get a resource bundle with the default class loader and locale. |
static ResourceBundle |
getBundle(String baseName,
Locale locale)
Get a resource bundle with the default class loader. |
static ResourceBundle |
getBundle(String baseName,
Locale locale,
ClassLoader loader)
Get a resource bundle the hard way. |
static URL |
getLocalizedFile(String baseName,
String ext)
Get a localized file in the default locale with the default class loader. |
static URL |
getLocalizedFile(String baseName,
String ext,
Locale locale)
Get a localized file with the default class loader. |
static URL |
getLocalizedFile(String baseName,
String ext,
Locale locale,
ClassLoader loader)
Get a localized file. |
static String |
getLocalizedValue(Attributes attr,
Attributes.Name key)
Find a localized value in a JAR manifest in the default system locale. |
static String |
getLocalizedValue(Attributes attr,
Attributes.Name key,
Locale locale)
Find a localized value in a JAR manifest. |
static Object |
getLocalizedValue(Map table,
String key)
Find a localized value for a given key in the default system locale. |
static Object |
getLocalizedValue(Map table,
String key,
Locale locale)
Find a localized value for a given key and locale. |
static Iterator |
getLocalizingSuffixes()
Get a list of all suffixes used to search for localized resources. |
static String |
getMessage(Class clazz,
String resName)
Finds a localized string in a bundle. |
static String |
getMessage(Class clazz,
String resName,
Object param1)
Finds a localized string in a bundle and formats the message by passing requested parameters. |
static String |
getMessage(Class clazz,
String resName,
Object[] arr)
Finds a localized 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 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 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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public NbBundle()
Method Detail |
public static String getBranding()
null
for nonepublic static void setBranding(String bt) throws IllegalArgumentException
/^[a-z][a-z0-9]*(_[a-z][a-z0-9]*)*$/
bt
- the new branding, or null
to clear
IllegalArgumentException
- if in an incorrect formatpublic static URL getLocalizedFile(String baseName, String ext) throws MissingResourceException
Note that use of this call is similar to using the URL protocol nbresloc
(which is in fact 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 foundpublic static URL getLocalizedFile(String baseName, String ext, Locale locale) throws MissingResourceException
baseName
- base name of file, as dot-separated path (e.g. some.dir.File
)ext
- extension of file (or null
)locale
- locale of file
MissingResourceException
- if not foundpublic static URL getLocalizedFile(String baseName, String ext, Locale locale, ClassLoader loader) throws MissingResourceException
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 use
MissingResourceException
- if not foundpublic static Object getLocalizedValue(Map 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 use
null
if no key matchespublic static Object getLocalizedValue(Map table, String key)
table
- mapping from localized strings to objectskey
- the key to look for
null
if no key matchesgetLocalizedValue(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 use
null
public static String getLocalizedValue(Attributes attr, Attributes.Name key)
attr
- the manifest attributeskey
- the key to look for (case-insensitive)
null
public static final ResourceBundle getBundle(String baseName) throws 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. The
IDE 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 basename
MissingResourceException
- if the bundle does not existpublic static ResourceBundle getBundle(Class clazz) throws MissingResourceException
clazz
- the class to take the package name from
MissingResourceException
- if the bundle does not existpublic static final ResourceBundle getBundle(String baseName, Locale locale) throws MissingResourceException
baseName
- bundle basenamelocale
- the locale to use
MissingResourceException
- if the bundle does not existpublic static final ResourceBundle getBundle(String baseName, Locale locale, ClassLoader loader) throws MissingResourceException
baseName
- bundle basenamelocale
- the locale to useloader
- the class loader to use
MissingResourceException
- if the bundle does not existpublic static String getMessage(Class clazz, String resName) throws MissingResourceException
clazz
- the class to use to locate the bundleresName
- name of the resource to look for
MissingResourceException
- 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 bundleresName
- name of the resource to look forparam1
- the argument to use when formatting the message
MissingResourceException
- 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 bundleresName
- name of the resource to look forparam1
- the argument to use when formatting the messageparam2
- the second argument to use for formatting
MissingResourceException
- 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 bundleresName
- 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 formatting
MissingResourceException
- 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 bundleresName
- name of the resource to look forarr
- array of parameters to use for formatting the message
MissingResourceException
- if either the bundle or the string cannot be foundMessageFormat.format(String,Object[])
public static Iterator getLocalizingSuffixes()
NbBundle
methods use as the search order.
For example, you might get a sequence such as:
String
public static void setClassLoaderFinder(NbBundle.ClassLoaderFinder loaderFinder)
loaderFinder
- ignored
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |