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