View Javadoc
1   /**
2    * Copyright 2010-2014 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  
25  public class OverrideProcessor implements PropertyProcessor {
26  
27  	Mode propertyOverwriteMode;
28  	Properties overrideProperties;
29  	List<String> includes;
30  	List<String> excludes;
31  	int indent;
32  
33  	public OverrideProcessor() {
34  		this(Constants.DEFAULT_PROPERTY_OVERWRITE_MODE);
35  	}
36  
37  	public OverrideProcessor(Mode propertyOverwriteMode) {
38  		this(Constants.DEFAULT_PROPERTY_OVERWRITE_MODE, null, 0);
39  	}
40  
41  	public OverrideProcessor(Mode propertyOverwriteMode, Properties overrideProperties) {
42  		this(Constants.DEFAULT_PROPERTY_OVERWRITE_MODE, overrideProperties, 0);
43  	}
44  
45  	public OverrideProcessor(Mode propertyOverwriteMode, Properties overrideProperties, int indent) {
46  		super();
47  		this.propertyOverwriteMode = propertyOverwriteMode;
48  		this.overrideProperties = overrideProperties;
49  		this.indent = indent;
50  	}
51  
52  	@Override
53  	public void process(Properties properties) {
54  		List<String> keys = PropertyUtils.getSortedKeys(overrideProperties, includes, excludes);
55  		for (String key : keys) {
56  			String newValue = overrideProperties.getProperty(key);
57  			PropertyUtils.addOrOverrideProperty(properties, key, newValue, propertyOverwriteMode, indent);
58  		}
59  	}
60  
61  	public Mode getPropertyOverwriteMode() {
62  		return propertyOverwriteMode;
63  	}
64  
65  	public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
66  		this.propertyOverwriteMode = propertyOverwriteMode;
67  	}
68  
69  	public Properties getOverrideProperties() {
70  		return overrideProperties;
71  	}
72  
73  	public void setOverrideProperties(Properties overrideProperties) {
74  		this.overrideProperties = overrideProperties;
75  	}
76  
77  	public List<String> getIncludes() {
78  		return includes;
79  	}
80  
81  	public void setIncludes(List<String> includes) {
82  		this.includes = includes;
83  	}
84  
85  	public List<String> getExcludes() {
86  		return excludes;
87  	}
88  
89  	public void setExcludes(List<String> excludes) {
90  		this.excludes = excludes;
91  	}
92  
93  }