com.ebmwebsourcing.easycommons.properties
Class PropertiesHelper

java.lang.Object
  extended by com.ebmwebsourcing.easycommons.properties.PropertiesHelper

public final class PropertiesHelper
extends java.lang.Object

Utility to handle a CDK properties file.


Constructor Summary
PropertiesHelper()
           
 
Method Summary
static boolean containsPlaceHolder(java.lang.String str)
          Test if the specified string contains at least one place holder
static java.util.Properties flattenProperties(java.util.Properties properties)
          Get a flat view of a Properties object including recursively, default properties if any.
static java.lang.String[] parsePropertyValues(java.lang.String propValue)
          Parse the values of a property.
static void resolveMap(java.util.Map<java.lang.String,java.lang.String> mapToResolve, java.util.Properties propertiesToUse)
          Resolve the place holders in the values of the specified Map mapToResolve against the specified Properties propertiesToUse.
static void resolveMapWithNoException(java.util.Map<java.lang.String,java.lang.String> mapToResolve, java.util.Properties propertiesToUse)
          Resolve the place holders in the values of the specified Map mapToResolve against the specified Properties propertiesToUse.
static void resolveProperties(java.util.Properties propertiesToResolve, java.util.Properties propertiesToUse)
          Resolve the specified Properties propertiesToResolve against the specified Properties propertiesToUse.
static java.io.ByteArrayInputStream resolvePropertiesForInputStream(java.io.InputStream inputStreamToResolve, java.util.Properties propertiesToUse)
          Resolve the place holders in the values of the specified InputStream inputStreamToResolve against the specified Properties propertiesToUse.
static java.lang.String resolveString(java.lang.String str, java.util.Properties propertiesToUse)
          Replace the place holders by their values in the specified string str.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiesHelper

public PropertiesHelper()
Method Detail

resolveProperties

public static final void resolveProperties(java.util.Properties propertiesToResolve,
                                           java.util.Properties propertiesToUse)
                                    throws PropertiesException
Resolve the specified Properties propertiesToResolve against the specified Properties propertiesToUse. If the place holders of a property value cannot be resolved, the place holders are not replaced in the resulting resulting value.

Parameters:
propertiesToResolve - the Properties to resolve (which contain place holders)
propertiesToUse - the Properties to use to resolve
Throws:
PropertiesException - if an error occurs when resolving the Properties (if there is a place holder loop in the specified Properties)

resolvePropertiesForInputStream

public static final java.io.ByteArrayInputStream resolvePropertiesForInputStream(java.io.InputStream inputStreamToResolve,
                                                                                 java.util.Properties propertiesToUse)
                                                                          throws PropertiesException,
                                                                                 java.io.IOException
Resolve the place holders in the values of the specified InputStream inputStreamToResolve against the specified Properties propertiesToUse. If the place holders of a property value cannot be resolved, the place holders are not replaced in the resulting resulting value.

Parameters:
inputStreamToResolve - the InputStream containing properties value with place holders to resolve
propertiesToUse - the Properties to use to resolve
Throws:
PropertiesException - if an error occurs when resolving the Properties (if there is a place holder loop in the specified Properties)
java.io.IOException - if an error occurred when reading from the specified input stream or if writing this resolved property list to the specified output stream throws an IOException.

resolveMapWithNoException

public static final void resolveMapWithNoException(java.util.Map<java.lang.String,java.lang.String> mapToResolve,
                                                   java.util.Properties propertiesToUse)
Resolve the place holders in the values of the specified Map mapToResolve against the specified Properties propertiesToUse. If the resolution of place holders fails, the string value is not modified in the map.

Parameters:
mapToResolve - the Map containing string value with place holders to resolve
propertiesToUse - the Properties to use to resolve

resolveMap

public static final void resolveMap(java.util.Map<java.lang.String,java.lang.String> mapToResolve,
                                    java.util.Properties propertiesToUse)
                             throws PropertiesException
Resolve the place holders in the values of the specified Map mapToResolve against the specified Properties propertiesToUse. If the place holders of a string value cannot be resolved, the place holders are not replaced in the resulting string (only the resolved place holders are replaced, not the others).

Parameters:
mapToResolve - the Map containing string value with place holders to resolve
propertiesToUse - the Properties to use to resolve
Throws:
PropertiesException - if an error occurs when resolving the Properties (if there is a place holder loop in the specified Properties)

resolveString

public static final java.lang.String resolveString(java.lang.String str,
                                                   java.util.Properties propertiesToUse)
                                            throws PropertiesException
Replace the place holders by their values in the specified string str. If place holders of the string str cannot be resolved, they are not replaced in the resulting string.

Parameters:
str - a string containing place holders
propertiesToUse - the Properties to resolve (which contains place holders)
Returns:
the string where the place holders have been replaced by their values (the places holders which cannot be resolved are still present in the resulting string)
Throws:
PropertiesException - if an error occurs when resolving a place holder (if there is a place holder loop in the specified Properties)

containsPlaceHolder

public static final boolean containsPlaceHolder(java.lang.String str)
Test if the specified string contains at least one place holder

Parameters:
str - a string
Returns:
true if the specified string contains at least one place holder

flattenProperties

public static final java.util.Properties flattenProperties(java.util.Properties properties)
Get a flat view of a Properties object including recursively, default properties if any.

Parameters:
properties - Properties to consider.
Returns:
Flatten properties.

parsePropertyValues

public static java.lang.String[] parsePropertyValues(java.lang.String propValue)
Parse the values of a property. Delimiter are whitespace or comma character.

Parameters:
propValue -
Returns:
an array of string containing the extracted values.


Copyright © 2011 Petals Link. All Rights Reserved.