Package org.ofbiz.core.util
Class UtilProperties
java.lang.Object
org.ofbiz.core.util.UtilProperties
Generic Property Accessor with Cache - Utilities for working with properties files
- Version:
- 1.0
- Author:
- David E. Jones
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic UtilCache<String,ResourceBundle> 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 localestatic UtilCache<Object,FlexibleProperties> An instance of the generic cache for storing the FlexibleProperties corresponding to each properties file keyed by a String for the resource location.static UtilCache<URL,FlexibleProperties> An instance of the generic cache for storing the FlexibleProperties corresponding to each properties file keyed by a URL object -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetMessage(String resource, String name, Object[] arguments, Locale locale) 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 classstatic StringgetMessage(String resource, String name, List<?> arguments, Locale locale) 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 classstatic StringgetMessage(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.static PropertiesgetProperties(String resource) Returns the specified resource/properties filestatic PropertiesgetProperties(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.static PropertiesgetProperties(URL url) Returns the specified resource/properties filestatic doublegetPropertyNumber(String resource, String name) static doublegetPropertyNumber(URL url, String name) static StringgetPropertyValue(String resource, String name) Returns the value of the specified property name from the specified resource/properties filestatic StringgetPropertyValue(String resource, String name, String defaultValue) Returns the value of the specified property name from the specified resource/properties file.static StringgetPropertyValue(URL url, String name) Returns the value of the specified property name from the specified resource/properties filestatic StringgetPropertyValue(URL url, String name, String defaultValue) Returns the value of the specified property name from the specified resource/properties file.static ResourceBundlegetResourceBundle(String resource, Locale locale) Returns the specified resource/properties file as a ResourceBundlestatic StringgetSplitPropertyValue(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.static booleanpropertyValueEquals(String resource, String name, String compareString) Compares the specified property to the compareString, returns true if they are the same, false otherwisestatic booleanpropertyValueEquals(URL url, String name, String compareString) Compares the specified property to the compareString, returns true if they are the same, false otherwisestatic booleanpropertyValueEqualsIgnoreCase(String resource, String name, String compareString) Compares Ignoring Case the specified property to the compareString, returns true if they are the same, false otherwisestatic booleanpropertyValueEqualsIgnoreCase(URL url, String name, String compareString) Compares Ignoring Case the specified property to the compareString, returns true if they are the same, false otherwise
-
Field Details
-
resourceCache
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
An instance of the generic cache for storing the FlexibleProperties corresponding to each properties file keyed by a URL object -
bundleLocaleCache
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
-
-
Constructor Details
-
UtilProperties
public UtilProperties()
-
-
Method Details
-
propertyValueEquals
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'name- The name of the property in the properties filecompareString- The String to compare the property value to- Returns:
- True if the strings are the same, false otherwise
-
propertyValueEqualsIgnoreCase
public static boolean propertyValueEqualsIgnoreCase(String resource, String name, String compareString) 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'name- The name of the property in the properties filecompareString- The String to compare the property value to- Returns:
- True if the strings are the same, false otherwise
-
getPropertyValue
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'name- The name of the property in the properties filedefaultValue- The value to return if the property is not found- Returns:
- The value of the property in the properties file, or if not found then the defaultValue
-
getPropertyNumber
-
getPropertyValue
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 URLname- The name of the property in the properties file- Returns:
- The value of the property in the properties file
-
getProperties
Returns the specified resource/properties file- Parameters:
resource- The name of the resource - can be a file, class, or URL- Returns:
- The properties file
-
getProperties
Returns the specified resource/properties file- Parameters:
url- The url of the resource- Returns:
- The properties file
-
propertyValueEquals
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 resourcename- The name of the property in the properties filecompareString- The String to compare the property value to- Returns:
- True if the strings are the same, false otherwise
-
propertyValueEqualsIgnoreCase
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 resourcename- The name of the property in the properties filecompareString- The String to compare the property value to- Returns:
- True if the strings are the same, false otherwise
-
getPropertyValue
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 resourcename- The name of the property in the properties filedefaultValue- The value to return if the property is not found- Returns:
- The value of the property in the properties file, or if not found then the defaultValue
-
getPropertyNumber
-
getPropertyValue
Returns the value of the specified property name from the specified resource/properties file- Parameters:
url- URL object specifying the location of the resourcename- The name of the property in the properties file- Returns:
- The value of the property in the properties file
-
getSplitPropertyValue
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 resourcename- The name of the split property in the properties file- Returns:
- The value of the split property from the properties file
-
getMessage
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 URLname- The name of the property in the properties filelocale- The locale that the given resource will correspond to- Returns:
- The value of the property in the properties file
-
getMessage
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 URLname- The name of the property in the properties filelocale- The locale that the given resource will correspond toarguments- An array of Objects to insert into the message argument place holders- Returns:
- The value of the property in the properties file
-
getMessage
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 URLname- The name of the property in the properties filelocale- The locale that the given resource will correspond toarguments- A list of Objects to insert into the message argument place holders- Returns:
- The value of the property in the properties file
-
getResourceBundle
Returns the specified resource/properties file as a ResourceBundle- Parameters:
resource- The name of the resource - can be a file, class, or URLlocale- The locale that the given resource will correspond to- Returns:
- The ResourceBundle
-
getProperties
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 URLlocale- The locale that the given resource will correspond to- Returns:
- The Properties class
-