org.kuali.student.common.util
Class PropertiesFactory

java.lang.Object
  extended by org.kuali.student.common.util.PropertiesFactory

public class PropertiesFactory
extends Object

A really freaking simple properties filter that returns a properties map for a subset of a properties file. Give this method the file name of the properties file, and then give it the prefix to filter on. The prefix gets a "." appended to it on filtering.

For example, if the properties are:

Then filtering on "prop1" returns a map with values:

Author:
Kuali Student Team (ks.team2@kuali.org)

Field Summary
(package private)  Properties properties
           
 
Constructor Summary
PropertiesFactory(File file)
          This constructs a PropertiesFactory.
PropertiesFactory(InputStream in)
          This constructs a PropertiesFactory.
PropertiesFactory(String filename)
          This constructs a PropertiesFactory.
 
Method Summary
 Map<Object,Object> getProperties(String prefix)
          This method filters the properties based on the prefix given as described above.
static Map<Object,Object> getProperties(String filename, String prefix)
          A static version of the properties filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

Properties properties
Constructor Detail

PropertiesFactory

public PropertiesFactory(String filename)
                  throws IOException
This constructs a PropertiesFactory.

Parameters:
filename - the filename of the properties file as determined by ClassLoader.getSystemResource(String).
Throws:
IOException

PropertiesFactory

public PropertiesFactory(File file)
                  throws FileNotFoundException,
                         IOException
This constructs a PropertiesFactory.

Parameters:
file - the properties file
Throws:
FileNotFoundException
IOException

PropertiesFactory

public PropertiesFactory(InputStream in)
                  throws IOException
This constructs a PropertiesFactory.

Parameters:
in - an InputStream to read the properties from
Throws:
IOException
Method Detail

getProperties

public Map<Object,Object> getProperties(String prefix)
This method filters the properties based on the prefix given as described above. The prefix will be appended with a "." delimiter and the returned values will not have either the prefix or the delimiter.

Parameters:
prefix - the prefix to filter on
Returns:
a map of the properties minus their prefix. This list is really String,Object, oh well.

getProperties

public static Map<Object,Object> getProperties(String filename,
                                               String prefix)
                                        throws IOException
A static version of the properties filter.
     <bean id="test" class="org.kuali.student.common.util.PropertiesFactory" factory-method="getProperties" >
         <constructor-arg value="file.properties"/>
         <constructor-arg value="prefix1"/>
     </bean>
 

Parameters:
filename -
prefix - the prefix to filter on
Returns:
a map of the properties minus their prefix. This list is really String,Object, oh well.
Throws:
IOException


Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.