org.ops4j.util.collections
Class PropertiesUtils

java.lang.Object
  extended by org.ops4j.util.collections.PropertiesUtils

public final class PropertiesUtils
extends Object

Utility class supporting operations related to property retrival.


Method Summary
static String getProperty(Properties props, String key, String def)
          Return the value of a property.
static String[] readListFile(URL listFile)
          Read a file and return the list of lines in an array of strings.
static Properties readProperties(InputStream stream, Properties mappings, boolean closeStream)
          Read a set of properties from a property file provided as an Inputstream.
static Properties readProps(URL propsUrl, Properties mappings)
          Read a set of properties from a property file specificed by a url.
static String resolveProperty(Properties props, String value)
          Resolve symbols in a supplied value against supplied known properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readProps

public static Properties readProps(URL propsUrl,
                                   Properties mappings)
                            throws IOException
Read a set of properties from a property file specificed by a url.

Parameters:
propsUrl - the url of the property file to read
mappings - Properties that will be available for translations initially.
Returns:
the resolved properties
Throws:
IOException - if an io error occurs
See Also:
readProperties(java.io.InputStream,java.util.Properties,boolean)

readProperties

public static Properties readProperties(InputStream stream,
                                        Properties mappings,
                                        boolean closeStream)
                                 throws IOException
Read a set of properties from a property file provided as an Inputstream.

Property files may reference symbolic properties in the form ${name}. Translations occur from both the mappings properties as well as all values within the Properties that are being read.

Example;

   Properties mappings = System.getProperties();
   Properties myProps = PropertiesUtils.readProperties( "mine.properties", mappings );
 

and the "mine.properties" file contains;

 mything=${myplace}/mything
 myplace=${user.home}/myplace
 

then the Properties object myProps will contain;

 mything=/home/niclas/myplace/mything
 myplace=/home/niclas/myplace
 

Parameters:
stream - the InputStream of the property file to read.
mappings - Properties that will be available for translations initially.
closeStream - true if the method should close the stream before returning, false otherwise.
Returns:
the resolved properties.
Throws:
IOException - if an io error occurs

resolveProperty

public static String resolveProperty(Properties props,
                                     String value)
Resolve symbols in a supplied value against supplied known properties.

Parameters:
props - a set of know properties
value - the string to parse for tokens
Returns:
the resolved string

getProperty

public static String getProperty(Properties props,
                                 String key,
                                 String def)
Return the value of a property.

Parameters:
props - the property file
key - the property key to lookup
def - the default value
Returns:
the resolve value

readListFile

public static String[] readListFile(URL listFile)
                             throws IOException
Read a file and return the list of lines in an array of strings.

Parameters:
listFile - the url to read from
Returns:
the lines
Throws:
IOException - if a read error occurs


Copyright © 2006-2013 OPS4J - Open Participation Software for Java. All Rights Reserved.