Project

General

Profile

Download (2.11 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2021 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.api.service.media;
10

    
11
import java.io.IOException;
12
import java.util.ArrayList;
13
import java.util.List;
14

    
15
import org.apache.http.HttpException;
16
import org.springframework.stereotype.Component;
17

    
18
import eu.etaxonomy.cdm.common.URI;
19
import eu.etaxonomy.cdm.common.media.CdmImageInfo;
20

    
21
/**
22
 * @author a.kohlbecker
23
 * @since May 5, 2021
24
 */
25
@Component
26
public class MediaInfoFactory {
27

    
28
    /**
29
     * TODO needs to be managed in CDM PREFERENCES
30
     */
31
    private List<MediaUriTransformation> uriTransformations = new ArrayList<>();
32

    
33
    /**
34
     * TODO needs to be managed in CDM PREFERENCES
35
     *
36
     * Transformation from
37
     * https://pictures.bgbm.org/digilib/Scaler?fn=Cyprus/Sisymbrium_aegyptiacum_C1.jpg&mo=file
38
     *  to
39
     * https://image.bgbm.org/metadata/info?file=Cyprus/Sisymbrium_aegyptiacum_C1.jpg
40
     */
41
    private MediaUriTransformation bgbmMediaMetadataService() {
42
        MediaUriTransformation mut = new MediaUriTransformation();
43
        mut.setHost(new SearchReplace("pictures.bgbm.org", "image.bgbm.org"));
44
        mut.setPathQueryFragment(new SearchReplace("(digilib\\/Scaler\\?fn=)([^&]+)(&mo=file)", "file=$2"));
45
        return mut;
46
    }
47

    
48
    public MediaInfoFactory() {
49
        uriTransformations.add(bgbmMediaMetadataService());
50
    }
51

    
52
    public CdmImageInfo cdmImageInfoWithMetaData(URI imageUri) throws IOException, HttpException {
53
        return new MediaMedadataFileReader(imageUri)
54
               .readSuffix()
55
               .readImageLength()
56
               .readImageInfo()
57
               .readMetaData()
58
               .getCdmImageInfo();
59

    
60
    }
61

    
62
    public CdmImageInfo cdmImageInfo(URI imageUri) throws IOException, HttpException {
63
        return new MediaMedadataFileReader(imageUri)
64
                .readSuffix()
65
                .readImageLength()
66
                .readImageInfo()
67
                .getCdmImageInfo();
68

    
69
    }
70

    
71

    
72

    
73

    
74

    
75
}
(2-2/6)