001    package org.kuali.incubator;
002    
003    import java.io.File;
004    import java.io.IOException;
005    import java.util.List;
006    import java.util.Properties;
007    
008    import org.kuali.ole.utility.ConfigUtil;
009    import org.kuali.ole.utility.Constants;
010    import org.kuali.ole.utility.PropertyUtils;
011    import org.kuali.ole.utility.ResourceUtil;
012    
013    /**
014     * 
015     */
016    public class PropertyUtil {
017            ResourceUtil resourceUtil = new ResourceUtil();
018            ConfigUtil configUtil = new ConfigUtil();
019            private static PropertyUtil propertyUtil = new PropertyUtil();
020            private static final String DEFAULT_PROPERTIES_FILENAME = "env.properties";
021            private static final String DEFAULT_PROPERTIES_LOCATION = "classpath:org/kuali/incubator/" + DEFAULT_PROPERTIES_FILENAME;
022            private static final String SYSTEM_PROPERTY = "ole.solrclient.properties";
023    
024            public static PropertyUtil getPropertyUtil() {
025                    return propertyUtil;
026            }
027    
028            private Properties props;
029    
030            private PropertyUtil() {
031                    try {
032                            String externalConfigFile = getExternalConfigFile();
033                            List<String> locations = PropertyUtils.getLocations(DEFAULT_PROPERTIES_LOCATION, SYSTEM_PROPERTY, externalConfigFile);
034                            props = PropertyUtils.getAppEnvironmentProperties(locations);
035                    } catch (IOException e) {
036                            throw new IllegalStateException("Exception loading properties", e);
037                    }
038            }
039    
040            public String getProperty(String key) {
041                    return props.getProperty(key);
042            }
043    
044            public Properties getProperties() {
045                    Properties p = new Properties();
046                    p.putAll(props);
047                    return p;
048            }
049    
050            public String getExternalConfigFile() {
051                    StringBuilder sb = new StringBuilder();
052                    sb.append(configUtil.getApplicationHome(Constants.KUALI_GROUP, Constants.OLE_SOLAR_CLIENT));
053                    sb.append(File.separator + "properties" + File.separator);
054                    sb.append(DEFAULT_PROPERTIES_FILENAME);
055                    return sb.toString();
056            }
057    }