System.out.println(InfoConstants.LICENSE);
System.exit(0);
}
/* initialization */
PictureBox pictureBox = null;
/* get picture folder */
File dir;
if (line.hasOption("d")) {
dir = new File(line.getOptionValue("d"));
/* load picture folder */
try {
logger.log(Level.FINE, "directory: "
+ dir.getCanonicalPath());
pictureBox = new PictureBox(dir);
} catch (FileNotFoundException fnfe) {
logger.log(Level.WARNING, fnfe.getMessage(), fnfe);
System.out.println("The directory " + dir.getAbsolutePath()
+ " doesn't exist.");
System.exit(0);
} catch (IOException ioe) {
logger.log(Level.WARNING,
"error while loading files from directory", ioe);
}
/* print only pictures */
if (!line.hasOption("a")) {
System.out.println(pictureBox
.getPicturesAsString(PictureBox.FORMAT_TXT));
}
/* catch address and print them */
if (line.hasOption("a")) {
try {
if (line.hasOption("k")) {
logger.log(Level.FINE,
"an individual Google Maps API key is used: "
+ line.getOptionValue("k"));
System.out
.println("An individual Google Maps API key is used: "
+ line.getOptionValue("k") + ".");
pictureBox.catchAddresses(new GoogleMapsReader(line
.getOptionValue("k")), new ProgressCli(
"Catch addresses from Google Maps"));
} else {
pictureBox
.catchAddresses(
new GoogleMapsReader(),
new ProgressCli(
"Catch addresses from Google Maps"));
}
/* print pictures */
System.out.println(pictureBox
.getPicturesAsString(PictureBox.FORMAT_TXT));
} catch (UnknownHostException uhe) {
logger.log(Level.WARNING, uhe.getMessage(), uhe);
System.out
.println("An error occured while connecting to Google Maps "
+ "(maybe there is no Internet connection).");
}
/* write caught addresses to picture files */
if (line.hasOption("w")) {
logger.log(Level.FINE,
"write caught addresses (field '"
+ line.getOptionValue("w") + "')");
ExifToolWriter writer = new ExifToolWriter();
if (line.hasOption("b")) {
writer.setBackupMode(false);
}
if (line.hasOption("p")) {
System.out.println("Setting "
+ line.getOptionValue("p")
+ " as path to ExifTool...");
try {
writer
.setExifToolPath(line
.getOptionValue("p"));
} catch (IOException ioe) {
System.out
.println("An error occured while setting the ExifToolPath: "
+ ioe.getMessage());
}
}
/* find out field */
int field = InfoConstants.IMAGE_DESCRIPTION;
if (line.getOptionValue("w").contains(WRITE_TO_COMMENT)) {
field = InfoConstants.USER_COMMENT;
}
/* write data */
pictureBox.writeAddresses(writer, field,
new ProgressCli(
"Writing addresses to picture files"));
}
}
/* export to text file */
if (line.hasOption("e")) {
File exportFile = new File(line.getOptionValue("e"));
logger.log(Level.FINE, "Picture data will be exported to "
+ exportFile.getName() + ".");
System.out.println("Picture data will be exported to "
+ exportFile.getName() + ".");
try {
pictureBox.saveToFile(exportFile,
PictureBox.FORMAT_TXT_OS);
} catch (IOException ioe) {
logger
.log(
Level.WARNING,