franta-hg@3: /** franta-hg@3: * copy-image-resizer franta-hg@3: * Copyright © 2014 František Kučera (frantovo.cz) franta-hg@3: * franta-hg@3: * This program is free software: you can redistribute it and/or modify franta-hg@3: * it under the terms of the GNU General Public License as published by franta-hg@3: * the Free Software Foundation, either version 3 of the License, or franta-hg@3: * (at your option) any later version. franta-hg@3: * franta-hg@3: * This program is distributed in the hope that it will be useful, franta-hg@3: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@3: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@3: * GNU General Public License for more details. franta-hg@3: * franta-hg@3: * You should have received a copy of the GNU General Public License franta-hg@3: * along with this program. If not, see . franta-hg@3: */ franta-hg@5: package cz.frantovo.copyImageResizer; franta-hg@3: franta-hg@3: import java.io.File; franta-hg@3: import java.util.ArrayList; franta-hg@3: import java.util.Collection; franta-hg@3: franta-hg@3: /** franta-hg@6: * franta-hg@3: * @author Ing. František Kučera (frantovo.cz) franta-hg@3: */ franta-hg@5: public class RecursiveOptions { franta-hg@3: franta-hg@3: /** franta-hg@3: * Source directory franta-hg@3: */ franta-hg@3: private File input; franta-hg@3: /** franta-hg@3: * Output directory franta-hg@3: */ franta-hg@3: private File output; franta-hg@3: /** franta-hg@3: * Image resolutions to create franta-hg@3: */ franta-hg@3: private final Collection sizes = new ArrayList<>(); franta-hg@14: /** franta-hg@14: * Whether errors (while resizing/copying particular images) should be just logged and skipped. franta-hg@14: */ franta-hg@18: private ERROR_MODE errorMode; franta-hg@3: franta-hg@6: public File getInput() { franta-hg@3: return input; franta-hg@3: } franta-hg@3: franta-hg@3: public void setInput(File input) { franta-hg@3: this.input = input; franta-hg@3: } franta-hg@3: franta-hg@6: public File getOutput() { franta-hg@3: return output; franta-hg@3: } franta-hg@3: franta-hg@3: public void setOutput(File output) { franta-hg@3: this.output = output; franta-hg@3: } franta-hg@3: franta-hg@3: public Collection getSizes() { franta-hg@3: return sizes; franta-hg@3: } franta-hg@3: franta-hg@3: public void addSize(SizeSpecification size) { franta-hg@3: sizes.add(size); franta-hg@3: } franta-hg@12: franta-hg@18: public ERROR_MODE getErrorMode() { franta-hg@18: return errorMode; franta-hg@14: } franta-hg@14: franta-hg@18: public void setErrorMode(ERROR_MODE errorMode) { franta-hg@18: this.errorMode = errorMode; franta-hg@14: } franta-hg@14: franta-hg@12: public void validate() throws InvalidOptionsException { franta-hg@12: InvalidOptionsException e = new InvalidOptionsException(); franta-hg@12: franta-hg@12: if (input == null) { franta-hg@12: e.addProblem(new InvalidOptionsException.OptionProblem("input directory must be specified")); franta-hg@12: } else if (!input.isDirectory()) { franta-hg@12: e.addProblem(new InvalidOptionsException.OptionProblem("input directory must exist and be a directory: " + input)); franta-hg@12: } franta-hg@12: franta-hg@12: if (output == null) { franta-hg@12: e.addProblem(new InvalidOptionsException.OptionProblem("output directory must be specified")); franta-hg@12: } franta-hg@12: franta-hg@12: if (sizes.isEmpty()) { franta-hg@12: e.addProblem(new InvalidOptionsException.OptionProblem("at least one size (output resolution) must be specified")); franta-hg@12: } franta-hg@12: franta-hg@12: if (e.hasProblems()) { franta-hg@12: throw e; franta-hg@12: } franta-hg@12: } franta-hg@18: franta-hg@18: public static enum ERROR_MODE { franta-hg@18: franta-hg@18: /** franta-hg@18: * fail on first error franta-hg@18: */ franta-hg@18: FAIL_EARLY, franta-hg@18: /** franta-hg@18: * just log errors, skip them and fail at the end franta-hg@18: */ franta-hg@18: FAIL_LATER, franta-hg@18: /** franta-hg@18: * just log errors, skip them and report success franta-hg@18: */ franta-hg@18: SILENT_SKIP franta-hg@18: } franta-hg@3: }