|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.kuali.common.util.PropertyUtils
public class PropertyUtils
Simplify handling of Properties
especially as it relates to storing and loading. Properties
can be loaded from
any url Spring resource loading can understand. When storing and loading, locations ending in .xml
are automatically handled
using storeToXML()
and loadFromXML()
, respectively. Properties
are always stored in sorted order
with the encoding
indicated via a comment.
Constructor Summary | |
---|---|
PropertyUtils()
|
Method Summary | |
---|---|
static void |
addOrOverrideProperty(Properties properties,
String key,
String newValue,
Mode propertyOverwriteMode)
Before setting the newValue, check to see if there is a conflict with an existing value. |
static Properties |
combine(List<Properties> properties)
|
static Properties |
combine(Properties... properties)
|
static boolean |
containsUnresolvedPlaceholder(String string)
|
static boolean |
containsUnresolvedPlaceholder(String string,
String prefix,
String suffix)
|
static Properties |
convert(Map<String,String> map)
Convert the Map to a Properties object. |
static void |
debug(Properties properties)
|
static Properties |
duplicate(Properties properties)
Return a new properties object that duplicates the properties passed in. |
static List<String> |
getEndsWithKeys(Properties properties,
String suffix)
Return a sorted List of keys from properties that end with suffix . |
static Properties |
getEnvAsProperties()
Return a new properties object containing environment variables as properties prefixed with env |
static Properties |
getEnvAsProperties(String prefix)
Return a new properties object containing environment variables as properties prefixed with prefix |
static Properties |
getGlobalProperties()
Return a new properties object containing the properties from getEnvAsProperties() and
System.getProperties() . |
static Properties |
getGlobalProperties(Properties properties)
Return a new properties object containing the properties passed in, plus any properties returned by getEnvAsProperties()
and System.getProperties() . |
static Properties |
getPrefixedProperties(Properties properties,
String prefix)
Return a new Properties object containing properties prefixed with prefix . |
static Properties |
getProperties(GlobalPropertiesMode mode)
Return a new properties object containing global properties as requested. |
static Properties |
getProperties(Properties properties,
GlobalPropertiesMode mode)
Return a new properties object containing the properties passed in, plus any global properties as requested. |
static Properties |
getProperties(Properties properties,
String include,
String exclude)
Return property keys that should be included as a sorted list. |
static String |
getProperty(String key,
GlobalPropertiesMode mode)
Search global properties to find a value for key according to the mode passed in. |
static String |
getProperty(String key,
Properties properties,
GlobalPropertiesMode mode)
Search properties plus global properties to find a value for key according to the mode passed in. |
static List<PropertyProcessor> |
getPropertyProcessors(GlobalPropertiesMode mode)
Return modifiers that add environment variables, system properties, or both, according to the mode passed in. |
static Properties |
getResolvedProperties(Properties properties)
Return a new Properties object containing only those properties where the resolved value is different from the original
value. |
static Properties |
getResolvedProperties(Properties properties,
GlobalPropertiesMode globalPropertiesMode)
Return a new Properties object containing only those properties where the resolved value is different from the original
value. |
static Properties |
getResolvedProperties(Properties properties,
org.springframework.util.PropertyPlaceholderHelper helper)
Return a new Properties object containing only those properties where the resolved value is different from the original
value. |
static Properties |
getResolvedProperties(Properties properties,
org.springframework.util.PropertyPlaceholderHelper helper,
GlobalPropertiesMode globalPropertiesMode)
Return a new Properties object containing only those properties where the resolved value is different from the original
value. |
static List<String> |
getSortedKeys(Properties properties)
Return the property keys as a sorted list. |
static List<String> |
getSortedKeys(Properties properties,
List<String> includes,
List<String> excludes)
Return property keys that should be included as a sorted list. |
static List<String> |
getSortedKeys(Properties properties,
String include,
String exclude)
Return property keys that should be included as a sorted list. |
static List<String> |
getStartsWithKeys(Properties properties,
String prefix)
Return a sorted List of keys from properties that start with prefix |
static List<String> |
getValues(Properties properties,
List<String> keys)
Return the property values from keys |
static boolean |
include(String value,
List<String> includes,
List<String> excludes)
Return true if value should be included, false otherwise.If excludes is not empty and matches value return false.If value has not been explicitly excluded, check the includes list.If includes is empty return true.If includes is not empty, return true if, and only if, value matches a pattern from the
includes list.A single wildcard * is supported for includes and excludes . |
static void |
info(Properties properties)
|
static boolean |
isSingleUnresolvedPlaceholder(String string)
|
static boolean |
isSingleUnresolvedPlaceholder(String string,
String prefix,
String suffix)
|
static boolean |
isSingleWildcardMatch(String s,
List<String> patterns)
|
static boolean |
isSingleWildcardMatch(String value,
String pattern)
Match value against pattern where pattern can optionally contain a single wildcard * . |
static boolean |
isXml(String location)
Return true if, and only if, location ends with .xml (case insensitive). |
static Properties |
load(File file)
Return a new Properties object loaded from file . |
static Properties |
load(File file,
String encoding)
Return a new Properties object loaded from file using the given encoding. |
static Properties |
load(String location)
Return a new Properties object loaded from location . |
static Properties |
load(String location,
String encoding)
Return a new Properties object loaded from location using encoding . |
protected static boolean |
obscure(String key)
|
static void |
process(Properties properties,
List<PropertyProcessor> processors)
|
static void |
process(Properties properties,
PropertyProcessor processor)
|
static Properties |
reformatKeysAsEnvVars(Properties properties)
Return a new properties object where the keys have been converted to upper case and periods have been replaced with an underscore. |
static void |
store(Properties properties,
File file)
Store the properties to the indicated file using the platform default encoding. |
static void |
store(Properties properties,
File file,
String encoding)
Store the properties to the indicated file using the indicated encoding. |
static void |
store(Properties properties,
File file,
String encoding,
String comment)
Store the properties to the indicated file using the indicated encoding with the indicated comment appearing at the top of the file. |
static Properties |
toEmpty(Properties properties)
|
static String |
toString(Properties properties)
|
static void |
trim(Properties properties,
List<String> includes,
List<String> excludes)
Alter the properties passed in to contain only the desired property values. |
static void |
trim(Properties properties,
String includesCSV,
String excludesCSV)
Alter the properties passed in to contain only the desired property values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PropertyUtils()
Method Detail |
---|
public static final Properties combine(List<Properties> properties)
public static final Properties combine(Properties... properties)
public static final void process(Properties properties, PropertyProcessor processor)
public static final void process(Properties properties, List<PropertyProcessor> processors)
public static final Properties toEmpty(Properties properties)
public static final boolean isSingleUnresolvedPlaceholder(String string)
public static final boolean isSingleUnresolvedPlaceholder(String string, String prefix, String suffix)
public static final boolean containsUnresolvedPlaceholder(String string)
public static final boolean containsUnresolvedPlaceholder(String string, String prefix, String suffix)
public static final Properties getResolvedProperties(Properties properties)
Properties
object containing only those properties where the resolved value is different from the original
value. Using global properties to perform property resolution as indicated by Constants.DEFAULT_GLOBAL_PROPERTIES_MODE
public static final Properties getResolvedProperties(Properties properties, GlobalPropertiesMode globalPropertiesMode)
Properties
object containing only those properties where the resolved value is different from the original
value. Using global properties to perform property resolution as indicated by globalPropertiesMode
public static final Properties getResolvedProperties(Properties properties, org.springframework.util.PropertyPlaceholderHelper helper)
Properties
object containing only those properties where the resolved value is different from the original
value. Using global properties to perform property resolution as indicated by Constants.DEFAULT_GLOBAL_PROPERTIES_MODE
public static final Properties getResolvedProperties(Properties properties, org.springframework.util.PropertyPlaceholderHelper helper, GlobalPropertiesMode globalPropertiesMode)
Properties
object containing only those properties where the resolved value is different from the original
value. Using global properties to perform property resolution as indicated by globalPropertiesMode
public static final List<String> getValues(Properties properties, List<String> keys)
keys
public static final List<String> getEndsWithKeys(Properties properties, String suffix)
List
of keys from properties
that end with suffix
.
public static final void trim(Properties properties, String includesCSV, String excludesCSV)
properties
passed in to contain only the desired property values. includes
and
excludes
are comma separated values.
public static final void trim(Properties properties, List<String> includes, List<String> excludes)
properties
passed in to contain only the desired property values.
public static final boolean include(String value, List<String> includes, List<String> excludes)
value
should be included, false otherwise.excludes
is not empty and matches value
return false.value
has not been explicitly excluded, check the includes
list.includes
is empty return true.includes
is not empty, return true if, and only if, value
matches a pattern from the
includes
list.*
is supported for includes
and excludes
.
public static final boolean isSingleWildcardMatch(String s, List<String> patterns)
public static final boolean isSingleWildcardMatch(String value, String pattern)
value
against pattern
where pattern
can optionally contain a single wildcard *
. If both are
null
return true
. If one of value
or pattern
is null
but the other isn't, return
false
. Any pattern
containing more than a single wildcard throws IllegalArgumentException
.
PropertyUtils.isSingleWildcardMatch(null, null) = true PropertyUtils.isSingleWildcardMatch(null, *) = false PropertyUtils.isSingleWildcardMatch(*, null) = false PropertyUtils.isSingleWildcardMatch(*, "*") = true PropertyUtils.isSingleWildcardMatch("abcdef", "bcd") = false PropertyUtils.isSingleWildcardMatch("abcdef", "*def") = true PropertyUtils.isSingleWildcardMatch("abcdef", "abc*") = true PropertyUtils.isSingleWildcardMatch("abcdef", "ab*ef") = true PropertyUtils.isSingleWildcardMatch("abcdef", "abc*def") = true PropertyUtils.isSingleWildcardMatch(*, "**") = IllegalArgumentException
public static final Properties getProperties(Properties properties, String include, String exclude)
public static final List<String> getSortedKeys(Properties properties, String include, String exclude)
public static final List<String> getSortedKeys(Properties properties, List<String> includes, List<String> excludes)
public static final List<String> getStartsWithKeys(Properties properties, String prefix)
List
of keys from properties
that start with prefix
public static final List<String> getSortedKeys(Properties properties)
public static final String toString(Properties properties)
public static final void info(Properties properties)
public static final void debug(Properties properties)
public static final void store(Properties properties, File file)
public static final void store(Properties properties, File file, String encoding)
public static final void store(Properties properties, File file, String encoding, String comment)
public static final Properties getGlobalProperties()
getEnvAsProperties()
and
System.getProperties()
. Properties from System.getProperties()
override properties from
getEnvAsProperties
if there are duplicates.
public static final Properties getGlobalProperties(Properties properties)
getEnvAsProperties()
and System.getProperties()
. Properties from getEnvAsProperties()
override properties
and
properties from System.getProperties()
override everything.
public static final Properties getProperties(Properties properties, GlobalPropertiesMode mode)
mode
is
NONE
the new properties are a duplicate of the properties passed in. If mode
is ENVIRONMENT
the new properties contain the original properties plus any properties returned by getEnvProperties()
. If
mode
is SYSTEM
the new properties contain the original properties plus System.getProperties()
.
If mode
is BOTH
the new properties contain the original properties plus getEnvProperties()
and
System.getProperties()
.
public static final Properties getProperties(GlobalPropertiesMode mode)
mode
is NONE
the new
properties are empty. If mode
is ENVIRONMENT
the new properties contain the properties returned by
getEnvProperties()
. If mode
is SYSTEM
the new properties contain
System.getProperties()
. If mode
is BOTH
the new properties contain
getEnvProperties
plus System.getProperties()
with system properties overriding environment variables if the
same case sensitive property key is supplied in both places.
public static final String getProperty(String key, GlobalPropertiesMode mode)
key
according to the mode passed in.
public static final String getProperty(String key, Properties properties, GlobalPropertiesMode mode)
properties
plus global properties to find a value for key
according to the mode passed in. If the
property is present in both, the value from the global properties is returned.
public static final List<PropertyProcessor> getPropertyProcessors(GlobalPropertiesMode mode)
public static final Properties convert(Map<String,String> map)
Map
to a Properties
object.
public static final Properties duplicate(Properties properties)
public static Properties getEnvAsProperties()
env
public static Properties getEnvAsProperties(String prefix)
prefix
public static final boolean isXml(String location)
.xml
(case insensitive).
public static final Properties load(File file)
Properties
object loaded from file
.
public static final Properties load(File file, String encoding)
Properties
object loaded from file
using the given encoding.
public static final Properties load(String location)
Properties
object loaded from location
.
public static final Properties load(String location, String encoding)
Properties
object loaded from location
using encoding
.
public static final Properties getPrefixedProperties(Properties properties, String prefix)
Properties
object containing properties prefixed with prefix
. If prefix
is blank,
the new properties object duplicates the properties passed in.
public static final Properties reformatKeysAsEnvVars(Properties properties)
public static final void addOrOverrideProperty(Properties properties, String key, String newValue, Mode propertyOverwriteMode)
propertyOverwriteMode
to make sure we have permission to override the value.
protected static boolean obscure(String key)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |