1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.utility;
17
18 import static org.apache.commons.lang.StringUtils.isBlank;
19
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23
24
25
26
27 public class ConfigUtil {
28 private static final Logger logger = LoggerFactory.getLogger(ConfigUtil.class);
29
30 public static final String KUALI_HOME_SYSTEM_PROPERTY = "kuali.home";
31 public static final String KUALI_HOME_ENVIRONMENT_VAR = "KUALI_HOME";
32 public static final String KUALI_HOME_DEFAULT_VALUE = System.getProperty("user.home") + "/.kuali";
33
34
35
36
37
38
39
40
41 public String getKualiHome() {
42 String kualiHome = getValue(KUALI_HOME_SYSTEM_PROPERTY, KUALI_HOME_ENVIRONMENT_VAR, KUALI_HOME_DEFAULT_VALUE);
43 String systemProperty = System.getProperty(KUALI_HOME_SYSTEM_PROPERTY);
44 if (!kualiHome.equals(systemProperty)) {
45 logger.info("Setting " + KUALI_HOME_SYSTEM_PROPERTY + "=" + kualiHome);
46 System.setProperty(KUALI_HOME_SYSTEM_PROPERTY, kualiHome);
47 }
48 return kualiHome;
49 }
50
51 public String getGroupHome(String group) {
52 return getKualiHome() + "/" + group;
53 }
54
55 public String getApplicationHome(String group, String application) {
56 return getGroupHome(group) + "/" + application;
57 }
58
59
60
61
62
63
64
65
66
67
68 public String getValue(String systemProperty, String environmentVariable, String defaultValue) {
69 if (!isBlank(systemProperty) && !isBlank(System.getProperty(systemProperty))) {
70 return System.getProperty(systemProperty);
71 } else if (!isBlank(environmentVariable) && !isBlank(System.getenv(environmentVariable))) {
72 return System.getenv(environmentVariable);
73 } else {
74 return defaultValue;
75 }
76 }
77 }