1 package org.kuali.ole;
2
3
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
6
7 import java.io.File;
8 import java.io.FileInputStream;
9 import java.io.IOException;
10 import java.util.Properties;
11
12
13
14
15
16
17
18
19 public class PropertyUtil {
20 private static Logger LOG = LoggerFactory.getLogger(PropertyUtil.class);
21 private static PropertyUtil propertyUtil = new PropertyUtil();
22 private String OLE_SRU_PROPERTIES_FILE_NAME = "OleSRUResource.properties";
23 private String environment;
24
25 public static PropertyUtil getPropertyUtil() {
26 return propertyUtil;
27 }
28
29 private Properties props;
30
31 private PropertyUtil() {
32 props = new Properties();
33 try {
34 props.load(getClass().getResourceAsStream(OLE_SRU_PROPERTIES_FILE_NAME));
35 } catch (Exception e) {
36 LOG.error("Unable to load the project.properties file" + e.getMessage());
37 LOG.info("Going to attempt to load from the locations set for env.properties.home");
38 }
39 String propsDir = System.getProperty("env.properties.home");
40 String fileSeparator = System.getProperty("file.separator");
41 File userPropsFile = new File(propsDir + fileSeparator + OLE_SRU_PROPERTIES_FILE_NAME);
42 if (userPropsFile.exists()) {
43 try {
44 props.load(new FileInputStream(userPropsFile));
45 } catch (IOException e) {
46 LOG.error(e.getMessage());
47 }
48 }
49 }
50
51 public String getProperty(String key) {
52 environment = System.getProperty("app.environment");
53 String propValue=props.getProperty(environment+"."+key);
54 if(propValue==null || "".equals(propValue))
55 propValue= props.getProperty(key);
56 return propValue;
57 }
58
59 }