Class PropertyResourceBundleUtils
- java.lang.Object
-
- io.microsphere.util.PropertyResourceBundleUtils
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_ENCODING
The default encoding forPropertyResourceBundle
, retrieved from the system property specified byDEFAULT_ENCODING_PROPERTY_NAME
.static java.lang.String
DEFAULT_ENCODING_PROPERTY_NAME
The system property name for specifying the default encoding used byPropertyResourceBundle
.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.ResourceBundle
getBundle(java.lang.String baseName)
Gets a resource bundle using the specified base name and the default encoding.static java.util.ResourceBundle
getBundle(java.lang.String baseName, java.lang.String encoding)
Retrieves a resource bundle using the specified base name and character encoding.static java.util.ResourceBundle
getBundle(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader classLoader, java.lang.String encoding)
Retrieves a resource bundle using the specified base name, locale, class loader, and character encoding.static java.util.ResourceBundle
getBundle(java.lang.String baseName, java.util.Locale locale, java.lang.String encoding)
Retrieves a resource bundle using the specified base name, locale, and character encoding.
-
-
-
Field Detail
-
DEFAULT_ENCODING_PROPERTY_NAME
public static final java.lang.String DEFAULT_ENCODING_PROPERTY_NAME
The system property name for specifying the default encoding used byPropertyResourceBundle
.This property is typically used to set the character encoding for reading properties files. If not explicitly set, the value of this property defaults to the platform's file encoding (
SystemUtils.FILE_ENCODING
).Example Usage
// Setting the default encoding to UTF-8 programmatically System.setProperty(PropertyResourceBundleUtils.DEFAULT_ENCODING_PROPERTY_NAME, "UTF-8"); // Then using it when loading a bundle ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages");
- See Also:
PropertyResourceBundle
,SystemUtils.FILE_ENCODING
, Constant Field Values
-
DEFAULT_ENCODING
public static final java.lang.String DEFAULT_ENCODING
The default encoding forPropertyResourceBundle
, retrieved from the system property specified byDEFAULT_ENCODING_PROPERTY_NAME
. If not explicitly set, it falls back to the platform's file encoding (SystemUtils.FILE_ENCODING
).Example Usage
// Programmatically setting the default encoding to UTF-8 System.setProperty(PropertyResourceBundleUtils.DEFAULT_ENCODING_PROPERTY_NAME, "UTF-8"); // Getting the default encoding String encoding = PropertyResourceBundleUtils.DEFAULT_ENCODING;
-
-
Method Detail
-
getBundle
@Nonnull public static java.util.ResourceBundle getBundle(java.lang.String baseName)
Gets a resource bundle using the specified base name and the default encoding.ResourceBundle.getBundle(String, Locale)
withdefault file encoding
encoding anddefault Locale
underThread context ClassLoader
This method is a convenience shortcut for:
getBundle(baseName, PropertyResourceBundleUtils.DEFAULT_ENCODING);
Example Usage
ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages");
- Parameters:
baseName
- the base name of the resource bundle, a fully qualified class name- Returns:
- the resource bundle
- Throws:
java.lang.NullPointerException
- ifbaseName
isnull
java.util.MissingResourceException
- if no resource bundle for the specified base name can be foundjava.lang.IllegalArgumentException
- if the given control doesn't perform properly (e.g.,control.getCandidateLocales
returns null)
-
getBundle
@Nonnull public static java.util.ResourceBundle getBundle(java.lang.String baseName, java.lang.String encoding)
Retrieves a resource bundle using the specified base name and character encoding.This method loads the resource bundle with the given base name and uses the specified encoding for reading the properties file. It uses the default locale (
Locale.getDefault()
) and the thread context class loader to locate and load the bundle.Example Usage
// Load a ResourceBundle with a specific encoding (e.g., UTF-8) ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages", "UTF-8");
- Parameters:
baseName
- the base name of the resource bundle, typically a fully qualified class nameencoding
- the character encoding used to read the properties file, such as "UTF-8"- Returns:
- the loaded resource bundle
- Throws:
java.lang.NullPointerException
- if the baseName or encoding is nulljava.util.MissingResourceException
- if no resource bundle can be found for the specified base namejava.lang.IllegalArgumentException
- if the encoding is not supported or the control object behaves improperly
-
getBundle
@Nonnull public static java.util.ResourceBundle getBundle(java.lang.String baseName, java.util.Locale locale, java.lang.String encoding)
Retrieves a resource bundle using the specified base name, locale, and character encoding.This method loads the resource bundle with the given base name and locale, using the specified encoding for reading the properties file. It uses the thread context class loader to locate and load the bundle.
Example Usage
// Load a ResourceBundle for a specific locale and encoding ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages", Locale.FRENCH, "UTF-8");
- Parameters:
baseName
- the base name of the resource bundle, typically a fully qualified class namelocale
- the locale for which a resource bundle is desiredencoding
- the character encoding used to read the properties file, such as "UTF-8"- Returns:
- the loaded resource bundle
- Throws:
java.lang.NullPointerException
- if the baseName, locale, or encoding is nulljava.util.MissingResourceException
- if no resource bundle can be found for the specified base name and localejava.lang.IllegalArgumentException
- if the encoding is not supported or the control object behaves improperly
-
getBundle
@Nonnull public static java.util.ResourceBundle getBundle(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader classLoader, java.lang.String encoding)
Retrieves a resource bundle using the specified base name, locale, class loader, and character encoding.This method loads the resource bundle with the given base name and locale, using the specified class loader and character encoding for reading the properties file.
Example Usage
// Load a ResourceBundle with a specific locale, class loader, and encoding ClassLoader loader = MyClass.class.getClassLoader(); ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages", Locale.GERMAN, loader, "UTF-8");
- Parameters:
baseName
- the base name of the resource bundle, typically a fully qualified class namelocale
- the locale for which a resource bundle is desiredclassLoader
- the class loader to use for loading the bundleencoding
- the character encoding used to read the properties file, such as "UTF-8"- Returns:
- the loaded resource bundle
- Throws:
java.lang.NullPointerException
- if any of the parameters (baseName, locale, classLoader, encoding) is nulljava.util.MissingResourceException
- if no resource bundle can be found for the specified base name and localejava.lang.IllegalArgumentException
- if the encoding is not supported or the control object behaves improperly
-
-