# HG changeset patch # User František Kučera # Date 1416178048 -3600 # Node ID 5019e3e93a4e3e1141674e52294658e6a5f88736 # Parent f3b4caf1d05d6150c91f3d8ff4beb72dfab33adc recursive resizer classes diff -r f3b4caf1d05d -r 5019e3e93a4e java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveException.java Sun Nov 16 23:47:28 2014 +0100 @@ -0,0 +1,42 @@ +/** + * copy-image-resizer + * Copyright © 2014 František Kučera (frantovo.cz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package cz.frantovo.copyImageResizer; + +/** + * Some problem with recursive directory/files processing. + * + * @author Ing. František Kučera (frantovo.cz) + */ +public class RecursiveException extends CopyImageResizerException { + + public RecursiveException() { + } + + public RecursiveException(String message) { + super(message); + } + + public RecursiveException(Throwable cause) { + super(cause); + } + + public RecursiveException(String message, Throwable cause) { + super(message, cause); + } + +} diff -r f3b4caf1d05d -r 5019e3e93a4e java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveImageResizer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveImageResizer.java Sun Nov 16 23:47:28 2014 +0100 @@ -0,0 +1,29 @@ +/** + * copy-image-resizer + * Copyright © 2014 František Kučera (frantovo.cz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package cz.frantovo.copyImageResizer; + +/** + * + * @author Ing. František Kučera (frantovo.cz) + */ +public class RecursiveImageResizer { + + public void resize(RecursiveOptions options) throws RecursiveException, ResizeException { + } + +} diff -r f3b4caf1d05d -r 5019e3e93a4e java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveOptions.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveOptions.java Sun Nov 16 23:47:28 2014 +0100 @@ -0,0 +1,91 @@ +/** + * copy-image-resizer + * Copyright © 2014 František Kučera (frantovo.cz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package cz.frantovo.copyImageResizer; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; + +/** + * + * @author Ing. František Kučera (frantovo.cz) + */ +public class RecursiveOptions { + + /** + * Source directory + */ + private File input; + /** + * Output directory + */ + private File output; + /** + * Image resolutions to create + */ + private final Collection sizes = new ArrayList<>(); + + public File getSourceDir() { + return input; + } + + public void setInput(File input) { + this.input = input; + } + + public File getDestinationDir() { + return output; + } + + public void setOutput(File output) { + this.output = output; + } + + public Collection getSizes() { + return sizes; + } + + public void addSize(SizeSpecification size) { + sizes.add(size); + } + + public static class SizeSpecification { + + private final int width; + private final int height; + private final String directory; + + public SizeSpecification(int width, int height, String directory) { + this.width = width; + this.height = height; + this.directory = directory; + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public String getDirectory() { + return directory; + } + } +} diff -r f3b4caf1d05d -r 5019e3e93a4e java/copy-image-resizer/src/cz/frantovo/copyImageResizer/ResizeException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/ResizeException.java Sun Nov 16 23:47:28 2014 +0100 @@ -0,0 +1,42 @@ +/** + * copy-image-resizer + * Copyright © 2014 František Kučera (frantovo.cz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package cz.frantovo.copyImageResizer; + +/** + * Some problem with resizing particular image. + * + * @author Ing. František Kučera (frantovo.cz) + */ +public class ResizeException extends CopyImageResizerException { + + public ResizeException() { + } + + public ResizeException(String message) { + super(message); + } + + public ResizeException(Throwable cause) { + super(cause); + } + + public ResizeException(String message, Throwable cause) { + super(message, cause); + } + +} diff -r f3b4caf1d05d -r 5019e3e93a4e java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIOptions.java --- a/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIOptions.java Sun Nov 16 21:59:13 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -/** - * copy-image-resizer - * Copyright © 2014 František Kučera (frantovo.cz) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package cz.frantovo.copyImageResizer.cli; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; - -/** - * - * @author Ing. František Kučera (frantovo.cz) - */ -public class CLIOptions { - - /** - * Source directory - */ - private File input; - /** - * Output directory - */ - private File output; - /** - * Image resolutions to create - */ - private final Collection sizes = new ArrayList<>(); - - public File getSourceDir() { - return input; - } - - public void setInput(File input) { - this.input = input; - } - - public File getDestinationDir() { - return output; - } - - public void setOutput(File output) { - this.output = output; - } - - public Collection getSizes() { - return sizes; - } - - public void addSize(SizeSpecification size) { - sizes.add(size); - } - - public static class SizeSpecification { - - private final int width; - private final int height; - private final String directory; - - public SizeSpecification(int width, int height, String directory) { - this.width = width; - this.height = height; - this.directory = directory; - } - - public int getWidth() { - return width; - } - - public int getHeight() { - return height; - } - - public String getDirectory() { - return directory; - } - } -} diff -r f3b4caf1d05d -r 5019e3e93a4e java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIParser.java --- a/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIParser.java Sun Nov 16 21:59:13 2014 +0100 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIParser.java Sun Nov 16 23:47:28 2014 +0100 @@ -17,6 +17,7 @@ */ package cz.frantovo.copyImageResizer.cli; +import cz.frantovo.copyImageResizer.RecursiveOptions; import java.io.File; import java.util.Arrays; import java.util.Collection; @@ -27,8 +28,8 @@ */ public class CLIParser { - public CLIOptions parseOptions(String[] args) throws CLIParserException { - CLIOptions options = new CLIOptions(); + public RecursiveOptions parseOptions(String[] args) throws CLIParserException { + RecursiveOptions options = new RecursiveOptions(); for (int i = 0; i < args.length; i++) { String arg = args[i]; @@ -63,7 +64,7 @@ INPUT_DIR("--input-dir") { // bash-completion: option @Override - public int parse(String[] args, int index, CLIOptions options) throws CLIParserException { + public int parse(String[] args, int index, RecursiveOptions options) throws CLIParserException { int originalIndex = index; String name = fetchNext(args, ++index); options.setInput(new File(name)); @@ -72,7 +73,7 @@ }, OUTPUT_DIR("--output-dir") { // bash-completion: option @Override - public int parse(String[] args, int index, CLIOptions options) throws CLIParserException { + public int parse(String[] args, int index, RecursiveOptions options) throws CLIParserException { int originalIndex = index; String name = fetchNext(args, ++index); options.setOutput(new File(name)); @@ -81,23 +82,23 @@ }, SIZE("--size") { // bash-completion: option @Override - public int parse(String[] args, int index, CLIOptions options) throws CLIParserException { + public int parse(String[] args, int index, RecursiveOptions options) throws CLIParserException { int originalIndex = index; int width = parseInt(fetchNext(args, ++index)); int height = parseInt(fetchNext(args, ++index)); String directory = width + "x" + height; - options.addSize(new CLIOptions.SizeSpecification(width, height, directory)); + options.addSize(new RecursiveOptions.SizeSpecification(width, height, directory)); return index - originalIndex; } }, SIZE_NAMED("--size-named") { // bash-completion: option @Override - public int parse(String[] args, int index, CLIOptions options) throws CLIParserException { + public int parse(String[] args, int index, RecursiveOptions options) throws CLIParserException { int originalIndex = index; int width = parseInt(fetchNext(args, ++index)); int height = parseInt(fetchNext(args, ++index)); String directory = fetchNext(args, ++index); - options.addSize(new CLIOptions.SizeSpecification(width, height, directory)); + options.addSize(new RecursiveOptions.SizeSpecification(width, height, directory)); return index - originalIndex; } }; @@ -134,6 +135,6 @@ * return 0, otherwise return positive integer: number of eaten arguments. * @throws CLIParserException */ - public abstract int parse(String[] args, int index, CLIOptions options) throws CLIParserException; + public abstract int parse(String[] args, int index, RecursiveOptions options) throws CLIParserException; } } diff -r f3b4caf1d05d -r 5019e3e93a4e java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIStarter.java --- a/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIStarter.java Sun Nov 16 21:59:13 2014 +0100 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIStarter.java Sun Nov 16 23:47:28 2014 +0100 @@ -17,18 +17,35 @@ */ package cz.frantovo.copyImageResizer.cli; +import cz.frantovo.copyImageResizer.RecursiveException; +import cz.frantovo.copyImageResizer.RecursiveImageResizer; +import cz.frantovo.copyImageResizer.RecursiveOptions; +import cz.frantovo.copyImageResizer.ResizeException; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * * @author Ing. František Kučera (frantovo.cz) */ public class CLIStarter { - /** - * @param args the command line arguments - */ + private static final Logger log = Logger.getLogger(CLIStarter.class.getName()); + public static void main(String[] args) { - // TODO code application logic here - System.out.println("TODO"); + + try { + CLIParser parser = new CLIParser(); + RecursiveOptions options = parser.parseOptions(args); + RecursiveImageResizer resizer = new RecursiveImageResizer(); + resizer.resize(options); + } catch (CLIParserException e) { + log.log(Level.SEVERE, "Unable to parse CLI options", e); + } catch (RecursiveException e) { + log.log(Level.SEVERE, "Error while processing filesystem hierarchy", e); + } catch (ResizeException e) { + log.log(Level.SEVERE, "Error while resizing image", e); + } } - + }