public final class ResourceBundleUtils extends Object
ResourceBundles.| Modifier and Type | Field and Description |
|---|---|
static String |
KEY_PREFIX
The prefix for resource keys to mark them as I18N keys.
|
static String |
PACKAGE_RESOURCE_BUNDLE_BASE_NAME
The resource bundle base name of package resource bundles.
|
| Modifier and Type | Method and Description |
|---|---|
static ResourceBundle |
getClassResourceBundle(Class<?> type)
Gets the resource bundle, which is in the same package as the provided type and has a base name equal to the simple name of the provided class.
|
static String |
getClassResourceStringPrefixed(Class<?> type,
String resourceKey)
Gets a resource string from the class-
ResourceBundle (same package and same base name as the provided type), if the resourceKey is prefixed with '%', else the resoure
key itself gets returned (no I18N). |
static ResourceBundle |
getConditionalResourceBundle(Class<?> type,
String resourceBundleBaseName)
Gets the
ResourceBundle. |
static ResourceBundle |
getConditionalResourceBundlePrefixed(Class<?> type,
String resourceBundleBaseName,
String resourceKey)
Gets the
ResourceBundle if the resource key is prefixed with '%', else null (no I18N). |
static ResourceBundle |
getPackageResourceBundle(Class<?> type)
Gets the package-
ResourceBundle (Bundle.properties), which is in the same package as the specified type. |
static String |
getPackageResourceStringPrefixed(Class<?> type,
String resourceKey)
Gets a resource string from the package-
ResourceBundle (Bundle.properties), if the resourceKey is prefixed with '%', else the resoure key itself gets returned (no
I18N). |
static String |
getPackageResourceStringPrefixed(String aPackage,
String resourceKey,
ClassLoader classLoader)
Gets a resource string from the package-
ResourceBundle (Bundle.properties), if the resourceKey is prefixed with '%', else the resoure key itself gets returned (no
I18N). |
static String |
getResourceStringPrefixed(String resourceKey,
ResourceBundle resourceBundle)
If the resource key starts with '%' prefix, the prefix gets stripped and the value gets read from the provided
ResourceBundle, else the provided resourceKey will be returned without
lookup (no I18N). |
static boolean |
isPrefixedResourceString(String resourceKey)
Checks if the resource key starts with the '%' prefix, which marks it as an I18N key.
|
public static final String PACKAGE_RESOURCE_BUNDLE_BASE_NAME
public static final String KEY_PREFIX
public static ResourceBundle getConditionalResourceBundlePrefixed(Class<?> type, String resourceBundleBaseName, String resourceKey)
ResourceBundle if the resource key is prefixed with '%', else null (no I18N).If resourceBundleBaseName is null, thegetClassResourceBundle(java.lang.Class)gets returned. If resourceBundleBaseName equals 'Bundle', thegetPackageResourceBundle(java.lang.Class)gets returned. Else the ResourceBundle for the resourceBundleBaseName gets returned using the sameClassLoaderas the provided type.
type - the typeresourceBundleBaseName - the base name of the ResourceBundle, 'Bundle' (for the package ResourceBundle) or null (for the class ResourceBundle).resourceKey - the prefixed resourceKey or the value to return (no I18N)getClassResourceBundle(java.lang.Class),
getPackageResourceBundle(java.lang.Class),
getConditionalResourceBundle(java.lang.Class, java.lang.String),
KEY_PREFIX,
PACKAGE_RESOURCE_BUNDLE_BASE_NAMEpublic static ResourceBundle getConditionalResourceBundle(Class<?> type, String resourceBundleBaseName)
ResourceBundle.If resourceBundleBaseName is null, thegetClassResourceBundle(java.lang.Class)gets returned. If resourceBundleBaseName equals 'Bundle', thegetPackageResourceBundle(java.lang.Class)gets returned. Else the ResourceBundle for the resourceBundleBaseName gets returned using the sameClassLoaderas the provided type.
type - the typeresourceBundleBaseName - the base name of the ResourceBundle, 'Bundle' (for the package ResourceBundle) or null (for the class ResourceBundle).getClassResourceBundle(java.lang.Class),
getPackageResourceBundle(java.lang.Class),
PACKAGE_RESOURCE_BUNDLE_BASE_NAMEpublic static ResourceBundle getClassResourceBundle(Class<?> type)
type - the typegetResourceBundle(java.lang.Class, java.lang.String)public static String getClassResourceStringPrefixed(Class<?> type, String resourceKey)
ResourceBundle (same package and same base name as the provided type), if the resourceKey is prefixed with '%', else the resoure
key itself gets returned (no I18N).type - the type of the same package and the same simple name as the base name of the ResourceBundleresourceKey - the prefixed resourceKey or the value to return (no I18N)KEY_PREFIXpublic static ResourceBundle getPackageResourceBundle(Class<?> type)
ResourceBundle (Bundle.properties), which is in the same package as the specified type.type - a type of the same packagePACKAGE_RESOURCE_BUNDLE_BASE_NAMEpublic static String getPackageResourceStringPrefixed(Class<?> type, String resourceKey)
ResourceBundle (Bundle.properties), if the resourceKey is prefixed with '%', else the resoure key itself gets returned (no
I18N).type - a type of the packageresourceKey - the prefixed keyKEY_PREFIXpublic static String getPackageResourceStringPrefixed(String aPackage, String resourceKey, ClassLoader classLoader)
ResourceBundle (Bundle.properties), if the resourceKey is prefixed with '%', else the resoure key itself gets returned (no
I18N).aPackage - the packageresourceKey - the prefixed resourceKey or the value to return (no I18N)classLoader - the ClassLoader to load the ResourceBundleKEY_PREFIXpublic static String getResourceStringPrefixed(String resourceKey, ResourceBundle resourceBundle)
ResourceBundle, else the provided resourceKey will be returned without
lookup (no I18N).resourceKey - the prefixed resourceKey or the value to return (no I18N)resourceBundle - the ResourceBundle to lookup valuesMissingResourceException - if no value for the specified key can be foundClassCastException - if the value is not a StringKEY_PREFIXpublic static boolean isPrefixedResourceString(String resourceKey)
resourceKey - the resource key to checkKEY_PREFIXCopyright © 2012–2019 Drombler. All rights reserved.