001 package org.kuali.incubator; 002 003 import org.slf4j.LoggerFactory; 004 import org.slf4j.Logger; 005 006 import java.io.File; 007 import java.io.FileInputStream; 008 import java.util.Properties; 009 010 /** 011 * Created by IntelliJ IDEA. 012 * User: pvsubrah 013 * Date: 4/8/12 014 * Time: 12:56 PM 015 * To change this template use File | Settings | File Templates. 016 */ 017 public class PropertyUtil { 018 private static final Logger LOG = LoggerFactory.getLogger(PropertyUtil.class); 019 private static PropertyUtil propertyUtil = new PropertyUtil(); 020 private String OLE_PROPERTIES_FILE_NAME = "env.properties"; 021 private String environment; 022 023 public static PropertyUtil getPropertyUtil() { 024 return propertyUtil; 025 } 026 027 private Properties props; 028 029 private PropertyUtil() { 030 props = new Properties(); 031 try { 032 props.load(getClass().getResourceAsStream(OLE_PROPERTIES_FILE_NAME)); 033 String propsDir = System.getProperty("env.properties.home"); 034 String fileSeparator = System.getProperty("file.separator"); 035 File userPropsFile = new File(propsDir + fileSeparator + OLE_PROPERTIES_FILE_NAME); 036 if (userPropsFile.exists()) { 037 props.load(new FileInputStream(userPropsFile)); 038 } 039 } catch (Exception e) { 040 LOG.error("Unable to load the project.properties file" + e.getMessage()); 041 } 042 } 043 044 public String getProperty(String key) { 045 environment = System.getProperty("app.environment"); 046 return props.getProperty(environment + "." + key); 047 } 048 }