Project

General

Profile

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

    
25
import eu.etaxonomy.cdm.common.media.CdmImageInfo;
26
import eu.etaxonomy.cdm.model.agent.AgentBase;
27
import eu.etaxonomy.cdm.model.common.TimePeriod;
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, CdmImageInfo cdmImageInfo){
63
		ImageFile imageFile = NewInstance(uri, size);
64

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

    
73
		return imageFile;
74
	}
75

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

    
99
	// *********************** CONSTRUCTOR ****************************/
100

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

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

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

    
119
	// *********************** GETTER /SETTER ****************************/
120

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

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