View Javadoc

1   package org.kuali.incubator;
2   
3   import org.slf4j.LoggerFactory;
4   import org.slf4j.Logger;
5   
6   import java.io.File;
7   import java.io.FileInputStream;
8   import java.util.Properties;
9   
10  /**
11   * Created by IntelliJ IDEA.
12   * User: pvsubrah
13   * Date: 4/8/12
14   * Time: 12:56 PM
15   * To change this template use File | Settings | File Templates.
16   */
17  public class PropertyUtil {
18      private static final Logger LOG = LoggerFactory.getLogger(PropertyUtil.class);
19      private static PropertyUtil propertyUtil = new PropertyUtil();
20      private String OLE_PROPERTIES_FILE_NAME = "env.properties";
21      private String environment;
22  
23      public static PropertyUtil getPropertyUtil() {
24          return propertyUtil;
25      }
26  
27      private Properties props;
28  
29      private PropertyUtil() {
30          props = new Properties();
31          try {
32              props.load(getClass().getResourceAsStream(OLE_PROPERTIES_FILE_NAME));
33              String propsDir = System.getProperty("env.properties.home");
34              String fileSeparator = System.getProperty("file.separator");
35              File userPropsFile = new File(propsDir + fileSeparator + OLE_PROPERTIES_FILE_NAME);
36              if (userPropsFile.exists()) {
37                  props.load(new FileInputStream(userPropsFile));
38              }
39          } catch (Exception e) {
40              LOG.error("Unable to load the project.properties file" + e.getMessage());
41          }
42      }
43  
44      public String getProperty(String key) {
45          environment = System.getProperty("app.environment");
46          return props.getProperty(environment + "." + key);
47      }
48  }