Project

General

Profile

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

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

    
22
import org.apache.log4j.Logger;
23
import org.hibernate.envers.Audited;
24
import org.joda.time.DateTime;
25

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

    
29
/**
30
 * @author m.doering
31
 * @since 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
//			imageFile.setSize((int)imageInfo.getLength());
69
		}
70

    
71
		return imageFile;
72
	}
73

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

    
97
	// *********************** CONSTRUCTOR ****************************/
98

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

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

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

    
117
	// *********************** GETTER /SETTER ****************************/
118

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

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