Project

General

Profile

Download (3.43 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.envers.Audited;
29
import org.hibernate.search.annotations.Field;
30
import org.hibernate.search.annotations.FieldBridge;
31
import org.hibernate.search.annotations.IndexedEmbedded;
32

    
33
import eu.etaxonomy.cdm.hibernate.search.StripHtmlBridge;
34
import eu.etaxonomy.cdm.jaxb.FormattedTextAdapter;
35

    
36
/**
37
 * @author a.mueller
38
 * @version 1.0
39
 * @since 25.04.2008
40
 */
41
@XmlAccessorType(XmlAccessType.FIELD)
42
@XmlType(name = "LanguageStringBase", propOrder = {
43
    "text",
44
    "language"
45
})
46
@XmlSeeAlso({
47
    LanguageString.class
48
})
49
@MappedSuperclass
50
@Audited
51
public abstract class LanguageStringBase extends AnnotatableEntity{
52
    private static final long serialVersionUID = -1892526642162438277L;
53
    @SuppressWarnings("unused")
54
    private static final Logger logger = Logger.getLogger(LanguageStringBase.class);
55

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

    
64
    @XmlElement(name = "Language")
65
    @XmlIDREF
66
    @XmlSchemaType(name = "IDREF")
67
    @ManyToOne(fetch = FetchType.EAGER)
68
//    @Cascade({CascadeType.MERGE})  remove cascade #5755
69
    @IndexedEmbedded(depth=1)
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
// ****************** CLONE ************************************/
116

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