001 /**
002 * Copyright 2010-2012 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 */
016 package org.kuali.common.util.execute;
017
018 import java.io.File;
019 import java.util.List;
020 import java.util.Properties;
021
022 import org.kuali.common.util.PropertyUtils;
023 import org.springframework.util.Assert;
024
025 public class StorePropertiesExecutable implements Executable {
026
027 String encoding = "UTF-8";
028 Properties properties;
029 File outputFile;
030 List<String> includes;
031 List<String> excludes;
032
033 @Override
034 public void execute() {
035 Assert.notNull(properties, "properties is null");
036 Assert.notNull(outputFile, "outputFile is null");
037 List<String> keys = PropertyUtils.getSortedKeys(properties, includes, excludes);
038 Properties outputProperties = new Properties();
039 for (String key : keys) {
040 String value = properties.getProperty(key);
041 outputProperties.setProperty(key, value);
042 }
043 PropertyUtils.store(outputProperties, outputFile, encoding);
044 }
045
046 public Properties getProperties() {
047 return properties;
048 }
049
050 public void setProperties(Properties properties) {
051 this.properties = properties;
052 }
053
054 public File getOutputFile() {
055 return outputFile;
056 }
057
058 public void setOutputFile(File outputFile) {
059 this.outputFile = outputFile;
060 }
061
062 public List<String> getIncludes() {
063 return includes;
064 }
065
066 public void setIncludes(List<String> includes) {
067 this.includes = includes;
068 }
069
070 public List<String> getExcludes() {
071 return excludes;
072 }
073
074 public void setExcludes(List<String> excludes) {
075 this.excludes = excludes;
076 }
077
078 public String getEncoding() {
079 return encoding;
080 }
081
082 public void setEncoding(String encoding) {
083 this.encoding = encoding;
084 }
085
086 }