| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.core.impl.config.property; |
| 18 | |
|
| 19 | |
import java.io.IOException; |
| 20 | |
import java.util.ArrayList; |
| 21 | |
import java.util.Comparator; |
| 22 | |
import java.util.HashMap; |
| 23 | |
import java.util.Iterator; |
| 24 | |
import java.util.LinkedHashMap; |
| 25 | |
import java.util.List; |
| 26 | |
import java.util.Map; |
| 27 | |
import java.util.Properties; |
| 28 | |
import java.util.Set; |
| 29 | |
import java.util.SortedSet; |
| 30 | |
import java.util.TreeSet; |
| 31 | |
|
| 32 | |
import org.apache.commons.lang.StringUtils; |
| 33 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 34 | |
import org.apache.log4j.Logger; |
| 35 | |
import org.kuali.rice.core.api.config.property.Config; |
| 36 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
| 37 | |
import org.kuali.rice.core.util.RiceUtilities; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public abstract class BaseConfig implements Config { |
| 49 | |
|
| 50 | 0 | private static final Logger LOG = Logger.getLogger(BaseConfig.class); |
| 51 | |
|
| 52 | 0 | private Map<String, Object> configs = new LinkedHashMap<String, Object>(); |
| 53 | |
|
| 54 | 0 | private List<String> fileLocs = new ArrayList<String>(); |
| 55 | |
|
| 56 | 0 | private Properties propertiesUsed = new Properties(); |
| 57 | |
|
| 58 | 0 | private Map<String, Object> objects = new LinkedHashMap<String, Object>(); |
| 59 | |
|
| 60 | 0 | public BaseConfig(String fileLoc) { |
| 61 | 0 | this.fileLocs.add(fileLoc); |
| 62 | 0 | } |
| 63 | |
|
| 64 | 0 | public BaseConfig(List<String> fileLocs) { |
| 65 | 0 | this.fileLocs = fileLocs; |
| 66 | 0 | } |
| 67 | |
|
| 68 | |
protected void parseWithConfigParserImpl() throws IOException { |
| 69 | 0 | ConfigParserImpl cp = new ConfigParserImpl(); |
| 70 | 0 | Map p = new Properties(); |
| 71 | 0 | p.putAll(propertiesUsed); |
| 72 | 0 | cp.parse(p, fileLocs.toArray(new String[fileLocs.size()])); |
| 73 | 0 | putPropertiesInPropsUsed(p, StringUtils.join(fileLocs, ", ")); |
| 74 | 0 | } |
| 75 | |
|
| 76 | |
protected void parseWithHierarchicalConfigParser() throws IOException { |
| 77 | 0 | for (String fileLoc : this.fileLocs) { |
| 78 | 0 | HierarchicalConfigParser configParser = new HierarchicalConfigParser(this.propertiesUsed); |
| 79 | 0 | this.configs.putAll(configParser.parse(fileLoc)); |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | 0 | Set<String> keys = this.configs.keySet(); |
| 84 | |
|
| 85 | 0 | for (Map.Entry<String, Object> config : this.configs.entrySet()) { |
| 86 | 0 | if (config.getValue() instanceof Map) { |
| 87 | 0 | putPropertiesInPropsUsed((Map) config.getValue(), config.getKey()); |
| 88 | |
} else { |
| 89 | 0 | String configValue = (String) config.getValue(); |
| 90 | 0 | if ( LOG.isDebugEnabled() ) { |
| 91 | 0 | LOG.debug("-->Putting root config Prop " + config.getKey() + "=[" + configValue + "]"); |
| 92 | |
} |
| 93 | 0 | this.propertiesUsed.put(config.getKey(), configValue); |
| 94 | 0 | } |
| 95 | |
} |
| 96 | 0 | } |
| 97 | 0 | } |
| 98 | |
|
| 99 | |
public void parseConfig() throws IOException { |
| 100 | 0 | if ( LOG.isInfoEnabled() ) { |
| 101 | 0 | LOG.info("Loading Rice configs: " + StringUtils.join(fileLocs, ", ")); |
| 102 | |
} |
| 103 | 0 | Map<String, Object> baseObjects = getBaseObjects(); |
| 104 | 0 | if (baseObjects != null) { |
| 105 | 0 | this.objects.putAll(baseObjects); |
| 106 | |
} |
| 107 | 0 | configureBuiltIns(this.propertiesUsed); |
| 108 | 0 | Properties baseProperties = getBaseProperties(); |
| 109 | 0 | if (baseProperties != null) { |
| 110 | 0 | this.propertiesUsed.putAll(baseProperties); |
| 111 | |
} |
| 112 | |
|
| 113 | 0 | parseWithConfigParserImpl(); |
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | 0 | if ( LOG.isInfoEnabled() ) { |
| 118 | 0 | LOG.info(""); |
| 119 | 0 | LOG.info("####################################"); |
| 120 | 0 | LOG.info("#"); |
| 121 | 0 | LOG.info("# Properties used after config override/replacement"); |
| 122 | 0 | LOG.info("# " + StringUtils.join(fileLocs, ", ")); |
| 123 | 0 | LOG.info("#"); |
| 124 | 0 | LOG.info("####################################"); |
| 125 | 0 | LOG.info(""); |
| 126 | |
} |
| 127 | 0 | Map<String, String> safePropsUsed = ConfigLogger.getDisplaySafeConfig(this.propertiesUsed); |
| 128 | 0 | Set<Map.Entry<String,String>> entrySet = safePropsUsed.entrySet(); |
| 129 | |
|
| 130 | 0 | SortedSet<Map.Entry<String,String>> sorted = new TreeSet<Map.Entry<String,String>>(new Comparator<Map.Entry<String,String>>() { |
| 131 | |
public int compare(Map.Entry<String,String> a, Map.Entry<String,String> b) { |
| 132 | 0 | return a.getKey().compareTo(b.getKey()); |
| 133 | |
} |
| 134 | |
}); |
| 135 | 0 | sorted.addAll(entrySet); |
| 136 | |
|
| 137 | 0 | if ( LOG.isInfoEnabled() ) { |
| 138 | 0 | for (Map.Entry<String, String> propUsed: sorted) { |
| 139 | 0 | LOG.info("Using config Prop " + propUsed.getKey() + "=[" + propUsed.getValue() + "]"); |
| 140 | |
} |
| 141 | |
} |
| 142 | 0 | } |
| 143 | |
|
| 144 | |
protected void putPropertiesInPropsUsed(Map properties, String fileName) { |
| 145 | |
|
| 146 | 0 | Map<String, String> safeConfig = ConfigLogger.getDisplaySafeConfig(properties); |
| 147 | 0 | if ( LOG.isInfoEnabled() ) { |
| 148 | 0 | LOG.info("Loading properties for config " + fileName); |
| 149 | |
} |
| 150 | 0 | for (Iterator iterator2 = properties.entrySet().iterator(); iterator2.hasNext();) { |
| 151 | 0 | Map.Entry configProp = (Map.Entry) iterator2.next(); |
| 152 | 0 | String key = (String) configProp.getKey(); |
| 153 | 0 | String value = (String) configProp.getValue(); |
| 154 | 0 | String safeValue = safeConfig.get(key); |
| 155 | 0 | if ( LOG.isDebugEnabled() ) { |
| 156 | 0 | LOG.debug("---->Putting config Prop " + key + "=[" + safeValue + "]"); |
| 157 | |
} |
| 158 | 0 | this.propertiesUsed.put(key, value); |
| 159 | 0 | } |
| 160 | 0 | } |
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
protected void configureBuiltIns(Properties properties) { |
| 166 | 0 | properties.put("host.ip", RiceUtilities.getIpNumber()); |
| 167 | 0 | properties.put("host.name", RiceUtilities.getHostName()); |
| 168 | 0 | } |
| 169 | |
|
| 170 | |
public abstract Properties getBaseProperties(); |
| 171 | |
|
| 172 | |
public abstract Map<String, Object> getBaseObjects(); |
| 173 | |
|
| 174 | |
public Properties getProperties() { |
| 175 | 0 | return this.propertiesUsed; |
| 176 | |
} |
| 177 | |
|
| 178 | |
public Map<String, String> getPropertiesWithPrefix(String prefix, boolean stripPrefix) { |
| 179 | 0 | Map<String, String> props = new HashMap<String, String>(); |
| 180 | 0 | for (Map.Entry entry : getProperties().entrySet()) { |
| 181 | 0 | String key = (String) entry.getKey(); |
| 182 | 0 | if (StringUtils.isNotBlank(key) && key.trim().startsWith(prefix)) { |
| 183 | 0 | props.put(stripPrefix ? key.substring(prefix.length()) : key, (String) entry.getValue()); |
| 184 | |
} |
| 185 | 0 | } |
| 186 | 0 | return props; |
| 187 | |
} |
| 188 | |
|
| 189 | |
public String getProperty(String key) { |
| 190 | 0 | return getProperties().getProperty(key); |
| 191 | |
} |
| 192 | |
|
| 193 | |
public boolean getBooleanProperty(String key, boolean defaultValue) { |
| 194 | 0 | return RiceUtilities.getBooleanValueForString(getProperty(key), defaultValue); |
| 195 | |
} |
| 196 | |
|
| 197 | |
public Map<String, Object> getObjects() { |
| 198 | 0 | return this.objects; |
| 199 | |
} |
| 200 | |
|
| 201 | |
public Object getObject(String key) { |
| 202 | 0 | return getObjects().get(key); |
| 203 | |
} |
| 204 | |
|
| 205 | |
public String getBaseWebServiceURL() { |
| 206 | 0 | return getProperty(BASE_WEB_SERVICE_URL_WORKFLOW_CLIENT_FILE); |
| 207 | |
} |
| 208 | |
|
| 209 | |
public String getBaseWebServiceWsdlPath() { |
| 210 | 0 | return getProperty(BASE_WEB_SERVICE_WSDL_PATH); |
| 211 | |
} |
| 212 | |
|
| 213 | |
public String getClientWSDLFullPathAndFileName() { |
| 214 | 0 | return getProperty(WSDL_LOCATION_WORKFLOW_CLIENT_FILE); |
| 215 | |
} |
| 216 | |
|
| 217 | |
public String getWebServicesConnectRetry() { |
| 218 | 0 | return getProperty(WEB_SERVICE_CONNECT_RETRY); |
| 219 | |
} |
| 220 | |
|
| 221 | |
public String getLog4jFileLocation() { |
| 222 | 0 | return getProperty(LOG4J_SETTINGS_PATH); |
| 223 | |
} |
| 224 | |
|
| 225 | |
public String getLog4jReloadInterval() { |
| 226 | 0 | return getProperty(LOG4J_SETTINGS_RELOADINTERVAL_MINS); |
| 227 | |
} |
| 228 | |
|
| 229 | |
public String getTransactionTimeout() { |
| 230 | 0 | return getProperty(TRANSACTION_TIMEOUT); |
| 231 | |
} |
| 232 | |
|
| 233 | |
public String getEmailConfigurationPath() { |
| 234 | 0 | return getProperty(EMAIL_SECURITY_PATH); |
| 235 | |
} |
| 236 | |
|
| 237 | |
public String getEnvironment() { |
| 238 | 0 | return getProperty(ENVIRONMENT); |
| 239 | |
} |
| 240 | |
|
| 241 | |
public String getEDLConfigLocation() { |
| 242 | 0 | return getProperty(EDL_CONFIG_LOCATION); |
| 243 | |
} |
| 244 | |
|
| 245 | |
public String getDefaultKewNoteClass() { |
| 246 | 0 | return getProperty(DEFAULT_KEW_NOTE_CLASS); |
| 247 | |
} |
| 248 | |
|
| 249 | |
public String getEmbeddedPluginLocation() { |
| 250 | 0 | return getProperty(EMBEDDED_PLUGIN_LOCATIAON); |
| 251 | |
} |
| 252 | |
|
| 253 | |
public Integer getRefreshRate() { |
| 254 | 0 | return Integer.valueOf(ConfigContext.getCurrentContextConfig().getProperty(Config.REFRESH_RATE)); |
| 255 | |
} |
| 256 | |
|
| 257 | |
public String getEndPointUrl() { |
| 258 | 0 | return ConfigContext.getCurrentContextConfig().getProperty(Config.SERVICE_SERVLET_URL); |
| 259 | |
} |
| 260 | |
|
| 261 | |
public String getAlternateOJBFile() { |
| 262 | 0 | return getProperty(Config.ALT_OJB_FILE); |
| 263 | |
} |
| 264 | |
|
| 265 | |
public String getAlternateSpringFile() { |
| 266 | 0 | return getProperty(Config.ALT_SPRING_FILE); |
| 267 | |
} |
| 268 | |
|
| 269 | |
public String getKeystoreAlias() { |
| 270 | 0 | return getProperty(Config.KEYSTORE_ALIAS); |
| 271 | |
} |
| 272 | |
|
| 273 | |
public String getKeystorePassword() { |
| 274 | 0 | return getProperty(Config.KEYSTORE_PASSWORD); |
| 275 | |
} |
| 276 | |
|
| 277 | |
public String getKeystoreFile() { |
| 278 | 0 | return getProperty(Config.KEYSTORE_FILE); |
| 279 | |
} |
| 280 | |
|
| 281 | |
public String getDailyEmailFirstDeliveryDate() { |
| 282 | 0 | return getProperty(Config.FIRST_DAILY_EMAIL_DELIVERY_DATE); |
| 283 | |
} |
| 284 | |
|
| 285 | |
public String getWeeklyEmailFirstDeliveryDate() { |
| 286 | 0 | return getProperty(org.kuali.rice.core.api.config.property.Config.FIRST_WEEKLY_EMAIL_DELIVERY_DATE); |
| 287 | |
} |
| 288 | |
|
| 289 | |
public String getDocumentLockTimeout() { |
| 290 | 0 | return getProperty(Config.DOCUMENT_LOCK_TIMEOUT); |
| 291 | |
} |
| 292 | |
|
| 293 | |
public Boolean getEmailReminderLifecycleEnabled() { |
| 294 | 0 | return Boolean.valueOf(getProperty(ENABLE_EMAIL_REMINDER_LIFECYCLE)); |
| 295 | |
} |
| 296 | |
|
| 297 | |
public Boolean getXmlPipelineLifeCycleEnabled() { |
| 298 | 0 | return Boolean.valueOf(getProperty(ENABLE_XML_PIPELINE_LIFECYCLE)); |
| 299 | |
} |
| 300 | |
|
| 301 | |
public Boolean getDevMode() { |
| 302 | 0 | return Boolean.valueOf(getProperty(DEV_MODE)); |
| 303 | |
} |
| 304 | |
|
| 305 | |
public Boolean getBatchMode() { |
| 306 | 0 | return new Boolean(getProperty(BATCH_MODE)); |
| 307 | |
} |
| 308 | |
|
| 309 | |
public Boolean getOutBoxOn() { |
| 310 | 0 | if (getProperty(Config.OUT_BOX_MODE) == null) { |
| 311 | 0 | return true; |
| 312 | |
} |
| 313 | 0 | return Boolean.valueOf(getProperty(Config.OUT_BOX_MODE)); |
| 314 | |
} |
| 315 | |
|
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | |
|
| 320 | |
public String getKEWBaseURL() { |
| 321 | 0 | return getProperty(Config.KEW_URL); |
| 322 | |
} |
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
public String getKIMBaseURL() { |
| 329 | 0 | return getProperty(Config.KIM_URL); |
| 330 | |
} |
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
public String getKRBaseURL() { |
| 337 | 0 | return getProperty(Config.KR_URL); |
| 338 | |
} |
| 339 | |
|
| 340 | |
|
| 341 | |
|
| 342 | |
|
| 343 | |
|
| 344 | |
public String getKENBaseURL() { |
| 345 | 0 | return getProperty(Config.KEN_URL); |
| 346 | |
} |
| 347 | |
|
| 348 | |
public String toString() { |
| 349 | 0 | return new ToStringBuilder(this).append("fileLocs", fileLocs).toString(); |
| 350 | |
} |
| 351 | |
|
| 352 | |
|
| 353 | |
public void putProperties(Properties properties) { |
| 354 | 0 | if (properties != null) { |
| 355 | 0 | getProperties().putAll(properties); |
| 356 | |
} |
| 357 | 0 | } |
| 358 | |
|
| 359 | |
public void putProperty(String key, String value) { |
| 360 | 0 | this.getProperties().put(key, value); |
| 361 | 0 | } |
| 362 | |
|
| 363 | |
public void putObject(String key, Object value) { |
| 364 | 0 | this.objects.put(key, value); |
| 365 | 0 | } |
| 366 | |
|
| 367 | |
public void putObjects(Map<String, Object> objects) { |
| 368 | 0 | if(objects != null){ |
| 369 | 0 | this.objects.putAll(objects); |
| 370 | |
} |
| 371 | |
|
| 372 | 0 | } |
| 373 | |
|
| 374 | |
public void removeObject(String key){ |
| 375 | 0 | this.objects.remove(key); |
| 376 | 0 | } |
| 377 | |
|
| 378 | |
public void removeProperty(String key){ |
| 379 | 0 | this.getProperties().remove(key); |
| 380 | 0 | } |
| 381 | |
|
| 382 | |
public void putConfig(Config config) { |
| 383 | 0 | putProperties(config.getProperties()); |
| 384 | 0 | putObjects(config.getObjects()); |
| 385 | 0 | } |
| 386 | |
} |