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