1 5 package com.jofti.util; 6 7 import java.io.InputStream ; 8 import java.util.Properties ; 9 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 13 import com.jofti.exception.JoftiException; 14 15 21 public class PropertyLoader { 22 23 private static Log log = LogFactory.getLog(PropertyLoader.class); 24 25 public static Properties loadProperties(String fileName) throws JoftiException{ 26 27 InputStream in =null; 28 Properties props =new Properties (); 29 try { 30 if(log.isDebugEnabled()) 31 log.debug("Getting Config"); 32 log.info("Getting stream for " + fileName); 33 in = PropertyLoader.class.getResourceAsStream(fileName); 34 if (in ==null){ 35 throw new JoftiException("Unable to find "+ fileName+ " ensure file is on classpath "); 36 } 37 log.info("Got stream for " + fileName); 38 39 props.load(in); 40 41 } catch(Exception e){ 42 log.error("Error loading "+ fileName+ " ensure file is on classpath " + e); 43 throw new JoftiException(e); 44 } finally{ 45 try 46 { 47 if (in != null){ 48 in.close(); 49 } 50 } catch (Exception e){ 51 log.error("Error closing input stream for property load " + e); 52 } 53 } 54 return props; 55 } 56 } 57 | Popular Tags |