001/**
002 * Copyright 2010-2014 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 */
016package org.kuali.common.util.property.processor;
017
018import java.util.List;
019import java.util.Properties;
020
021import org.kuali.common.util.Mode;
022import org.kuali.common.util.PropertyUtils;
023import org.kuali.common.util.property.Constants;
024
025public class OverrideProcessor implements PropertyProcessor {
026
027        Mode propertyOverwriteMode;
028        Properties overrideProperties;
029        List<String> includes;
030        List<String> excludes;
031        int indent;
032
033        public OverrideProcessor() {
034                this(Constants.DEFAULT_PROPERTY_OVERWRITE_MODE);
035        }
036
037        public OverrideProcessor(Mode propertyOverwriteMode) {
038                this(Constants.DEFAULT_PROPERTY_OVERWRITE_MODE, null, 0);
039        }
040
041        public OverrideProcessor(Mode propertyOverwriteMode, Properties overrideProperties) {
042                this(Constants.DEFAULT_PROPERTY_OVERWRITE_MODE, overrideProperties, 0);
043        }
044
045        public OverrideProcessor(Mode propertyOverwriteMode, Properties overrideProperties, int indent) {
046                super();
047                this.propertyOverwriteMode = propertyOverwriteMode;
048                this.overrideProperties = overrideProperties;
049                this.indent = indent;
050        }
051
052        @Override
053        public void process(Properties properties) {
054                List<String> keys = PropertyUtils.getSortedKeys(overrideProperties, includes, excludes);
055                for (String key : keys) {
056                        String newValue = overrideProperties.getProperty(key);
057                        PropertyUtils.addOrOverrideProperty(properties, key, newValue, propertyOverwriteMode, indent);
058                }
059        }
060
061        public Mode getPropertyOverwriteMode() {
062                return propertyOverwriteMode;
063        }
064
065        public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
066                this.propertyOverwriteMode = propertyOverwriteMode;
067        }
068
069        public Properties getOverrideProperties() {
070                return overrideProperties;
071        }
072
073        public void setOverrideProperties(Properties overrideProperties) {
074                this.overrideProperties = overrideProperties;
075        }
076
077        public List<String> getIncludes() {
078                return includes;
079        }
080
081        public void setIncludes(List<String> includes) {
082                this.includes = includes;
083        }
084
085        public List<String> getExcludes() {
086                return excludes;
087        }
088
089        public void setExcludes(List<String> excludes) {
090                this.excludes = excludes;
091        }
092
093}