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 javax.persistence.Entity;
|
14
|
import javax.xml.bind.annotation.XmlAccessType;
|
15
|
import javax.xml.bind.annotation.XmlAccessorType;
|
16
|
import javax.xml.bind.annotation.XmlElement;
|
17
|
import javax.xml.bind.annotation.XmlRootElement;
|
18
|
import javax.xml.bind.annotation.XmlType;
|
19
|
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.hibernate.envers.Audited;
|
22
|
import org.joda.time.DateTime;
|
23
|
|
24
|
import eu.etaxonomy.cdm.common.MediaMetaData.ImageMetaData;
|
25
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
26
|
|
27
|
/**
|
28
|
* @author m.doering
|
29
|
* @version 1.0
|
30
|
* @created 08-Nov-2007 13:06:28
|
31
|
*/
|
32
|
@XmlAccessorType(XmlAccessType.FIELD)
|
33
|
@XmlType(name = "ImageFile", propOrder = {
|
34
|
"height",
|
35
|
"width"
|
36
|
})
|
37
|
@XmlRootElement(name = "ImageFile")
|
38
|
@Entity
|
39
|
@Audited
|
40
|
public class ImageFile extends MediaRepresentationPart {
|
41
|
private static final long serialVersionUID = 5451418445009559953L;
|
42
|
private static final Logger logger = Logger.getLogger(ImageFile.class);
|
43
|
|
44
|
//image height in pixel
|
45
|
@XmlElement(name = "Height")
|
46
|
private int height;
|
47
|
|
48
|
//image width in pixel
|
49
|
@XmlElement(name = "Width")
|
50
|
private int width;
|
51
|
|
52
|
public static ImageFile NewInstance(String uri, Integer size){
|
53
|
logger.debug("NewInstance");
|
54
|
return new ImageFile(uri, size);
|
55
|
}
|
56
|
|
57
|
public static ImageFile NewInstance(String uri, Integer size, Integer height, Integer width){
|
58
|
return new ImageFile(uri, size, height, width);
|
59
|
}
|
60
|
|
61
|
public static ImageFile NewInstance(String uri, Integer size, ImageMetaData imageMetaData){
|
62
|
return new ImageFile(uri, size, imageMetaData.getHeight(), imageMetaData.getWidth());
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* Generated an instance of Media that contains one MediaRepresentation consisting of one ImageFile
|
67
|
* @param mimeType the MimeType
|
68
|
* @param suffix the file suffix (e.g. jpg, png, ...
|
69
|
* @param mediaCreated creation date of the media
|
70
|
* @param artist artist that created this media
|
71
|
* @param uri the uri of the image file
|
72
|
* @param size the size of the image file
|
73
|
* @param height the height of the image file
|
74
|
* @param width the width of the image file
|
75
|
* @return
|
76
|
*/
|
77
|
public static Media NewMediaInstance(DateTime mediaCreated, AgentBase artist, String uri, String mimeType, String suffix, Integer size, Integer height, Integer width){
|
78
|
Media media = Media.NewInstance();
|
79
|
media.setMediaCreated(mediaCreated);
|
80
|
media.setArtist(artist);
|
81
|
MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance(mimeType, suffix);
|
82
|
media.addRepresentation(mediaRepresentation);
|
83
|
ImageFile image = ImageFile.NewInstance(uri, size, height, size);
|
84
|
mediaRepresentation.addRepresentationPart(image);
|
85
|
return media;
|
86
|
}
|
87
|
|
88
|
|
89
|
|
90
|
|
91
|
protected ImageFile(){
|
92
|
super();
|
93
|
}
|
94
|
|
95
|
protected ImageFile(String uri, Integer size){
|
96
|
super(uri, size);
|
97
|
}
|
98
|
|
99
|
protected ImageFile(String uri, Integer size, Integer height, Integer width){
|
100
|
super(uri, size);
|
101
|
if (height != null){
|
102
|
this.setHeight(height);
|
103
|
}
|
104
|
if (width != null){
|
105
|
this.setWidth(width);
|
106
|
}
|
107
|
}
|
108
|
|
109
|
public int getHeight(){
|
110
|
return this.height;
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
*
|
115
|
* @param height height
|
116
|
*/
|
117
|
public void setHeight(int height){
|
118
|
this.height = height;
|
119
|
}
|
120
|
|
121
|
public int getWidth(){
|
122
|
return this.width;
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
*
|
127
|
* @param width width
|
128
|
*/
|
129
|
public void setWidth(int width){
|
130
|
this.width = width;
|
131
|
}
|
132
|
|
133
|
}
|