| 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 | import java.net.URI; |
|---|
| 13 | |
|---|
| 14 | import javax.persistence.Entity; |
|---|
| 15 | import javax.persistence.FetchType; |
|---|
| 16 | import javax.persistence.ManyToOne; |
|---|
| 17 | import javax.validation.constraints.Pattern; |
|---|
| 18 | import javax.xml.bind.annotation.XmlAccessType; |
|---|
| 19 | import javax.xml.bind.annotation.XmlAccessorType; |
|---|
| 20 | import javax.xml.bind.annotation.XmlElement; |
|---|
| 21 | import javax.xml.bind.annotation.XmlIDREF; |
|---|
| 22 | import javax.xml.bind.annotation.XmlRootElement; |
|---|
| 23 | import javax.xml.bind.annotation.XmlSchemaType; |
|---|
| 24 | import javax.xml.bind.annotation.XmlType; |
|---|
| 25 | |
|---|
| 26 | import org.apache.log4j.Logger; |
|---|
| 27 | import org.hibernate.annotations.Cascade; |
|---|
| 28 | import org.hibernate.annotations.CascadeType; |
|---|
| 29 | import org.hibernate.annotations.Type; |
|---|
| 30 | import org.hibernate.envers.Audited; |
|---|
| 31 | import org.hibernate.search.annotations.Field; |
|---|
| 32 | import org.hibernate.validator.constraints.Length; |
|---|
| 33 | |
|---|
| 34 | import eu.etaxonomy.cdm.model.agent.AgentBase; |
|---|
| 35 | import eu.etaxonomy.cdm.model.common.Language; |
|---|
| 36 | import eu.etaxonomy.cdm.model.common.LanguageStringBase; |
|---|
| 37 | import eu.etaxonomy.cdm.validation.Level2; |
|---|
| 38 | import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty; |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | * Typically, rights information includes a statement about various property |
|---|
| 42 | * rights associated with the resource, including intellectual property rights. |
|---|
| 43 | * http://purl.org/dc/elements/1.1/rights http://dublincore.org/documents/dcmi- |
|---|
| 44 | * terms/ |
|---|
| 45 | * @author m.doering |
|---|
| 46 | * @version 1.0 |
|---|
| 47 | * @created 08-Nov-2007 13:06:49 |
|---|
| 48 | */ |
|---|
| 49 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 50 | @XmlType(name = "Rights", propOrder = { |
|---|
| 51 | "uri", |
|---|
| 52 | "abbreviatedText", |
|---|
| 53 | "type", |
|---|
| 54 | "agent" |
|---|
| 55 | }) |
|---|
| 56 | @XmlRootElement(name = "Rights") |
|---|
| 57 | @Entity |
|---|
| 58 | @Audited |
|---|
| 59 | public class Rights extends LanguageStringBase implements Cloneable{ |
|---|
| 60 | private static final long serialVersionUID = 4920749849951432284L; |
|---|
| 61 | private static final Logger logger = Logger.getLogger(Rights.class); |
|---|
| 62 | |
|---|
| 63 | //external location of copyright text |
|---|
| 64 | @XmlElement(name = "URI") |
|---|
| 65 | @Field(index=org.hibernate.search.annotations.Index.UN_TOKENIZED) |
|---|
| 66 | @NullOrNotEmpty |
|---|
| 67 | @Length(max = 255) |
|---|
| 68 | @Pattern(regexp = "^([a-z0-9+.-]+):(?://(?:((?:[a-z0-9-._~!$&'()*+,;=:]|%[0-9A-F]{2})*)@)?((?:[a-z0-9-._~!$&'()*+,;=]|%[0-9A-F]{2})*)(?::(\\d*))?(/(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9A-F]{2})*)?|(/?(?:[a-z0-9-._~!$&'()*+,;=:@]|%[0-9A-F]{2})+(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9A-F]{2})*)?)(?:\\?((?:[a-z0-9-._~!$&'()*+,;=:/?@]|%[0-9A-F]{2})*))?(?:#((?:[a-z0-9-._~!$&'()*+,;=:/?@]|%[0-9A-F]{2})*))?$", groups = Level2.class, message = "{eu.etaxonomy.cdm.model.reference.Reference.uri.message}") |
|---|
| 69 | @Type(type="uriUserType") |
|---|
| 70 | private URI uri; |
|---|
| 71 | |
|---|
| 72 | @XmlElement(name = "AbbreviatedText") |
|---|
| 73 | private String abbreviatedText; |
|---|
| 74 | |
|---|
| 75 | @XmlElement(name = "Type") |
|---|
| 76 | @XmlIDREF |
|---|
| 77 | @XmlSchemaType(name = "IDREF") |
|---|
| 78 | @ManyToOne(fetch = FetchType.LAZY) |
|---|
| 79 | private RightsTerm type; |
|---|
| 80 | |
|---|
| 81 | // owner etc as defined by the rightstype |
|---|
| 82 | @XmlElement(name = "Agent") |
|---|
| 83 | @XmlIDREF |
|---|
| 84 | @XmlSchemaType(name = "IDREF") |
|---|
| 85 | @ManyToOne(fetch = FetchType.LAZY) |
|---|
| 86 | @Cascade(CascadeType.SAVE_UPDATE) |
|---|
| 87 | private AgentBase agent; |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | /** |
|---|
| 91 | * Factory method |
|---|
| 92 | * @return |
|---|
| 93 | */ |
|---|
| 94 | public static Rights NewInstance() { |
|---|
| 95 | logger.debug("NewInstance"); |
|---|
| 96 | return new Rights(); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | /** |
|---|
| 100 | * Factory method |
|---|
| 101 | * @return |
|---|
| 102 | */ |
|---|
| 103 | public static Rights NewInstance(String text, Language language) { |
|---|
| 104 | return new Rights(text, language); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | /** |
|---|
| 108 | * Default Constructor |
|---|
| 109 | */ |
|---|
| 110 | protected Rights() { |
|---|
| 111 | super(); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | /** |
|---|
| 115 | * Constructor |
|---|
| 116 | */ |
|---|
| 117 | protected Rights(String text, Language language) { |
|---|
| 118 | super(text, language); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | public RightsTerm getType(){ |
|---|
| 122 | return this.type; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | public void setType(RightsTerm type){ |
|---|
| 126 | this.type = type; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | public URI getUri(){ |
|---|
| 130 | return this.uri; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | public void setUri(URI uri){ |
|---|
| 134 | this.uri = uri; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | public String getAbbreviatedText(){ |
|---|
| 138 | return this.abbreviatedText; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | public void setAbbreviatedText(String abbreviatedStatement){ |
|---|
| 142 | this.abbreviatedText = abbreviatedStatement; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | public AgentBase getAgent() { |
|---|
| 146 | return agent; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | public void setAgent(AgentBase agent) { |
|---|
| 150 | this.agent = agent; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | //************************* CLONE **************************/ |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | /* (non-Javadoc) |
|---|
| 157 | * @see java.lang.Object#clone() |
|---|
| 158 | */ |
|---|
| 159 | @Override |
|---|
| 160 | public Object clone() throws CloneNotSupportedException{ |
|---|
| 161 | Rights result = (Rights)super.clone(); |
|---|
| 162 | //no changes to: type, agent |
|---|
| 163 | return result; |
|---|
| 164 | } |
|---|
| 165 | } |
|---|