Project

General

Profile

Download (3.49 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.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
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.XmlSchemaType;
23
import javax.xml.bind.annotation.XmlSeeAlso;
24
import javax.xml.bind.annotation.XmlType;
25
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
26

    
27
import org.apache.log4j.Logger;
28
import org.hibernate.annotations.Cascade;
29
import org.hibernate.annotations.CascadeType;
30
import org.hibernate.envers.Audited;
31
import org.hibernate.search.annotations.Field;
32
import org.hibernate.search.annotations.FieldBridge;
33
import org.hibernate.search.annotations.IndexedEmbedded;
34

    
35
import eu.etaxonomy.cdm.hibernate.search.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
@Audited
53
public abstract class LanguageStringBase extends AnnotatableEntity{
54
    private static final long serialVersionUID = -1892526642162438277L;
55
    @SuppressWarnings("unused")
56
    private static final Logger logger = Logger.getLogger(LanguageStringBase.class);
57

    
58
    @XmlElement(name = "Text")
59
    @XmlJavaTypeAdapter(FormattedTextAdapter.class)
60
    @Column(length=65536)
61
    @Field
62
    @FieldBridge(impl=StripHtmlBridge.class)
63
    @Lob
64
    protected String text;
65

    
66
    @XmlElement(name = "Language")
67
    @XmlIDREF
68
    @XmlSchemaType(name = "IDREF")
69
    @ManyToOne(fetch = FetchType.EAGER)
70
    @Cascade({CascadeType.MERGE})
71
    @IndexedEmbedded(depth=1)
72
    protected Language language;
73

    
74
    protected LanguageStringBase() {
75
        super();
76
    }
77

    
78
    protected LanguageStringBase(String text, Language language) {
79
        super();
80
        this.setLanguage(language);
81
        this.setText(text);
82

    
83
    }
84

    
85
    public Language getLanguage(){
86
        return this.language;
87
    }
88
    public void setLanguage(Language language){
89
        this.language = language;
90
    }
91

    
92
    public String getText(){
93
        return this.text;
94
    }
95

    
96
    public void setText(String text) {
97
        this.text = text;
98
    }
99

    
100
    @Transient
101
    public String getLanguageLabel(){
102
        if (language != null){
103
            return this.language.getRepresentation(Language.DEFAULT()).getLabel();
104
        }else{
105
            return null;
106
        }
107
    }
108

    
109
    public String getLanguageLabel(Language lang){
110
        if (language != null){
111
            return this.language.getRepresentation(lang).getLabel();
112
        }else{
113
            return null;
114
        }
115
    }
116

    
117
// ****************** CLONE ************************************/
118

    
119
    @Override
120
    public Object clone() throws CloneNotSupportedException{
121
        LanguageStringBase result = (LanguageStringBase) super.clone();
122
        //no changes to text and language
123
        //result.setText(this.text);
124
        //result.setLanguage(this.language);
125
        return result;
126
    }
127
}
(45-45/72)