View Javadoc

1   /**
2    * Copyright 2010-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }