~berthold-daum/zora/trunk

« back to all changes in this revision

Viewing changes to com.bdaum.zoom.recipes.c1/src/com/bdaum/zoom/recipes/c1/internal/C1Detector.java

  • Committer: bdaum
  • Date: 2015-12-26 10:21:51 UTC
  • Revision ID: berthold.daum@bdaum.de-20151226102151-44f1j5113167thb9
VersionĀ 2.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
import com.bdaum.zoom.cat.model.meta.WatchedFolder;
45
45
import com.bdaum.zoom.core.AbstractRecipeDetector;
 
46
import com.bdaum.zoom.core.Core;
46
47
import com.bdaum.zoom.core.IRecipeDetector;
47
48
import com.bdaum.zoom.core.QueryField;
48
49
import com.bdaum.zoom.image.IFileHandler;
56
57
import com.bdaum.zoom.image.recipe.Rotation;
57
58
import com.bdaum.zoom.image.recipe.UnsharpMask;
58
59
import com.bdaum.zoom.image.recipe.Vignette;
 
60
import com.bdaum.zoom.program.BatchUtilities;
 
61
import com.bdaum.zoom.program.DiskFullException;
59
62
 
60
63
public class C1Detector extends AbstractRecipeDetector {
61
64
        private static final String EIP = ".EIP"; //$NON-NLS-1$
201
204
                                        }
202
205
                                });
203
206
                        }
204
 
                        loadRecipeFiles(recipeFiles, focalLengthProvider, overlayMap);
205
 
                } catch (URISyntaxException e) {
206
 
                        // do nothing
 
207
                        loadRecipeFiles(recipeFiles.toArray(new File[recipeFiles.size()]),
 
208
                                        focalLengthProvider, overlayMap);
207
209
                } catch (IOException e) {
208
210
                        C1Activator.getDefault().logError(
209
211
                                        NLS.bind(Messages.C1Detector_io_error, uri), e);
210
 
                }
211
 
                return null;
212
 
        }
213
 
 
214
 
        private Recipe loadRecipeFiles(List<File> recipeFiles,
 
212
                } catch (URISyntaxException e) {
 
213
                        // do nothing
 
214
                }
 
215
                return null;
 
216
        }
 
217
 
 
218
        public File[] getMetafiles(String uri) {
 
219
                try {
 
220
                        List<File> recipeFiles = new ArrayList<File>(3);
 
221
                        File imageFile = new File(new URI(uri));
 
222
                        IFileHandler fileHandler = ImageConstants
 
223
                                        .findFileHandler(imageFile);
 
224
                        if (fileHandler == null) {
 
225
                                String fileName = imageFile.getName();
 
226
                                File folder = imageFile.getParentFile();
 
227
                                for (String c1folder : CAPTURE_ONE_FOLDERS) {
 
228
                                        StringBuilder sb = new StringBuilder();
 
229
                                        sb.append(c1folder).append('/').append(fileName)
 
230
                                                        .append(CAPTURE_ONE_SETTINGS);
 
231
                                        File metaFile = new File(folder, sb.toString());
 
232
                                        if (metaFile.exists())
 
233
                                                recipeFiles.add(metaFile);
 
234
                                }
 
235
                        }
 
236
                        return recipeFiles.toArray(new File[recipeFiles.size()]);
 
237
                } catch (URISyntaxException e) {
 
238
                        // do nothing
 
239
                }
 
240
                return null;
 
241
        }
 
242
 
 
243
        public void archiveRecipes(File targetFolder, String uri, String newUri,
 
244
                        boolean readOnly) throws IOException, DiskFullException {
 
245
                try {
 
246
                        File imageFile = new File(new URI(uri));
 
247
                        IFileHandler fileHandler = ImageConstants
 
248
                                        .findFileHandler(imageFile);
 
249
                        if (fileHandler == null) {
 
250
                                String fileName = imageFile.getName();
 
251
                                File folder = imageFile.getParentFile();
 
252
                                for (String c1folder : CAPTURE_ONE_FOLDERS) {
 
253
                                        StringBuilder sb = new StringBuilder();
 
254
                                        sb.append(c1folder).append('/').append(fileName)
 
255
                                                        .append(CAPTURE_ONE_SETTINGS);
 
256
                                        File metaFile = new File(folder, sb.toString());
 
257
                                        if (metaFile.exists()) {
 
258
                                                String newFileName = Core.getFileName(newUri, false);
 
259
                                                File cosFolder = new File(targetFolder, c1folder);
 
260
                                                cosFolder.mkdirs();
 
261
                                                File targetFile = new File(cosFolder, newFileName
 
262
                                                                + CAPTURE_ONE_SETTINGS);
 
263
                                                BatchUtilities.copyFile(metaFile, targetFile, null);
 
264
                                                if (readOnly)
 
265
                                                        targetFile.setReadOnly();
 
266
                                        }
 
267
                                }
 
268
                        }
 
269
                } catch (URISyntaxException e) {
 
270
                        // do nothing
 
271
                }
 
272
        }
 
273
 
 
274
        private Recipe loadRecipeFiles(File[] recipeFiles,
215
275
                        IFocalLengthProvider focalLengthProvider,
216
276
                        final Map<String, String> overlayMap) throws IOException {
217
277
                recipe = null;
374
434
                                                                                                        QueryField.CONTACT_STATE,
375
435
                                                                                                        value);
376
436
                                                                                } else if ("Contact_Postalcode" == key) { //$NON-NLS-1$
377
 
                                                                                        addStructField(contact,
 
437
                                                                                        addStructField(
 
438
                                                                                                        contact,
378
439
                                                                                                        QueryField.CONTACT_POSTALCODE,
379
440
                                                                                                        value);
380
441
                                                                                } else if ("Contact_Country" == key) { //$NON-NLS-1$
424
485
                                                                                                                        .getExifToolKey(),
425
486
                                                                                                        value);
426
487
                                                                                } else if ("Image_Location" == key) { //$NON-NLS-1$
427
 
                                                                                        addStructField(location,
 
488
                                                                                        addStructField(
 
489
                                                                                                        location,
428
490
                                                                                                        QueryField.LOCATION_DETAILS,
429
491
                                                                                                        value);
430
492
                                                                                } else if ("Image_City" == key) { //$NON-NLS-1$
436
498
                                                                                                        QueryField.LOCATION_STATE,
437
499
                                                                                                        value);
438
500
                                                                                } else if ("Image_Country" == key) { //$NON-NLS-1$
439
 
                                                                                        addStructField(location,
 
501
                                                                                        addStructField(
 
502
                                                                                                        location,
440
503
                                                                                                        QueryField.LOCATION_COUNTRYNAME,
441
504
                                                                                                        value);
442
505
                                                                                } else if ("Image_Isocountrycode" == key) { //$NON-NLS-1$
443
 
                                                                                        addStructField(location,
 
506
                                                                                        addStructField(
 
507
                                                                                                        location,
444
508
                                                                                                        QueryField.LOCATION_COUNTRYCODE,
445
509
                                                                                                        value);
446
510
                                                                                } else if ("Status_Title" == key) { //$NON-NLS-1$
489
553
                                                                                                                        .getExifToolKey(),
490
554
                                                                                                                        value);
491
555
                                                                                } else if ("getty_OriginalFileName" == key) { //$NON-NLS-1$
492
 
                                                                                        addStructField(artwork,
 
556
                                                                                        addStructField(
 
557
                                                                                                        artwork,
493
558
                                                                                                        QueryField.ARTWORKOROBJECT_TITLE,
494
559
                                                                                                        value);
495
560
                                                                                } else if ("getty_ParentMEID" == key) { //$NON-NLS-1$
640
705
                                        saxParser.parse(in, handler);
641
706
                                        if (overlayMap != null) {
642
707
                                                setStruct(overlayMap, QueryField.IPTC_CONTACT, contact);
643
 
                                                setStruct(overlayMap, QueryField.IPTC_LOCATIONSHOWN, location);
 
708
                                                setStruct(overlayMap, QueryField.IPTC_LOCATIONSHOWN,
 
709
                                                                location);
644
710
                                                setStruct(overlayMap, QueryField.IPTC_ARTWORK, artwork);
645
711
                                        }
646
712
                                } catch (ParserConfigurationException e) {
1156
1222
                        IFocalLengthProvider focalLengthProvider,
1157
1223
                        Map<String, String> overlayMap) {
1158
1224
                if (uri.toLowerCase().endsWith(CAPTURE_ONE_SETTINGS)) {
1159
 
                        List<File> files = new ArrayList<File>(1);
1160
1225
                        try {
1161
 
                                files.add(new File(new URI(uri)));
1162
 
                                return loadRecipeFiles(files, focalLengthProvider, overlayMap);
 
1226
                                return loadRecipeFiles(new File[] { new File(new URI(uri)) },
 
1227
                                                focalLengthProvider, overlayMap);
1163
1228
                        } catch (URISyntaxException e) {
1164
1229
                                C1Activator.getDefault().logError(
1165
1230
                                                NLS.bind(Messages.C1Detector_bad_uri, uri), e);
1170
1235
                }
1171
1236
                return null;
1172
1237
        }
 
1238
 
1173
1239
}