org.kuali.common.util
Class PropertyUtils

java.lang.Object
  extended by org.kuali.common.util.PropertyUtils

public class PropertyUtils
extends Object

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.


Field Summary
static String ADDITIONAL_LOCATIONS
           
static String ADDITIONAL_LOCATIONS_ENCODING
           
static String RICE_SUFFIX
           
 
Constructor Summary
PropertyUtils()
           
 
Method Summary
static void addListComparisonProperties(Properties properties, ComparisonResults listComparison, List<String> propertyNames)
          Set properties in the given Properties to CSV versions of the lists in the ComparisonResults
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 void appendToOrSetProperty(Properties properties, String key, String 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 void decrypt(Properties properties)
           
static void decrypt(Properties properties, org.jasypt.util.text.TextEncryptor encryptor)
          Decrypt any encrypted property values.
static void decrypt(Properties properties, org.jasypt.util.text.TextEncryptor encryptor, List<String> includes, List<String> excludes)
          Decrypt any encrypted property values matching the includes, excludes patterns.
static String decryptPropertyValue(org.jasypt.util.text.TextEncryptor encryptor, String value)
          Return the decrypted version of the property value.
static Properties duplicate(Properties properties)
          Return a new properties object that duplicates the properties passed in.
static void encrypt(Properties properties, org.jasypt.util.text.TextEncryptor encryptor)
          Encrypt all of the property values.
static void encrypt(Properties properties, org.jasypt.util.text.TextEncryptor encryptor, List<String> includes, List<String> excludes)
          Encrypt properties as dictated by includes and excludes.
static String encryptPropertyValue(org.jasypt.util.text.TextEncryptor encryptor, String value)
          Return the encrypted version of the property value.
static Properties getAdditionalProperties(Properties properties)
           
static Properties getAdditionalProperties(Properties properties, String encoding)
           
protected static String getCanonicalLocation(String location)
           
static Properties getEncryptedProperties(Properties properties)
          Return a new Properties object (never null) containing only those properties whose values are encrypted.
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 String getRequiredResolvedProperty(Properties properties, String key)
           
static String getRequiredResolvedProperty(Properties properties, String key, String defaultValue)
           
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 isEncryptedPropertyValue(String value)
          Return true if the value starts with ENC( and ends with ), false otherwise.
static boolean isRiceProperties(String location)
          Return true if, and only if, location ends with -rice-properties.xml (case insensitive).
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(List<ProjectProperties> pps)
           
static Properties load(List<String> locations, String encoding)
          Return a new Properties object loaded from locations using encoding.
static Properties load(PropertiesContext context)
           
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.
static Properties loadRiceProperties(File file)
          Return a new Properties object loaded from file where the properties are stored in Rice XML style syntax
static Properties loadRiceProperties(String location)
          Return a new Properties object loaded from location where the properties are stored in Rice XML style syntax
protected static boolean obscure(String key)
           
static void overrideWithGlobalValues(Properties properties, GlobalPropertiesMode mode)
           
static void prepareContextProperties(Properties properties)
          Process the properties passed in so they are ready for use by a Spring context.
1 - Override with system/environment properties
2 - Decrypt any ENC(...) values
3 - Resolve all property values throwing an exception if any are unresolvable.
static void prepareContextProperties(Properties properties, String encoding)
          Process the properties passed in so they are ready for use by a Spring context.
1 - Override with system/environment properties
2 - Decrypt any ENC(...) values
3 - Resolve all property values throwing an exception if any are unresolvable.
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 resolve(Properties properties)
           
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.
protected static void validateRiceProperties(String token, String key)
          Make sure they are just loading simple properties and are not using any of the unsupported "features".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RICE_SUFFIX

public static final String RICE_SUFFIX
See Also:
Constant Field Values

ADDITIONAL_LOCATIONS

public static final String ADDITIONAL_LOCATIONS
See Also:
Constant Field Values

ADDITIONAL_LOCATIONS_ENCODING

public static final String ADDITIONAL_LOCATIONS_ENCODING
See Also:
Constant Field Values
Constructor Detail

PropertyUtils

public PropertyUtils()
Method Detail

getRequiredResolvedProperty

public static String getRequiredResolvedProperty(Properties properties,
                                                 String key)

getRequiredResolvedProperty

public static String getRequiredResolvedProperty(Properties properties,
                                                 String key,
                                                 String defaultValue)

prepareContextProperties

public static void prepareContextProperties(Properties properties,
                                            String encoding)
Process the properties passed in so they are ready for use by a Spring context.
1 - Override with system/environment properties
2 - Decrypt any ENC(...) values
3 - Resolve all property values throwing an exception if any are unresolvable.


prepareContextProperties

public static void prepareContextProperties(Properties properties)
Process the properties passed in so they are ready for use by a Spring context.
1 - Override with system/environment properties
2 - Decrypt any ENC(...) values
3 - Resolve all property values throwing an exception if any are unresolvable.


resolve

public static void resolve(Properties properties)

decrypt

public static void decrypt(Properties properties)

getAdditionalProperties

public static Properties getAdditionalProperties(Properties properties)

getAdditionalProperties

public static Properties getAdditionalProperties(Properties properties,
                                                 String encoding)

appendToOrSetProperty

public static void appendToOrSetProperty(Properties properties,
                                         String key,
                                         String value)

load

public static Properties load(List<ProjectProperties> pps)

load

public static Properties load(PropertiesContext context)

decrypt

public static void decrypt(Properties properties,
                           org.jasypt.util.text.TextEncryptor encryptor)
Decrypt any encrypted property values. Encrypted values are surrounded by ENC(...), like:
 my.value = ENC(DGA"$S24FaIO)
 


getEncryptedProperties

public static Properties getEncryptedProperties(Properties properties)
Return a new Properties object (never null) containing only those properties whose values are encrypted. Encrypted values are surrounded by ENC(...), like:
 my.value = ENC(DGA"$S24FaIO)
 


decrypt

public static void decrypt(Properties properties,
                           org.jasypt.util.text.TextEncryptor encryptor,
                           List<String> includes,
                           List<String> excludes)
Decrypt any encrypted property values matching the includes, excludes patterns. Encrypted values are surrounded by ENC(...).
 my.value = ENC(DGA"$S24FaIO)
 


isEncryptedPropertyValue

public static boolean isEncryptedPropertyValue(String value)
Return true if the value starts with ENC( and ends with ), false otherwise.


encrypt

public static void encrypt(Properties properties,
                           org.jasypt.util.text.TextEncryptor encryptor)
Encrypt all of the property values. Encrypted values are surrounded by ENC(...).
 my.value = ENC(DGA"$S24FaIO)
 


encrypt

public static void encrypt(Properties properties,
                           org.jasypt.util.text.TextEncryptor encryptor,
                           List<String> includes,
                           List<String> excludes)
Encrypt properties as dictated by includes and excludes. Encrypted values are surrounded by ENC(...).
 my.value = ENC(DGA"$S24FaIO)
 


decryptPropertyValue

public static String decryptPropertyValue(org.jasypt.util.text.TextEncryptor encryptor,
                                          String value)
Return the decrypted version of the property value. Encrypted values are surrounded by ENC(...).
 my.value = ENC(DGA"$S24FaIO)
 


encryptPropertyValue

public static String encryptPropertyValue(org.jasypt.util.text.TextEncryptor encryptor,
                                          String value)
Return the encrypted version of the property value. A value is considered "encrypted" when it appears surrounded by ENC(...).
 my.value = ENC(DGA"$S24FaIO)
 


overrideWithGlobalValues

public static void overrideWithGlobalValues(Properties properties,
                                            GlobalPropertiesMode mode)

combine

public static final Properties combine(List<Properties> properties)

combine

public static final Properties combine(Properties... properties)

process

public static final void process(Properties properties,
                                 PropertyProcessor processor)

process

public static final void process(Properties properties,
                                 List<PropertyProcessor> processors)

toEmpty

public static final Properties toEmpty(Properties properties)

isSingleUnresolvedPlaceholder

public static final boolean isSingleUnresolvedPlaceholder(String string)

isSingleUnresolvedPlaceholder

public static final boolean isSingleUnresolvedPlaceholder(String string,
                                                          String prefix,
                                                          String suffix)

containsUnresolvedPlaceholder

public static final boolean containsUnresolvedPlaceholder(String string)

containsUnresolvedPlaceholder

public static final boolean containsUnresolvedPlaceholder(String string,
                                                          String prefix,
                                                          String suffix)

getResolvedProperties

public static final Properties getResolvedProperties(Properties properties)
Return a new 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


getResolvedProperties

public static final 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. Using global properties to perform property resolution as indicated by globalPropertiesMode


getResolvedProperties

public static final 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. Using global properties to perform property resolution as indicated by Constants.DEFAULT_GLOBAL_PROPERTIES_MODE


getResolvedProperties

public static final 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. Using global properties to perform property resolution as indicated by globalPropertiesMode


getValues

public static final List<String> getValues(Properties properties,
                                           List<String> keys)
Return the property values from keys


getEndsWithKeys

public static final List<String> getEndsWithKeys(Properties properties,
                                                 String suffix)
Return a sorted List of keys from properties that end with suffix.


trim

public static final void trim(Properties properties,
                              String includesCSV,
                              String excludesCSV)
Alter the properties passed in to contain only the desired property values. includes and excludes are comma separated values.


trim

public static final void trim(Properties properties,
                              List<String> includes,
                              List<String> excludes)
Alter the properties passed in to contain only the desired property values.


include

public static final 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.


isSingleWildcardMatch

public static final boolean isSingleWildcardMatch(String s,
                                                  List<String> patterns)

isSingleWildcardMatch

public static final boolean isSingleWildcardMatch(String value,
                                                  String pattern)
Match 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
 


getProperties

public static final Properties getProperties(Properties properties,
                                             String include,
                                             String exclude)
Return property keys that should be included as a sorted list.


getSortedKeys

public static final List<String> getSortedKeys(Properties properties,
                                               String include,
                                               String exclude)
Return property keys that should be included as a sorted list.


getSortedKeys

public static final List<String> getSortedKeys(Properties properties,
                                               List<String> includes,
                                               List<String> excludes)
Return property keys that should be included as a sorted list.


getStartsWithKeys

public static final List<String> getStartsWithKeys(Properties properties,
                                                   String prefix)
Return a sorted List of keys from properties that start with prefix


getSortedKeys

public static final List<String> getSortedKeys(Properties properties)
Return the property keys as a sorted list.


toString

public static final String toString(Properties properties)

info

public static final void info(Properties properties)

debug

public static final void debug(Properties properties)

store

public static final void store(Properties properties,
                               File file)
Store the properties to the indicated file using the platform default encoding.


store

public static final void store(Properties properties,
                               File file,
                               String encoding)
Store the properties to the indicated file using the indicated encoding.


store

public static final 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.


getGlobalProperties

public static final Properties getGlobalProperties()
Return a new properties object containing the properties from getEnvAsProperties() and System.getProperties(). Properties from System.getProperties() override properties from getEnvAsProperties if there are duplicates.


getGlobalProperties

public static final Properties getGlobalProperties(Properties properties)
Return a new properties object containing the properties passed in, plus any properties returned by getEnvAsProperties() and System.getProperties() . Properties from getEnvAsProperties() override properties and properties from System.getProperties() override everything.


getProperties

public static final Properties getProperties(Properties properties,
                                             GlobalPropertiesMode mode)
Return a new properties object containing the properties passed in, plus any global properties as requested. If 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().


getProperties

public static final Properties getProperties(GlobalPropertiesMode mode)
Return a new properties object containing global properties as requested. If 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.


getProperty

public static final String getProperty(String key,
                                       GlobalPropertiesMode mode)
Search global properties to find a value for key according to the mode passed in.


getProperty

public static final 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. If the property is present in both, the value from the global properties is returned.


getPropertyProcessors

public static final List<PropertyProcessor> getPropertyProcessors(GlobalPropertiesMode mode)
Return modifiers that add environment variables, system properties, or both, according to the mode passed in.


convert

public static final Properties convert(Map<String,String> map)
Convert the Map to a Properties object.


duplicate

public static final Properties duplicate(Properties properties)
Return a new properties object that duplicates the properties passed in.


getEnvAsProperties

public static Properties getEnvAsProperties()
Return a new properties object containing environment variables as properties prefixed with env


getEnvAsProperties

public static Properties getEnvAsProperties(String prefix)
Return a new properties object containing environment variables as properties prefixed with prefix


isXml

public static final boolean isXml(String location)
Return true if, and only if, location ends with .xml (case insensitive).


isRiceProperties

public static final boolean isRiceProperties(String location)
Return true if, and only if, location ends with -rice-properties.xml (case insensitive).


loadRiceProperties

public static final Properties loadRiceProperties(File file)
Return a new Properties object loaded from file where the properties are stored in Rice XML style syntax


loadRiceProperties

public static final Properties loadRiceProperties(String location)
Return a new Properties object loaded from location where the properties are stored in Rice XML style syntax


validateRiceProperties

protected static final void validateRiceProperties(String token,
                                                   String key)
Make sure they are just loading simple properties and are not using any of the unsupported "features". Can't have a key named config.location, and can't use the system, override, or random attributes.


load

public static final Properties load(File file)
Return a new Properties object loaded from file.


load

public static final Properties load(File file,
                                    String encoding)
Return a new Properties object loaded from file using the given encoding.


load

public static final Properties load(String location)
Return a new Properties object loaded from location.


load

public static final Properties load(List<String> locations,
                                    String encoding)
Return a new Properties object loaded from locations using encoding.


load

public static final Properties load(String location,
                                    String encoding)
Return a new Properties object loaded from location using encoding.


getCanonicalLocation

protected static String getCanonicalLocation(String location)

getPrefixedProperties

public static final Properties getPrefixedProperties(Properties properties,
                                                     String prefix)
Return a new Properties object containing properties prefixed with prefix. If prefix is blank, the new properties object duplicates the properties passed in.


reformatKeysAsEnvVars

public static final 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.


addOrOverrideProperty

public static final 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. If there is no existing value, add the property. If there is a conflict, check propertyOverwriteMode to make sure we have permission to override the value.


obscure

protected static boolean obscure(String key)

addListComparisonProperties

public static final void addListComparisonProperties(Properties properties,
                                                     ComparisonResults listComparison,
                                                     List<String> propertyNames)
Set properties in the given Properties to CSV versions of the lists in the ComparisonResults

Parameters:
properties - the Properties to populate
listComparison - the ComparisonResults to use for data
propertyNames - the list of property keys to set. Exactly 3 names are required, and the assumed order is: index 0: key for the ADDED list index 1: key for the SAME list index 2: key for the DELETED list


Copyright © 2010-2013 The Kuali Foundation. All Rights Reserved.