| 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 | * @version 1.0 |
|---|
| 32 | * @created 08-Nov-2007 13:06:28 |
|---|
| 33 | */ |
|---|
| 34 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 35 | @XmlType(name = "ImageFile", propOrder = { |
|---|
| 36 | "height", |
|---|
| 37 | "width" |
|---|
| 38 | }) |
|---|
| 39 | @XmlRootElement(name = "ImageFile") |
|---|
| 40 | @Entity |
|---|
| 41 | @Audited |
|---|
| 42 | public class ImageFile extends MediaRepresentationPart { |
|---|
| 43 | private static final long serialVersionUID = 5451418445009559953L; |
|---|
| 44 | private static final Logger logger = Logger.getLogger(ImageFile.class); |
|---|
| 45 | |
|---|
| 46 | //image height in pixel |
|---|
| 47 | @XmlElement(name = "Height") |
|---|
| 48 | private int height; |
|---|
| 49 | |
|---|
| 50 | //image width in pixel |
|---|
| 51 | @XmlElement(name = "Width") |
|---|
| 52 | private int width; |
|---|
| 53 | |
|---|
| 54 | public static ImageFile NewInstance(URI uri, Integer size){ |
|---|
| 55 | logger.debug("NewInstance"); |
|---|
| 56 | return new ImageFile(uri, size); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | public static ImageFile NewInstance(URI uri, Integer size, Integer height, Integer width){ |
|---|
| 60 | return new ImageFile(uri, size, height, width); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | public static ImageFile NewInstance(URI uri, Integer size, ImageInfo imageInfo){ |
|---|
| 64 | ImageFile imageFile = NewInstance(uri, size); |
|---|
| 65 | |
|---|
| 66 | if(imageInfo != null){ |
|---|
| 67 | imageFile.setHeight(imageInfo.getHeight()); |
|---|
| 68 | imageFile.setWidth(imageInfo.getWidth()); |
|---|
| 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 | |
|---|
| 98 | |
|---|
| 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 | public Integer getHeight(){ |
|---|
| 119 | return this.height; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | /** |
|---|
| 123 | * |
|---|
| 124 | * @param height height |
|---|
| 125 | */ |
|---|
| 126 | public void setHeight(Integer height){ |
|---|
| 127 | this.height = height; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | public Integer getWidth(){ |
|---|
| 131 | return this.width; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | /** |
|---|
| 135 | * |
|---|
| 136 | * @param width width |
|---|
| 137 | */ |
|---|
| 138 | public void setWidth(Integer width){ |
|---|
| 139 | this.width = width; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | } |
|---|