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.execute;
17  
18  import java.io.File;
19  import java.util.List;
20  import java.util.Properties;
21  
22  import org.kuali.common.util.PropertyUtils;
23  import org.springframework.util.Assert;
24  
25  public class StorePropertiesExecutable implements Executable {
26  
27  	String encoding = "UTF-8";
28  	boolean skip;
29  	Properties properties;
30  	File outputFile;
31  	List<String> includes;
32  	List<String> excludes;
33  
34  	@Override
35  	public void execute() {
36  		if (skip) {
37  			return;
38  		}
39  		Assert.notNull(properties, "properties is null");
40  		Assert.notNull(outputFile, "outputFile is null");
41  		List<String> keys = PropertyUtils.getSortedKeys(properties, includes, excludes);
42  		Properties outputProperties = new Properties();
43  		for (String key : keys) {
44  			String value = properties.getProperty(key);
45  			outputProperties.setProperty(key, value);
46  		}
47  		PropertyUtils.store(outputProperties, outputFile, encoding);
48  	}
49  
50  	public Properties getProperties() {
51  		return properties;
52  	}
53  
54  	public void setProperties(Properties properties) {
55  		this.properties = properties;
56  	}
57  
58  	public File getOutputFile() {
59  		return outputFile;
60  	}
61  
62  	public void setOutputFile(File outputFile) {
63  		this.outputFile = outputFile;
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 String getEncoding() {
83  		return encoding;
84  	}
85  
86  	public void setEncoding(String encoding) {
87  		this.encoding = encoding;
88  	}
89  
90  	public boolean isSkip() {
91  		return skip;
92  	}
93  
94  	public void setSkip(boolean skip) {
95  		this.skip = skip;
96  	}
97  
98  }