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; 024import org.kuali.common.util.property.GlobalPropertiesMode; 025 026public class GlobalOverrideProcessor implements PropertyProcessor { 027 028 GlobalPropertiesMode globalPropertiesMode; 029 Mode propertyOverwriteMode; 030 List<String> includes; 031 List<String> excludes; 032 033 public GlobalOverrideProcessor() { 034 this(Constants.DEFAULT_GLOBAL_PROPERTIES_MODE, Constants.DEFAULT_PROPERTY_OVERWRITE_MODE); 035 } 036 037 public GlobalOverrideProcessor(GlobalPropertiesMode globalPropertiesMode) { 038 this(globalPropertiesMode, Constants.DEFAULT_PROPERTY_OVERWRITE_MODE); 039 } 040 041 public GlobalOverrideProcessor(GlobalPropertiesMode globalPropertiesMode, Mode propertyOverwriteMode) { 042 super(); 043 this.globalPropertiesMode = globalPropertiesMode; 044 this.propertyOverwriteMode = propertyOverwriteMode; 045 } 046 047 @Override 048 public void process(Properties properties) { 049 Properties global = PropertyUtils.getProperties(properties, globalPropertiesMode); 050 List<String> keys = PropertyUtils.getSortedKeys(properties, includes, excludes); 051 for (String key : keys) { 052 String newValue = global.getProperty(key); 053 PropertyUtils.addOrOverrideProperty(properties, key, newValue, propertyOverwriteMode); 054 } 055 } 056 057 public GlobalPropertiesMode getGlobalPropertiesMode() { 058 return globalPropertiesMode; 059 } 060 061 public void setGlobalPropertiesMode(GlobalPropertiesMode globalPropertiesMode) { 062 this.globalPropertiesMode = globalPropertiesMode; 063 } 064 065 public Mode getPropertyOverwriteMode() { 066 return propertyOverwriteMode; 067 } 068 069 public void setPropertyOverwriteMode(Mode propertyOverwriteMode) { 070 this.propertyOverwriteMode = propertyOverwriteMode; 071 } 072 073 public List<String> getIncludes() { 074 return includes; 075 } 076 077 public void setIncludes(List<String> includes) { 078 this.includes = includes; 079 } 080 081 public List<String> getExcludes() { 082 return excludes; 083 } 084 085 public void setExcludes(List<String> excludes) { 086 this.excludes = excludes; 087 } 088 089}