View Javadoc

1   package org.kuali.incubator;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import java.util.List;
6   import java.util.Properties;
7   
8   import org.kuali.ole.utility.ConfigUtil;
9   import org.kuali.ole.utility.Constants;
10  import org.kuali.ole.utility.PropertyUtils;
11  import org.kuali.ole.utility.ResourceUtil;
12  
13  /**
14   * 
15   */
16  public class PropertyUtil {
17  	ResourceUtil resourceUtil = new ResourceUtil();
18  	ConfigUtil configUtil = new ConfigUtil();
19  	private static PropertyUtil propertyUtil = new PropertyUtil();
20  	private static final String DEFAULT_PROPERTIES_FILENAME = "env.properties";
21  	private static final String DEFAULT_PROPERTIES_LOCATION = "classpath:org/kuali/incubator/" + DEFAULT_PROPERTIES_FILENAME;
22  	private static final String SYSTEM_PROPERTY = "ole.solrclient.properties";
23  
24  	public static PropertyUtil getPropertyUtil() {
25  		return propertyUtil;
26  	}
27  
28  	private Properties props;
29  
30  	private PropertyUtil() {
31  		try {
32  			String externalConfigFile = getExternalConfigFile();
33  			List<String> locations = PropertyUtils.getLocations(DEFAULT_PROPERTIES_LOCATION, SYSTEM_PROPERTY, externalConfigFile);
34  			props = PropertyUtils.getAppEnvironmentProperties(locations);
35  		} catch (IOException e) {
36  			throw new IllegalStateException("Exception loading properties", e);
37  		}
38  	}
39  
40  	public String getProperty(String key) {
41  		return props.getProperty(key);
42  	}
43  
44  	public Properties getProperties() {
45  		Properties p = new Properties();
46  		p.putAll(props);
47  		return p;
48  	}
49  
50  	public String getExternalConfigFile() {
51  		StringBuilder sb = new StringBuilder();
52  		sb.append(configUtil.getApplicationHome(Constants.KUALI_GROUP, Constants.OLE_SOLAR_CLIENT));
53  		sb.append(File.separator + "properties" + File.separator);
54  		sb.append(DEFAULT_PROPERTIES_FILENAME);
55  		return sb.toString();
56  	}
57  }