author | František Kučera <franta-hg@frantovo.cz> |
Mon, 17 Nov 2014 23:41:37 +0100 | |
changeset 21 | aecbaa8adb93 |
parent 18 | a5a36526ff71 |
permissions | -rw-r--r-- |
franta-hg@3 | 1 |
/** |
franta-hg@3 | 2 |
* copy-image-resizer |
franta-hg@3 | 3 |
* Copyright © 2014 František Kučera (frantovo.cz) |
franta-hg@3 | 4 |
* |
franta-hg@3 | 5 |
* This program is free software: you can redistribute it and/or modify |
franta-hg@3 | 6 |
* it under the terms of the GNU General Public License as published by |
franta-hg@3 | 7 |
* the Free Software Foundation, either version 3 of the License, or |
franta-hg@3 | 8 |
* (at your option) any later version. |
franta-hg@3 | 9 |
* |
franta-hg@3 | 10 |
* This program is distributed in the hope that it will be useful, |
franta-hg@3 | 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
franta-hg@3 | 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
franta-hg@3 | 13 |
* GNU General Public License for more details. |
franta-hg@3 | 14 |
* |
franta-hg@3 | 15 |
* You should have received a copy of the GNU General Public License |
franta-hg@3 | 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
franta-hg@3 | 17 |
*/ |
franta-hg@5 | 18 |
package cz.frantovo.copyImageResizer; |
franta-hg@3 | 19 |
|
franta-hg@3 | 20 |
import java.io.File; |
franta-hg@3 | 21 |
import java.util.ArrayList; |
franta-hg@3 | 22 |
import java.util.Collection; |
franta-hg@3 | 23 |
|
franta-hg@3 | 24 |
/** |
franta-hg@6 | 25 |
* |
franta-hg@3 | 26 |
* @author Ing. František Kučera (frantovo.cz) |
franta-hg@3 | 27 |
*/ |
franta-hg@5 | 28 |
public class RecursiveOptions { |
franta-hg@3 | 29 |
|
franta-hg@3 | 30 |
/** |
franta-hg@3 | 31 |
* Source directory |
franta-hg@3 | 32 |
*/ |
franta-hg@3 | 33 |
private File input; |
franta-hg@3 | 34 |
/** |
franta-hg@3 | 35 |
* Output directory |
franta-hg@3 | 36 |
*/ |
franta-hg@3 | 37 |
private File output; |
franta-hg@3 | 38 |
/** |
franta-hg@3 | 39 |
* Image resolutions to create |
franta-hg@3 | 40 |
*/ |
franta-hg@3 | 41 |
private final Collection<SizeSpecification> sizes = new ArrayList<>(); |
franta-hg@14 | 42 |
/** |
franta-hg@14 | 43 |
* Whether errors (while resizing/copying particular images) should be just logged and skipped. |
franta-hg@14 | 44 |
*/ |
franta-hg@18 | 45 |
private ERROR_MODE errorMode; |
franta-hg@3 | 46 |
|
franta-hg@6 | 47 |
public File getInput() { |
franta-hg@3 | 48 |
return input; |
franta-hg@3 | 49 |
} |
franta-hg@3 | 50 |
|
franta-hg@3 | 51 |
public void setInput(File input) { |
franta-hg@3 | 52 |
this.input = input; |
franta-hg@3 | 53 |
} |
franta-hg@3 | 54 |
|
franta-hg@6 | 55 |
public File getOutput() { |
franta-hg@3 | 56 |
return output; |
franta-hg@3 | 57 |
} |
franta-hg@3 | 58 |
|
franta-hg@3 | 59 |
public void setOutput(File output) { |
franta-hg@3 | 60 |
this.output = output; |
franta-hg@3 | 61 |
} |
franta-hg@3 | 62 |
|
franta-hg@3 | 63 |
public Collection<SizeSpecification> getSizes() { |
franta-hg@3 | 64 |
return sizes; |
franta-hg@3 | 65 |
} |
franta-hg@3 | 66 |
|
franta-hg@3 | 67 |
public void addSize(SizeSpecification size) { |
franta-hg@3 | 68 |
sizes.add(size); |
franta-hg@3 | 69 |
} |
franta-hg@12 | 70 |
|
franta-hg@18 | 71 |
public ERROR_MODE getErrorMode() { |
franta-hg@18 | 72 |
return errorMode; |
franta-hg@14 | 73 |
} |
franta-hg@14 | 74 |
|
franta-hg@18 | 75 |
public void setErrorMode(ERROR_MODE errorMode) { |
franta-hg@18 | 76 |
this.errorMode = errorMode; |
franta-hg@14 | 77 |
} |
franta-hg@14 | 78 |
|
franta-hg@12 | 79 |
public void validate() throws InvalidOptionsException { |
franta-hg@12 | 80 |
InvalidOptionsException e = new InvalidOptionsException(); |
franta-hg@12 | 81 |
|
franta-hg@12 | 82 |
if (input == null) { |
franta-hg@12 | 83 |
e.addProblem(new InvalidOptionsException.OptionProblem("input directory must be specified")); |
franta-hg@12 | 84 |
} else if (!input.isDirectory()) { |
franta-hg@12 | 85 |
e.addProblem(new InvalidOptionsException.OptionProblem("input directory must exist and be a directory: " + input)); |
franta-hg@12 | 86 |
} |
franta-hg@12 | 87 |
|
franta-hg@12 | 88 |
if (output == null) { |
franta-hg@12 | 89 |
e.addProblem(new InvalidOptionsException.OptionProblem("output directory must be specified")); |
franta-hg@12 | 90 |
} |
franta-hg@12 | 91 |
|
franta-hg@12 | 92 |
if (sizes.isEmpty()) { |
franta-hg@12 | 93 |
e.addProblem(new InvalidOptionsException.OptionProblem("at least one size (output resolution) must be specified")); |
franta-hg@12 | 94 |
} |
franta-hg@12 | 95 |
|
franta-hg@12 | 96 |
if (e.hasProblems()) { |
franta-hg@12 | 97 |
throw e; |
franta-hg@12 | 98 |
} |
franta-hg@12 | 99 |
} |
franta-hg@18 | 100 |
|
franta-hg@18 | 101 |
public static enum ERROR_MODE { |
franta-hg@18 | 102 |
|
franta-hg@18 | 103 |
/** |
franta-hg@18 | 104 |
* fail on first error |
franta-hg@18 | 105 |
*/ |
franta-hg@18 | 106 |
FAIL_EARLY, |
franta-hg@18 | 107 |
/** |
franta-hg@18 | 108 |
* just log errors, skip them and fail at the end |
franta-hg@18 | 109 |
*/ |
franta-hg@18 | 110 |
FAIL_LATER, |
franta-hg@18 | 111 |
/** |
franta-hg@18 | 112 |
* just log errors, skip them and report success |
franta-hg@18 | 113 |
*/ |
franta-hg@18 | 114 |
SILENT_SKIP |
franta-hg@18 | 115 |
} |
franta-hg@3 | 116 |
} |