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.


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

PropertyUtils

public PropertyUtils()
Method Detail

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).


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(String location,
                                    String encoding)
Return a new Properties object loaded from location using encoding.


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)


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