View Javadoc

1   /**
2    * Copyright 2010-2012 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.Collections;
19  import java.util.List;
20  import java.util.Properties;
21  
22  import org.kuali.common.util.Mode;
23  import org.kuali.common.util.PropertyUtils;
24  import org.kuali.common.util.Str;
25  import org.kuali.common.util.property.Constants;
26  
27  public class PathProcessor implements PropertyProcessor {
28  
29  	Mode propertyOverwriteMode = Constants.DEFAULT_PROPERTY_OVERWRITE_MODE;
30  	String suffix = Constants.DEFAULT_PATH_SUFFIX;
31  	List<String> includes;
32  	List<String> excludes;
33  
34  	public PathProcessor() {
35  		this(Collections.<String> emptyList());
36  	}
37  
38  	public PathProcessor(String include) {
39  		this(Collections.singletonList(include));
40  	}
41  
42  	public PathProcessor(List<String> includes) {
43  		super();
44  		this.includes = includes;
45  	}
46  
47  	@Override
48  	public void process(Properties properties) {
49  		List<String> keys = PropertyUtils.getSortedKeys(properties, includes, excludes);
50  		for (String key : keys) {
51  			String oldValue = properties.getProperty(key);
52  			String newValue = Str.getPath(oldValue);
53  			String newKey = key + "." + suffix;
54  			PropertyUtils.addOrOverrideProperty(properties, newKey, newValue, propertyOverwriteMode);
55  		}
56  	}
57  
58  	public String getSuffix() {
59  		return suffix;
60  	}
61  
62  	public void setSuffix(String suffix) {
63  		this.suffix = suffix;
64  	}
65  
66  	public List<String> getIncludes() {
67  		return includes;
68  	}
69  
70  	public void setIncludes(List<String> includes) {
71  		this.includes = includes;
72  	}
73  
74  	public List<String> getExcludes() {
75  		return excludes;
76  	}
77  
78  	public void setExcludes(List<String> excludes) {
79  		this.excludes = excludes;
80  	}
81  
82  	public Mode getPropertyOverwriteMode() {
83  		return propertyOverwriteMode;
84  	}
85  
86  	public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
87  		this.propertyOverwriteMode = propertyOverwriteMode;
88  	}
89  
90  }