Thursday, July 19, 2007

apache commons configurator usage

commons configurator usage:
Download the below jars from apache site:
commons-collections-3.2.jar  application/octet-stream
commons-configuration-1.4.jar  application/octet-stream
commons-lang-2.3.jar  application/octet-stream

Usage of org.apache.commons.configuration class for dynamic property file reading is below:


 static PropertiesConfiguration config = null;
public void init(FilterConfig filterConfig) throws ServletException
{

try
{
 config = new PropertiesConfiguration(filterConfig.getInitParameter("ROBOT_FILE"));
 FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
 reloadingStrategy.setRefreshDelay(1000 * 60 * 5);// 5 mins

 config.setReloadingStrategy(reloadingStrategy);
List patternsList = (List) config.getProperty("patterns");

} catch (ConfigurationException e)
{
 log.error(e);
}

}

By default the char seperator is "," and the list is automatically created.
Cool isnt it.


commons digester usage:

QuizResultsTO result = null; try { digester.addObjectCreate("quiz", "com.biomedcentral.business.imagelibrary.model.quiz.QuizResultsTO"); digester.addCallMethod("quiz/title", "setQuizTitle", 0); result = (QuizResultsTO) digester.parse(file); } catch (Exception e) { logger.error("Quiz configuration file not parseable", e); throw new TechnicalException(e); } return result.getQuizTitle();

No comments: