|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ofbiz.base.util.UtilProperties
public class UtilProperties
Generic Property Accessor with Cache - Utilities for working with properties files.
UtilProperties divides properties files into two classes: non-locale-specific - which are used for application parameters, configuration settings, etc; and locale-specific - which are used for UI labels, system messages, etc. Each class of properties files is kept in its own cache.
The locale-specific class of properties files can be in any one of three formats: the standard text-based key=value format (*.properties file), the Java XML properties format, and the OFBiz-specific XML file format (see the xmlToProperties method).
Nested Class Summary | |
---|---|
static class |
UtilProperties.ExtendedProperties
Custom Properties class. |
static class |
UtilProperties.UtilResourceBundle
Custom ResourceBundle class. |
Field Summary | |
---|---|
protected static java.util.Set<java.util.Locale> |
defaultCandidateLocales
|
protected static java.util.Locale |
fallbackLocale
|
static java.util.Locale |
LOCALE_ROOT
|
static java.lang.String |
module
|
protected static java.util.Set<java.lang.String> |
propertiesNotFound
|
protected static UtilCache<java.lang.String,java.util.Properties> |
resourceCache
An instance of the generic cache for storing the non-locale-specific properties. |
protected static java.util.Set<java.lang.String> |
resourceNotFoundMessagesShown
|
protected static UtilCache<java.lang.String,java.util.Properties> |
urlCache
An instance of the generic cache for storing the non-locale-specific properties. |
Constructor Summary | |
---|---|
UtilProperties()
|
Method Summary | |
---|---|
static java.lang.String |
createResourceName(java.lang.String resource,
java.util.Locale locale,
boolean removeExtension)
Create a localized resource name based on a resource name and a locale. |
static java.util.List<java.util.Locale> |
getCandidateLocales(java.util.Locale locale)
Returns a list of candidate locales based on a supplied locale. |
static java.util.Set<java.util.Locale> |
getDefaultCandidateLocales()
Returns the default candidate Locale list. |
static java.util.Locale |
getFallbackLocale()
Returns the configured fallback locale. |
static java.lang.String |
getMessage(java.lang.String resource,
java.lang.String name,
java.util.List arguments,
java.util.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 class |
static java.lang.String |
getMessage(java.lang.String resource,
java.lang.String name,
java.util.Locale locale)
Returns the value of the specified property name from the specified resource/properties file corresponding to the given locale. |
static java.lang.String |
getMessage(java.lang.String resource,
java.lang.String name,
java.util.Map<java.lang.String,? extends java.lang.Object> context,
java.util.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 FlexibleStringExpander class |
static java.lang.String |
getMessage(java.lang.String resource,
java.lang.String name,
java.lang.Object[] arguments,
java.util.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 class |
static java.lang.String |
getMessageList(java.lang.String resource,
java.lang.String name,
java.util.Locale locale,
java.lang.Object... arguments)
|
static java.lang.String |
getMessageMap(java.lang.String resource,
java.lang.String name,
java.util.Locale locale,
java.lang.Object... context)
|
static java.util.Properties |
getProperties(java.lang.String resource)
Returns the specified resource/properties file |
static java.util.Properties |
getProperties(java.lang.String resource,
java.util.Locale locale)
Returns the specified resource/properties file. |
static java.util.Properties |
getProperties(java.net.URL url)
Returns the specified resource/properties file |
static double |
getPropertyNumber(java.lang.String resource,
java.lang.String name)
|
static double |
getPropertyNumber(java.net.URL url,
java.lang.String name)
|
static java.lang.String |
getPropertyValue(java.lang.String resource,
java.lang.String name)
Returns the value of the specified property name from the specified resource/properties file |
static java.lang.String |
getPropertyValue(java.lang.String resource,
java.lang.String name,
java.lang.String defaultValue)
Returns the value of the specified property name from the specified resource/properties file. |
static java.lang.String |
getPropertyValue(java.net.URL url,
java.lang.String name)
Returns the value of the specified property name from the specified resource/properties file |
static java.lang.String |
getPropertyValue(java.net.URL url,
java.lang.String name,
java.lang.String defaultValue)
Returns the value of the specified property name from the specified resource/properties file. |
static java.util.ResourceBundle |
getResourceBundle(java.lang.String resource,
java.util.Locale locale)
Returns the specified resource/properties file as a ResourceBundle |
static ResourceBundleMapWrapper |
getResourceBundleMap(java.lang.String resource,
java.util.Locale locale)
Returns the specified resource/properties file as a Map with the original ResourceBundle in the Map under the key _RESOURCE_BUNDLE_ |
static ResourceBundleMapWrapper |
getResourceBundleMap(java.lang.String resource,
java.util.Locale locale,
java.util.Map<java.lang.String,java.lang.Object> context)
Returns the specified resource/properties file as a Map with the original ResourceBundle in the Map under the key _RESOURCE_BUNDLE_ |
static java.lang.String |
getSplitPropertyValue(java.net.URL url,
java.lang.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 boolean |
isPropertiesResourceNotFound(java.lang.String resource,
java.util.Locale locale,
boolean removeExtension)
|
static java.util.List<java.util.Locale> |
localeToCandidateList(java.util.Locale locale)
Converts a Locale instance to a candidate Locale list. |
static boolean |
propertyValueEquals(java.lang.String resource,
java.lang.String name,
java.lang.String compareString)
Compares the specified property to the compareString, returns true if they are the same, false otherwise |
static boolean |
propertyValueEquals(java.net.URL url,
java.lang.String name,
java.lang.String compareString)
Compares the specified property to the compareString, returns true if they are the same, false otherwise |
static boolean |
propertyValueEqualsIgnoreCase(java.lang.String resource,
java.lang.String name,
java.lang.String compareString)
Compares Ignoring Case the specified property to the compareString, returns true if they are the same, false otherwise |
static boolean |
propertyValueEqualsIgnoreCase(java.net.URL url,
java.lang.String name,
java.lang.String compareString)
Compares Ignoring Case the specified property to the compareString, returns true if they are the same, false otherwise |
static java.net.URL |
resolvePropertiesUrl(java.lang.String resource,
java.util.Locale locale)
Resolve a properties file URL. |
static void |
setPropertyValue(java.lang.String resource,
java.lang.String name,
java.lang.String value)
Sets the specified value of the specified property name to the specified resource/properties file |
static java.util.Properties |
xmlToProperties(java.io.InputStream in,
java.util.Locale locale,
java.util.Properties properties)
Convert XML property file to Properties instance. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String module
protected static UtilCache<java.lang.String,java.util.Properties> resourceCache
protected static UtilCache<java.lang.String,java.util.Properties> urlCache
public static final java.util.Locale LOCALE_ROOT
protected static java.util.Locale fallbackLocale
protected static java.util.Set<java.util.Locale> defaultCandidateLocales
protected static java.util.Set<java.lang.String> propertiesNotFound
protected static java.util.Set<java.lang.String> resourceNotFoundMessagesShown
Constructor Detail |
---|
public UtilProperties()
Method Detail |
---|
public static boolean propertyValueEquals(java.lang.String resource, java.lang.String name, java.lang.String compareString)
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
public static boolean propertyValueEqualsIgnoreCase(java.lang.String resource, java.lang.String name, java.lang.String compareString)
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
public static java.lang.String getPropertyValue(java.lang.String resource, java.lang.String name, java.lang.String defaultValue)
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
public static double getPropertyNumber(java.lang.String resource, java.lang.String name)
public static java.lang.String getPropertyValue(java.lang.String resource, java.lang.String name)
resource
- The name of the resource - can be a file, class, or URLname
- The name of the property in the properties file
public static java.util.Properties getProperties(java.lang.String resource)
resource
- The name of the resource - can be a file, class, or URL
public static java.util.Properties getProperties(java.net.URL url)
url
- The URL to the resource
public static boolean propertyValueEquals(java.net.URL url, java.lang.String name, java.lang.String compareString)
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
public static boolean propertyValueEqualsIgnoreCase(java.net.URL url, java.lang.String name, java.lang.String compareString)
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
public static java.lang.String getPropertyValue(java.net.URL url, java.lang.String name, java.lang.String defaultValue)
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
public static double getPropertyNumber(java.net.URL url, java.lang.String name)
public static java.lang.String getPropertyValue(java.net.URL url, java.lang.String name)
url
- URL object specifying the location of the resourcename
- The name of the property in the properties file
public static java.lang.String getSplitPropertyValue(java.net.URL url, java.lang.String name)
url
- URL object specifying the location of the resourcename
- The name of the split property in the properties file
public static void setPropertyValue(java.lang.String resource, java.lang.String name, java.lang.String value)
resource
- The name of the resource - must be a filename
- The name of the property in the properties filevalue
- The value of the property in the properties filepublic static java.lang.String getMessage(java.lang.String resource, java.lang.String name, java.util.Locale locale)
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
public static java.lang.String getMessage(java.lang.String resource, java.lang.String name, java.lang.Object[] arguments, java.util.Locale locale)
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
public static java.lang.String getMessage(java.lang.String resource, java.lang.String name, java.util.List arguments, java.util.Locale locale)
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
public static java.lang.String getMessageList(java.lang.String resource, java.lang.String name, java.util.Locale locale, java.lang.Object... arguments)
public static java.lang.String getMessage(java.lang.String resource, java.lang.String name, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Locale locale)
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 tocontext
- A Map of Objects to insert into the message place holders using the ${} syntax of the FlexibleStringExpander
public static java.lang.String getMessageMap(java.lang.String resource, java.lang.String name, java.util.Locale locale, java.lang.Object... context)
public static java.util.ResourceBundle getResourceBundle(java.lang.String resource, java.util.Locale locale)
resource
- The name of the resource - can be a file, class, or URLlocale
- The locale that the given resource will correspond to
public static ResourceBundleMapWrapper getResourceBundleMap(java.lang.String resource, java.util.Locale locale)
resource
- The name of the resource - can be a file, class, or URLlocale
- The locale that the given resource will correspond to
public static ResourceBundleMapWrapper getResourceBundleMap(java.lang.String resource, java.util.Locale locale, java.util.Map<java.lang.String,java.lang.Object> context)
resource
- The name of the resource - can be a file, class, or URLlocale
- The locale that the given resource will correspond tocontext
- The screen rendering context
public static java.util.Properties getProperties(java.lang.String resource, java.util.Locale locale)
Note that this method will return a Properties instance for the specified locale only - if you need I18n properties, then use getResourceBundle(String resource, Locale locale). This method is intended to be used primarily by the UtilProperties class.
resource
- The name of the resource - can be a file, class, or URLlocale
- The desired locale
public static java.util.Locale getFallbackLocale()
The fallback locale can be
configured using the locale.properties.fallback
property in
general.properties
.
public static java.util.List<java.util.Locale> localeToCandidateList(java.util.Locale locale)
localeToCandidateList(Locale.US)
would return
a list containing en_US
and en
.
public static java.util.Set<java.util.Locale> getDefaultCandidateLocales()
LOCALE_ROOT
(empty) locale - in that order.
public static java.util.List<java.util.Locale> getCandidateLocales(java.util.Locale locale)
locale
- The desired locale
public static java.lang.String createResourceName(java.lang.String resource, java.util.Locale locale, boolean removeExtension)
resource
- The desired resourcelocale
- The desired localeremoveExtension
- Remove file extension from resource String
public static boolean isPropertiesResourceNotFound(java.lang.String resource, java.util.Locale locale, boolean removeExtension)
public static java.net.URL resolvePropertiesUrl(java.lang.String resource, java.util.Locale locale)
This method uses the following strategy:
resource (MyProps.xml)
resource
and ends with the locale's string and
.xml (MyProps_en.xml)
resource
and ends with the locale's string and
.properties (MyProps_en.properties)
resource and ends with the locale's string (MyProps_en)
component://
protocol is supported in the
resource
parameter.
resource
- The resource to resolvelocale
- The desired locale
public static java.util.Properties xmlToProperties(java.io.InputStream in, java.util.Locale locale, java.util.Properties properties) throws java.io.IOException, java.util.InvalidPropertiesFormatException
The format of the custom XML properties file is:
<resource>
where "locale 1", "locale 2" are valid Locale strings.
<property key="key">
<value xml:lang="locale 1">Some value</value>
<value xml:lang="locale 2">Some value</value>
...
</property>
...
</resource>
in
- XML file InputStreamlocale
- The desired localeproperties
- Optional Properties object to populate
java.io.IOException
java.util.InvalidPropertiesFormatException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |