1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.property.processor;
17
18 import java.util.List;
19 import java.util.Properties;
20
21 import org.kuali.common.util.Mode;
22 import org.kuali.common.util.PropertyUtils;
23 import org.kuali.common.util.property.Constants;
24 import org.kuali.common.util.property.GlobalPropertiesMode;
25
26 public class GlobalOverrideProcessor implements PropertyProcessor {
27
28 GlobalPropertiesMode globalPropertiesMode;
29 Mode propertyOverwriteMode;
30 List<String> includes;
31 List<String> excludes;
32
33 public GlobalOverrideProcessor() {
34 this(Constants.DEFAULT_GLOBAL_PROPERTIES_MODE, Constants.DEFAULT_PROPERTY_OVERWRITE_MODE);
35 }
36
37 public GlobalOverrideProcessor(GlobalPropertiesMode globalPropertiesMode) {
38 this(globalPropertiesMode, Constants.DEFAULT_PROPERTY_OVERWRITE_MODE);
39 }
40
41 public GlobalOverrideProcessor(GlobalPropertiesMode globalPropertiesMode, Mode propertyOverwriteMode) {
42 super();
43 this.globalPropertiesMode = globalPropertiesMode;
44 this.propertyOverwriteMode = propertyOverwriteMode;
45 }
46
47 @Override
48 public void process(Properties properties) {
49 Properties global = PropertyUtils.getProperties(properties, globalPropertiesMode);
50 List<String> keys = PropertyUtils.getSortedKeys(properties, includes, excludes);
51 for (String key : keys) {
52 String newValue = global.getProperty(key);
53 PropertyUtils.addOrOverrideProperty(properties, key, newValue, propertyOverwriteMode);
54 }
55 }
56
57 public GlobalPropertiesMode getGlobalPropertiesMode() {
58 return globalPropertiesMode;
59 }
60
61 public void setGlobalPropertiesMode(GlobalPropertiesMode globalPropertiesMode) {
62 this.globalPropertiesMode = globalPropertiesMode;
63 }
64
65 public Mode getPropertyOverwriteMode() {
66 return propertyOverwriteMode;
67 }
68
69 public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
70 this.propertyOverwriteMode = propertyOverwriteMode;
71 }
72
73 public List<String> getIncludes() {
74 return includes;
75 }
76
77 public void setIncludes(List<String> includes) {
78 this.includes = includes;
79 }
80
81 public List<String> getExcludes() {
82 return excludes;
83 }
84
85 public void setExcludes(List<String> excludes) {
86 this.excludes = excludes;
87 }
88
89 }