| 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.common; |
|---|
| 11 | |
|---|
| 12 | import javax.persistence.Column; |
|---|
| 13 | import javax.persistence.FetchType; |
|---|
| 14 | import javax.persistence.Lob; |
|---|
| 15 | import javax.persistence.ManyToOne; |
|---|
| 16 | import javax.persistence.MappedSuperclass; |
|---|
| 17 | import javax.persistence.Transient; |
|---|
| 18 | |
|---|
| 19 | import javax.xml.bind.annotation.XmlAccessType; |
|---|
| 20 | import javax.xml.bind.annotation.XmlAccessorType; |
|---|
| 21 | import javax.xml.bind.annotation.XmlElement; |
|---|
| 22 | import javax.xml.bind.annotation.XmlIDREF; |
|---|
| 23 | import javax.xml.bind.annotation.XmlSchemaType; |
|---|
| 24 | import javax.xml.bind.annotation.XmlSeeAlso; |
|---|
| 25 | import javax.xml.bind.annotation.XmlType; |
|---|
| 26 | import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
|---|
| 27 | |
|---|
| 28 | import org.apache.log4j.Logger; |
|---|
| 29 | import org.hibernate.annotations.CascadeType; |
|---|
| 30 | import org.hibernate.annotations.Cascade; |
|---|
| 31 | import org.hibernate.search.annotations.Field; |
|---|
| 32 | import org.hibernate.search.annotations.FieldBridge; |
|---|
| 33 | import org.hibernate.search.annotations.Index; |
|---|
| 34 | |
|---|
| 35 | import eu.etaxonomy.cdm.hibernate.StripHtmlBridge; |
|---|
| 36 | import eu.etaxonomy.cdm.jaxb.FormattedTextAdapter; |
|---|
| 37 | |
|---|
| 38 | /** |
|---|
| 39 | * @author a.mueller |
|---|
| 40 | * @version 1.0 |
|---|
| 41 | * @created 25.04.2008 |
|---|
| 42 | */ |
|---|
| 43 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 44 | @XmlType(name = "LanguageStringBase", propOrder = { |
|---|
| 45 | "text", |
|---|
| 46 | "language" |
|---|
| 47 | }) |
|---|
| 48 | @XmlSeeAlso({ |
|---|
| 49 | LanguageString.class |
|---|
| 50 | }) |
|---|
| 51 | @MappedSuperclass |
|---|
| 52 | public abstract class LanguageStringBase extends AnnotatableEntity{ |
|---|
| 53 | private static final long serialVersionUID = -1892526642162438277L; |
|---|
| 54 | @SuppressWarnings("unused") |
|---|
| 55 | private static final Logger logger = Logger.getLogger(LanguageStringBase.class); |
|---|
| 56 | |
|---|
| 57 | @XmlElement(name = "Text") |
|---|
| 58 | @XmlJavaTypeAdapter(FormattedTextAdapter.class) |
|---|
| 59 | @Column(length=65536) |
|---|
| 60 | @Field(index=Index.TOKENIZED) |
|---|
| 61 | @FieldBridge(impl=StripHtmlBridge.class) |
|---|
| 62 | @Lob |
|---|
| 63 | protected String text; |
|---|
| 64 | |
|---|
| 65 | @XmlElement(name = "Language") |
|---|
| 66 | @XmlIDREF |
|---|
| 67 | @XmlSchemaType(name = "IDREF") |
|---|
| 68 | @ManyToOne(fetch = FetchType.EAGER) |
|---|
| 69 | @Cascade({CascadeType.MERGE}) |
|---|
| 70 | protected Language language; |
|---|
| 71 | |
|---|
| 72 | protected LanguageStringBase() { |
|---|
| 73 | super(); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | protected LanguageStringBase(String text, Language language) { |
|---|
| 77 | super(); |
|---|
| 78 | this.setLanguage(language); |
|---|
| 79 | this.setText(text); |
|---|
| 80 | |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | public Language getLanguage(){ |
|---|
| 84 | return this.language; |
|---|
| 85 | } |
|---|
| 86 | public void setLanguage(Language language){ |
|---|
| 87 | this.language = language; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | public String getText(){ |
|---|
| 91 | return this.text; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | public void setText(String text) { |
|---|
| 95 | this.text = text; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | @Transient |
|---|
| 99 | public String getLanguageLabel(){ |
|---|
| 100 | if (language != null){ |
|---|
| 101 | return this.language.getRepresentation(Language.DEFAULT()).getLabel(); |
|---|
| 102 | }else{ |
|---|
| 103 | return null; |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | public String getLanguageLabel(Language lang){ |
|---|
| 108 | if (language != null){ |
|---|
| 109 | return this.language.getRepresentation(lang).getLabel(); |
|---|
| 110 | }else{ |
|---|
| 111 | return null; |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | @Override |
|---|
| 116 | public Object clone() throws CloneNotSupportedException{ |
|---|
| 117 | LanguageStringBase result = (LanguageStringBase) super.clone(); |
|---|
| 118 | //no changes to text and language |
|---|
| 119 | //result.setText(this.text); |
|---|
| 120 | //result.setLanguage(this.language); |
|---|
| 121 | return result; |
|---|
| 122 | } |
|---|
| 123 | } |
|---|