+ break;
+ }
+ case LOAD_PHOTO: {
+ for (String file : files) {
+ try {
+ Card card = getCard(file, null).getCard();
+ for (Contact contact : card) {
+ String filename = contact.toString(format, "");
+ File f = new File(dir, filename);
+
+ if (f.exists()) {
+ System.out.println("Loading " + f);
+ try {
+ String type = "jpeg";
+ int dotIndex = filename.indexOf('.');
+ if (dotIndex >= 0
+ && (dotIndex + 1) < filename.length()) {
+ type = filename.substring(dotIndex + 1)
+ .toLowerCase();
+ }
+
+ String b64 = StringUtils.fromImage(f);
+
+ // remove previous photos:
+ for (Data photo = contact
+ .getPreferredData("PHOTO"); photo != null; photo = contact
+ .getPreferredData("PHOTO")) {
+ photo.delete();
+ }
+ //
+
+ List<TypeInfo> types = new LinkedList<TypeInfo>();
+ types.add(new TypeInfo("ENCODING", "b"));
+ types.add(new TypeInfo("TYPE", type));
+ Data photo = new Data(types, "PHOTO", b64, null);
+ contact.add(photo);
+ } catch (IOException e) {
+ System.err.println("Cannot read photo: "
+ + filename);
+ }
+ }
+ }
+ card.save();
+ } catch (IOException e) {
+ System.err
+ .println(trans(StringId.CLI_ERR_CANNOT_OPEN, file));
+ }
+ }
+ break;
+ }
+ case SAVE_PHOTO: {
+ for (String file : files) {
+ try {
+ Card card = getCard(file, null).getCard();
+ for (Contact contact : card) {
+ Data photo = contact.getPreferredData("PHOTO");
+ if (photo != null) {
+ String filename = contact.toString(format, "");
+ File f = new File(dir, filename + ".png");
+ System.out.println("Saving " + f);
+ try {
+ ImageIO.write(
+ StringUtils.toImage(photo.getValue()),
+ "png", f);
+ } catch (IOException e) {
+ System.err.println(trans(
+ StringId.CLI_ERR_CANNOT_SAVE_PHOTO,
+ contact.getPreferredDataValue("FN")));
+ }
+ }
+ }
+ } catch (IOException e) {
+ System.err
+ .println(trans(StringId.CLI_ERR_CANNOT_OPEN, file));
+ }
+ }
+ break;
+ }
+ case CONTACT_MANAGER: {