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            boolean skip;
029            Properties properties;
030            File outputFile;
031            List<String> includes;
032            List<String> excludes;
033    
034            @Override
035            public void execute() {
036                    if (skip) {
037                            return;
038                    }
039                    Assert.notNull(properties, "properties is null");
040                    Assert.notNull(outputFile, "outputFile is null");
041                    List<String> keys = PropertyUtils.getSortedKeys(properties, includes, excludes);
042                    Properties outputProperties = new Properties();
043                    for (String key : keys) {
044                            String value = properties.getProperty(key);
045                            outputProperties.setProperty(key, value);
046                    }
047                    PropertyUtils.store(outputProperties, outputFile, encoding);
048            }
049    
050            public Properties getProperties() {
051                    return properties;
052            }
053    
054            public void setProperties(Properties properties) {
055                    this.properties = properties;
056            }
057    
058            public File getOutputFile() {
059                    return outputFile;
060            }
061    
062            public void setOutputFile(File outputFile) {
063                    this.outputFile = outputFile;
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 String getEncoding() {
083                    return encoding;
084            }
085    
086            public void setEncoding(String encoding) {
087                    this.encoding = encoding;
088            }
089    
090            public boolean isSkip() {
091                    return skip;
092            }
093    
094            public void setSkip(boolean skip) {
095                    this.skip = skip;
096            }
097    
098    }