001 /**
002 * Copyright 2010-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.common.util.property.processor;
017
018 import java.util.List;
019 import java.util.Properties;
020
021 import org.kuali.common.util.Mode;
022 import org.kuali.common.util.PropertyUtils;
023 import org.kuali.common.util.property.Constants;
024
025 public class OverrideProcessor implements PropertyProcessor {
026
027 Mode propertyOverwriteMode;
028 Properties overrideProperties;
029 List<String> includes;
030 List<String> excludes;
031
032 public OverrideProcessor() {
033 this(Constants.DEFAULT_PROPERTY_OVERWRITE_MODE);
034 }
035
036 public OverrideProcessor(Mode propertyOverwriteMode) {
037 this(Constants.DEFAULT_PROPERTY_OVERWRITE_MODE, null);
038 }
039
040 public OverrideProcessor(Mode propertyOverwriteMode, Properties overrideProperties) {
041 super();
042 this.propertyOverwriteMode = propertyOverwriteMode;
043 this.overrideProperties = overrideProperties;
044 }
045
046 @Override
047 public void process(Properties properties) {
048 List<String> keys = PropertyUtils.getSortedKeys(overrideProperties, includes, excludes);
049 for (String key : keys) {
050 String newValue = overrideProperties.getProperty(key);
051 PropertyUtils.addOrOverrideProperty(properties, key, newValue, propertyOverwriteMode);
052 }
053 }
054
055 public Mode getPropertyOverwriteMode() {
056 return propertyOverwriteMode;
057 }
058
059 public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
060 this.propertyOverwriteMode = propertyOverwriteMode;
061 }
062
063 public Properties getOverrideProperties() {
064 return overrideProperties;
065 }
066
067 public void setOverrideProperties(Properties overrideProperties) {
068 this.overrideProperties = overrideProperties;
069 }
070
071 public List<String> getIncludes() {
072 return includes;
073 }
074
075 public void setIncludes(List<String> includes) {
076 this.includes = includes;
077 }
078
079 public List<String> getExcludes() {
080 return excludes;
081 }
082
083 public void setExcludes(List<String> excludes) {
084 this.excludes = excludes;
085 }
086
087 }