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