站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc 5.5.0

NbBundle (NetBeans Utilities API) - NetBeans API Javadoc 5.5.0

org.openide.util 6.8.22

org.openide.util
Class NbBundle

java.lang.Object
  extended by org.openide.util.NbBundle

public class NbBundle
extends Object

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/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 Object getLocalizedValue(Map table, String key)
          Find a localized and/or branded value for a given key in the default system locale.
static Object getLocalizedValue(Map table, String key, Locale locale)
          Find a localized and/or branded value for a given key and locale.
static Iterator 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 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

NbBundle

public NbBundle()
Deprecated. There is no reason to instantiate or subclass this class. All methods in it are static.

Do not call.

Method Detail

getBranding

public static String getBranding()
Get the current branding token.

Returns:
the branding, or null for none

setBranding

public static void setBranding(String bt)
                        throws IllegalArgumentException
Set the current branding token. The permitted format, as a regular expression:
[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.

Parameters:
bt - the new branding, or null to clear
Throws:
IllegalArgumentException - if in an incorrect format

getLocalizedFile

public static URL getLocalizedFile(String baseName,
                                   String ext)
                            throws MissingResourceException
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.

Get a localized and/or branded file in the default locale with the default class loader.

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.

Parameters:
baseName - base name of file, as dot-separated path (e.g. some.dir.File)
ext - extension of file (or null)
Returns:
URL of matching localized file
Throws:
MissingResourceException - if not found

getLocalizedFile

public static URL getLocalizedFile(String baseName,
                                   String ext,
                                   Locale locale)
                            throws MissingResourceException
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.

Get a localized and/or branded file with the default class loader.

Parameters:
baseName - base name of file, as dot-separated path (e.g. some.dir.File)
ext - extension of file (or null)
locale - locale of file
Returns:
URL of matching localized file
Throws:
MissingResourceException - if not found

getLocalizedFile

public static URL getLocalizedFile(String baseName,
                                   String ext,
                                   Locale locale,
                                   ClassLoader loader)
                            throws MissingResourceException
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.

Get a localized and/or branded file.

Parameters:
baseName - base name of file, as dot-separated path (e.g. some.dir.File)
ext - extension of file (or null)
locale - locale of file
loader - class loader to use
Returns:
URL of matching localized file
Throws:
MissingResourceException - if not found

getLocalizedValue

public static Object getLocalizedValue(Map table,
                                       String key,
                                       Locale locale)
Find a localized and/or branded value for a given key and locale. Scans through a map to find the most localized match possible. For example:

   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")

Parameters:
table - mapping from localized strings to objects
key - the key to look for
locale - the locale to use
Returns:
the localized object or null if no key matches

getLocalizedValue

public static Object getLocalizedValue(Map table,
                                       String key)
Find a localized and/or branded value for a given key in the default system locale.

Parameters:
table - mapping from localized strings to objects
key - the key to look for
Returns:
the localized object or null if no key matches
See Also:
getLocalizedValue(Map,String,Locale)

getLocalizedValue

public static String getLocalizedValue(Attributes attr,
                                       Attributes.Name key,
                                       Locale locale)
Find a localized and/or branded value in a JAR manifest.

Parameters:
attr - the manifest attributes
key - the key to look for (case-insensitive)
locale - the locale to use
Returns:
the value if found, else null

getLocalizedValue

public static String getLocalizedValue(Attributes attr,
                                       Attributes.Name key)
Find a localized and/or branded value in a JAR manifest in the default system locale.

Parameters:
attr - the manifest attributes
key - the key to look for (case-insensitive)
Returns:
the value if found, else null

getBundle

public static final ResourceBundle getBundle(String baseName)
                                      throws MissingResourceException
Get a resource bundle with the default class loader and locale/branding. Caution: 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.

Parameters:
baseName - bundle basename
Returns:
the resource bundle
Throws:
MissingResourceException - if the bundle does not exist

getBundle

public static ResourceBundle getBundle(Class clazz)
                                throws MissingResourceException
Get a resource bundle in the same package as the provided class, with the default locale/branding and the class' own classloader. This is the usual style of invocation.

Parameters:
clazz - the class to take the package name from
Returns:
the resource bundle
Throws:
MissingResourceException - if the bundle does not exist

getBundle

public static final ResourceBundle getBundle(String baseName,
                                             Locale locale)
                                      throws MissingResourceException
Get a resource bundle with the default class loader and branding.

Parameters:
baseName - bundle basename
locale - the locale to use (but still uses default branding)
Returns:
the resource bundle
Throws:
MissingResourceException - if the bundle does not exist

getBundle

public static final ResourceBundle getBundle(String baseName,
                                             Locale locale,
                                             ClassLoader loader)
                                      throws MissingResourceException
Get a resource bundle the hard way.

Parameters:
baseName - bundle basename
locale - the locale to use (but still uses default branding)
loader - the class loader to use
Returns:
the resource bundle
Throws:
MissingResourceException - if the bundle does not exist

getMessage

public static String getMessage(Class clazz,
                                String resName)
                         throws MissingResourceException
Finds a localized and/or branded string in a bundle.

Parameters:
clazz - the class to use to locate the bundle
resName - name of the resource to look for
Returns:
the string associated with the resource
Throws:
MissingResourceException - if either the bundle or the string cannot be found

getMessage

public static String getMessage(Class clazz,
                                String resName,
                                Object param1)
                         throws MissingResourceException
Finds a localized and/or branded string in a bundle and formats the message by passing requested parameters.

Parameters:
clazz - the class to use to locate the bundle
resName - name of the resource to look for
param1 - the argument to use when formatting the message
Returns:
the string associated with the resource
Throws:
MissingResourceException - if either the bundle or the string cannot be found
See Also:
MessageFormat.format(String,Object[])

getMessage

public static String getMessage(Class clazz,
                                String resName,
                                Object param1,
                                Object param2)
                         throws MissingResourceException
Finds a localized and/or branded string in a bundle and formats the message by passing requested parameters.

Parameters:
clazz - the class to use to locate the bundle
resName - name of the resource to look for
param1 - the argument to use when formatting the message
param2 - the second argument to use for formatting
Returns:
the string associated with the resource
Throws:
MissingResourceException - if either the bundle or the string cannot be found
See Also:
MessageFormat.format(String,Object[])

getMessage

public static String getMessage(Class clazz,
                                String resName,
                                Object param1,
                                Object param2,
                                Object param3)
                         throws MissingResourceException
Finds a localized and/or branded string in a bundle and formats the message by passing requested parameters.

Parameters:
clazz - the class to use to locate the bundle
resName - name of the resource to look for
param1 - the argument to use when formatting the message
param2 - the second argument to use for formatting
param3 - the third argument to use for formatting
Returns:
the string associated with the resource
Throws:
MissingResourceException - if either the bundle or the string cannot be found
See Also:
MessageFormat.format(String,Object[])

getMessage

public static String getMessage(Class clazz,
                                String resName,
                                Object[] arr)
                         throws MissingResourceException
Finds a localized and/or branded string in a bundle and formats the message by passing requested parameters.

Parameters:
clazz - the class to use to locate the bundle
resName - name of the resource to look for
arr - array of parameters to use for formatting the message
Returns:
the string associated with the resource
Throws:
MissingResourceException - if either the bundle or the string cannot be found
See Also:
MessageFormat.format(String,Object[])

getLocalizingSuffixes

public static Iterator getLocalizingSuffixes()
Get a list of all suffixes used to search for localized/branded resources. Based on the default locale and branding, returns the list of suffixes which various 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:
  1. "_branding_de"
  2. "_branding"
  3. "_de"
  4. ""

Returns:
a read-only iterator of type String
Since:
1.1.5

setClassLoaderFinder

public static void setClassLoaderFinder(NbBundle.ClassLoaderFinder loaderFinder)
Deprecated. Useless.

Do not use.

Parameters:
loaderFinder - ignored

org.openide.util 6.8.22

Built on May 28 2007.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.