Project

General

Profile

Download (3.57 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.cdm.model.media;
11

    
12

    
13
import java.net.URI;
14
import java.time.ZonedDateTime;
15

    
16
import javax.persistence.Entity;
17
import javax.xml.bind.annotation.XmlAccessType;
18
import javax.xml.bind.annotation.XmlAccessorType;
19
import javax.xml.bind.annotation.XmlElement;
20
import javax.xml.bind.annotation.XmlRootElement;
21
import javax.xml.bind.annotation.XmlType;
22

    
23
import org.apache.log4j.Logger;
24
import org.hibernate.envers.Audited;
25

    
26
import eu.etaxonomy.cdm.common.media.ImageInfo;
27
import eu.etaxonomy.cdm.model.agent.AgentBase;
28

    
29
/**
30
 * @author m.doering
31
 * @created 08-Nov-2007 13:06:28
32
 */
33
@XmlAccessorType(XmlAccessType.FIELD)
34
@XmlType(name = "ImageFile", propOrder = {
35
    "height",
36
    "width"
37
})
38
@XmlRootElement(name = "ImageFile")
39
@Entity
40
@Audited
41
public class ImageFile extends MediaRepresentationPart {
42
	private static final long serialVersionUID = 5451418445009559953L;
43
	private static final Logger logger = Logger.getLogger(ImageFile.class);
44

    
45
	//image height in pixel
46
	@XmlElement(name = "Height")
47
	private int height;
48

    
49
	//image width in pixel
50
	@XmlElement(name = "Width")
51
	private int width;
52

    
53
	public static ImageFile NewInstance(URI uri, Integer size){
54
		logger.debug("NewInstance");
55
		return new ImageFile(uri, size);
56
	}
57

    
58
	public static ImageFile NewInstance(URI uri, Integer size, Integer height, Integer width){
59
		return new ImageFile(uri, size, height, width);
60
	}
61

    
62
	public static ImageFile NewInstance(URI uri, Integer size, ImageInfo imageInfo){
63
		ImageFile imageFile = NewInstance(uri, size);
64

    
65
		if(imageInfo != null){
66
			imageFile.setHeight(imageInfo.getHeight());
67
			imageFile.setWidth(imageInfo.getWidth());
68
		}
69

    
70
		return imageFile;
71
	}
72

    
73
	/**
74
	 * Generated an instance of Media that contains one MediaRepresentation consisting of one ImageFile
75
	 * @param mimeType the MimeType
76
	 * @param suffix the file suffix (e.g. jpg, png, ...
77
	 * @param mediaCreated creation date of the media
78
	 * @param artist artist that created this media
79
	 * @param uri the uri of the image file
80
	 * @param size the size of the image file
81
	 * @param height the height of the image file
82
	 * @param width the width of the image file
83
	 * @return
84
	 */
85
	public static Media NewMediaInstance(ZonedDateTime mediaCreated, AgentBase artist, URI uri, String mimeType, String suffix, Integer size, Integer height, Integer width){
86
		Media media = Media.NewInstance();
87
		media.setMediaCreated(mediaCreated);
88
		media.setArtist(artist);
89
		MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance(mimeType, suffix);
90
		media.addRepresentation(mediaRepresentation);
91
		ImageFile image = ImageFile.NewInstance(uri, size, height, size);
92
		mediaRepresentation.addRepresentationPart(image);
93
		return media;
94
	}
95

    
96
	// *********************** CONSTRUCTOR ****************************/
97

    
98
	protected ImageFile(){
99
		super();
100
	}
101

    
102
	protected ImageFile(URI uri, Integer size){
103
		super(uri, size);
104
	}
105

    
106
	protected ImageFile(URI uri, Integer size, Integer height, Integer width){
107
		super(uri, size);
108
		if (height != null){
109
			this.setHeight(height);
110
		}
111
		if (width != null){
112
			this.setWidth(width);
113
		}
114
	}
115

    
116
	// *********************** GETTER /SETTER ****************************/
117

    
118
	public Integer getHeight(){
119
		return this.height;
120
	}
121
	public void setHeight(Integer height){
122
		this.height = height;
123
	}
124

    
125
	public Integer getWidth(){
126
		return this.width;
127
	}
128
	public void setWidth(Integer width){
129
		this.width = width;
130
	}
131
}
(5-5/13)