| java.lang.Object org.ofbiz.base.util.UtilProperties
UtilProperties | public class UtilProperties (Code) | | Generic Property Accessor with Cache - Utilities for working with properties files
author: David E. Jones version: $Revision: 1.9 $ since: 1.0 |
Method Summary | |
protected static ResourceBundle | getBaseResourceBundle(String resource, Locale locale) | public static String | getMessage(String resource, String name, Locale locale) Returns the value of the specified property name from the specified resource/properties file corresponding to the given locale. | public static String | getMessage(String resource, String name, Object[] arguments, Locale locale) | public static String | getMessage(String resource, String name, List arguments, Locale locale) | public static String | getMessage(String resource, String name, Map context, Locale locale) | public static Properties | getProperties(String resource) | public static Properties | getProperties(URL url) | public static Properties | getProperties(String resource, Locale locale) Returns the specified resource/properties file
NOTE: This is NOT fully implemented yet to fulfill all of the requirements
for i18n messages. | public static double | getPropertyNumber(String resource, String name) | public static double | getPropertyNumber(URL url, String name) | public static String | getPropertyValue(String resource, String name, String defaultValue) Returns the value of the specified property name from the specified resource/properties file. | public static String | getPropertyValue(String resource, String name) | public static String | getPropertyValue(URL url, String name, String defaultValue) Returns the value of the specified property name from the specified resource/properties file. | public static String | getPropertyValue(URL url, String name) | public static ResourceBundle | getResourceBundle(String resource, Locale locale) | public static Map | getResourceBundleMap(String resource, Locale locale) | public static String | getSplitPropertyValue(URL url, String name) Returns the value of a split property name from the specified resource/properties file
Rather than specifying the property name the value of a name.X property is specified which
will correspond to a value.X property whose value will be returned. | public static boolean | propertyValueEquals(String resource, String name, String compareString) | public static boolean | propertyValueEquals(URL url, String name, String compareString) | public static boolean | propertyValueEqualsIgnoreCase(String resource, String name, String compareString) | public static boolean | propertyValueEqualsIgnoreCase(URL url, String name, String compareString) | protected static Map | resourceBundleToMap(ResourceBundle bundle) |
bundleLocaleCache | public static UtilCache bundleLocaleCache(Code) | | An instance of the generic cache for storing the ResourceBundle
corresponding to each properties file keyed by a String for the resource location and the locale
|
resourceCache | public static UtilCache resourceCache(Code) | | An instance of the generic cache for storing the FlexibleProperties
corresponding to each properties file keyed by a String for the resource location.
This will be used for both non-locale and locale keyed FexibleProperties instances.
|
urlCache | public static UtilCache urlCache(Code) | | An instance of the generic cache for storing the FlexibleProperties
corresponding to each properties file keyed by a URL object
|
getMessage | public static String getMessage(String resource, String name, Locale locale)(Code) | | Returns the value of the specified property name from the specified resource/properties file corresponding to the given locale.
Two reasons why we do not use the FlexibleProperties class for this:
- Doesn't support flexible locale based naming: try fname_locale (5 letter), then fname_locale (2 letter lang only), then fname
- Does not support parent properties/bundles so that if the fname_locale5 file doesn't have it then fname_locale2 is tried, then the fname bundle
Parameters: resource - The name of the resource - can be a file, class, or URL Parameters: name - The name of the property in the properties file Parameters: locale - The locale that the given resource will correspond to The value of the property in the properties file |
getMessage | public static String getMessage(String resource, String name, Object[] arguments, Locale locale)(Code) | | Returns the value of the specified property name from the specified resource/properties file corresponding
to the given locale and replacing argument place holders with the given arguments using the MessageFormat class
Parameters: resource - The name of the resource - can be a file, class, or URL Parameters: name - The name of the property in the properties file Parameters: locale - The locale that the given resource will correspond to Parameters: arguments - An array of Objects to insert into the message argument place holders The value of the property in the properties file |
getMessage | public static String getMessage(String resource, String name, List arguments, Locale locale)(Code) | | Returns the value of the specified property name from the specified resource/properties file corresponding
to the given locale and replacing argument place holders with the given arguments using the MessageFormat class
Parameters: resource - The name of the resource - can be a file, class, or URL Parameters: name - The name of the property in the properties file Parameters: locale - The locale that the given resource will correspond to Parameters: arguments - A List of Objects to insert into the message argument place holders The value of the property in the properties file |
getMessage | public static String getMessage(String resource, String name, Map context, Locale locale)(Code) | | Returns the value of the specified property name from the specified resource/properties file corresponding
to the given locale and replacing argument place holders with the given arguments using the FlexibleStringExpander class
Parameters: resource - The name of the resource - can be a file, class, or URL Parameters: name - The name of the property in the properties file Parameters: locale - The locale that the given resource will correspond to Parameters: context - A Map of Objects to insert into the message place holders using the ${} syntax of the FlexibleStringExpander The value of the property in the properties file |
getProperties | public static Properties getProperties(String resource)(Code) | | Returns the specified resource/properties file
Parameters: resource - The name of the resource - can be a file, class, or URL The properties file |
getProperties | public static Properties getProperties(URL url)(Code) | | Returns the specified resource/properties file
Parameters: resource - The name of the resource - can be a file, class, or URL The properties file |
getProperties | public static Properties getProperties(String resource, Locale locale)(Code) | | Returns the specified resource/properties file
NOTE: This is NOT fully implemented yet to fulfill all of the requirements
for i18n messages. Do NOT use.
To be used in an i18n context this still needs to be extended quite
a bit. The behavior needed is that for each getMessage the most specific
locale (with fname_en_US for instance) is searched first, then the next
less specific (fname_en for instance), then without the locale if it is
still not found (plain fname for example, not that these examples would
have .properties appended to them).
This would be accomplished by returning the following structure:
1. Get "fname" FlexibleProperties object
2. Get the "fname_en" FlexibleProperties object and if the "fname" one
is not null, set it as the default/parent of the "fname_en" object
3. Get the "fname_en_US" FlexibleProperties object and if the
"fname_en" one is not null, set it as the default/parent of the
"fname_en_US" object; if the "fname_en" one is null, but the "fname"
one is not, set the "fname" object as the default/parent of the
"fname_en_US" object
Then return the fname_en_US object if not null, else the fname_en, else the fname.
To make this all more fun, the default locale should be the parent of
the "fname" object in this example so that there is an even higher
chance of finding something for each request.
For efficiency all of these should be cached indendependently so the same
instance can be shared, speeding up loading time/efficiency.
All of this should work with the setDefaultProperties method of the
FlexibleProperties class, but it should be tested and updated as
necessary. It's a bit tricky, so chances are it won't work as desired...
Parameters: resource - The name of the resource - can be a file, class, or URL Parameters: locale - The locale that the given resource will correspond to The Properties class |
getPropertyNumber | public static double getPropertyNumber(String resource, String name)(Code) | | |
getPropertyNumber | public static double getPropertyNumber(URL url, String name)(Code) | | |
getPropertyValue | public static String getPropertyValue(String resource, String name, String defaultValue)(Code) | | Returns the value of the specified property name from the specified resource/properties file.
If the specified property name or properties file is not found, the defaultValue is returned.
Parameters: resource - The name of the resource - if the properties file is 'webevent.properties', the resource name is 'webevent' Parameters: name - The name of the property in the properties file Parameters: defaultValue - The value to return if the property is not found The value of the property in the properties file, or if not found then the defaultValue |
getPropertyValue | public static String getPropertyValue(String resource, String name)(Code) | | Returns the value of the specified property name from the specified resource/properties file
Parameters: resource - The name of the resource - can be a file, class, or URL Parameters: name - The name of the property in the properties file The value of the property in the properties file |
getPropertyValue | public static String getPropertyValue(URL url, String name, String defaultValue)(Code) | | Returns the value of the specified property name from the specified resource/properties file.
If the specified property name or properties file is not found, the defaultValue is returned.
Parameters: url - URL object specifying the location of the resource Parameters: name - The name of the property in the properties file Parameters: defaultValue - The value to return if the property is not found The value of the property in the properties file, or if not found then the defaultValue |
getPropertyValue | public static String getPropertyValue(URL url, String name)(Code) | | Returns the value of the specified property name from the specified resource/properties file
Parameters: url - URL object specifying the location of the resource Parameters: name - The name of the property in the properties file The value of the property in the properties file |
getResourceBundle | public static ResourceBundle getResourceBundle(String resource, Locale locale)(Code) | | Returns the specified resource/properties file as a ResourceBundle
Parameters: resource - The name of the resource - can be a file, class, or URL Parameters: locale - The locale that the given resource will correspond to The ResourceBundle |
getResourceBundleMap | public static Map getResourceBundleMap(String resource, Locale locale)(Code) | | Returns the specified resource/properties file as a Map with the original ResourceBundle in the Map under the key _RESOURCE_BUNDLE_
Parameters: resource - The name of the resource - can be a file, class, or URL Parameters: locale - The locale that the given resource will correspond to Map containing all entries in The ResourceBundle |
getSplitPropertyValue | public static String getSplitPropertyValue(URL url, String name)(Code) | | Returns the value of a split property name from the specified resource/properties file
Rather than specifying the property name the value of a name.X property is specified which
will correspond to a value.X property whose value will be returned. X is a number from 1 to
whatever and all values are checked until a name.X for a certain X is not found.
Parameters: url - URL object specifying the location of the resource Parameters: name - The name of the split property in the properties file The value of the split property from the properties file |
propertyValueEquals | public static boolean propertyValueEquals(String resource, String name, String compareString)(Code) | | Compares the specified property to the compareString, returns true if they are the same, false otherwise
Parameters: resource - The name of the resource - if the properties file is 'webevent.properties', the resource name is 'webevent' Parameters: name - The name of the property in the properties file Parameters: compareString - The String to compare the property value to True if the strings are the same, false otherwise |
propertyValueEquals | public static boolean propertyValueEquals(URL url, String name, String compareString)(Code) | | Compares the specified property to the compareString, returns true if they are the same, false otherwise
Parameters: url - URL object specifying the location of the resource Parameters: name - The name of the property in the properties file Parameters: compareString - The String to compare the property value to True if the strings are the same, false otherwise |
propertyValueEqualsIgnoreCase | public static boolean propertyValueEqualsIgnoreCase(String resource, String name, String compareString)(Code) | | Compares Ignoring Case the specified property to the compareString, returns true if they are the same, false otherwise
Parameters: resource - The name of the resource - if the properties file is 'webevent.properties', the resource name is 'webevent' Parameters: name - The name of the property in the properties file Parameters: compareString - The String to compare the property value to True if the strings are the same, false otherwise |
propertyValueEqualsIgnoreCase | public static boolean propertyValueEqualsIgnoreCase(URL url, String name, String compareString)(Code) | | Compares Ignoring Case the specified property to the compareString, returns true if they are the same, false otherwise
Parameters: url - URL object specifying the location of the resource Parameters: name - The name of the property in the properties file Parameters: compareString - The String to compare the property value to True if the strings are the same, false otherwise |
|
|