Project

General

Profile

Download (3.71 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 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

    
23
import eu.etaxonomy.cdm.common.URI;
24
import eu.etaxonomy.cdm.common.media.CdmImageInfo;
25
import eu.etaxonomy.cdm.model.agent.AgentBase;
26
import eu.etaxonomy.cdm.model.common.TimePeriod;
27

    
28
/**
29
 * @author m.doering
30
 * @since 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(URI uri, Integer size){
53
		logger.debug("NewInstance");
54
		return new ImageFile(uri, size);
55
	}
56

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

    
61
	public static ImageFile NewInstance(URI uri, Integer size, CdmImageInfo cdmImageInfo){
62
		ImageFile imageFile = NewInstance(uri, size);
63

    
64
		if(cdmImageInfo != null){
65
			imageFile.setHeight(cdmImageInfo.getHeight());
66
			imageFile.setWidth(cdmImageInfo.getWidth());
67
			if(cdmImageInfo.getLength() != 0){
68
			    imageFile.setSize((int)cdmImageInfo.getLength());
69
			}
70
		}
71

    
72
		return imageFile;
73
	}
74

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

    
98
	// *********************** CONSTRUCTOR ****************************/
99

    
100
	protected ImageFile(){
101
		super();
102
	}
103

    
104
	protected ImageFile(URI uri, Integer size){
105
		super(uri, size);
106
	}
107

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

    
118
	// *********************** GETTER /SETTER ****************************/
119

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

    
127
	public Integer getWidth(){
128
		return this.width;
129
	}
130
	public void setWidth(Integer width){
131
		this.width = width;
132
	}
133
}
(7-7/16)