free text search: better querying for 'isNotNull' and code harmonization
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / LanguageStringBase.java
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.search.annotations.Field;
31 import org.hibernate.search.annotations.FieldBridge;
32 import org.hibernate.search.annotations.Index;
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 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 @IndexedEmbedded
71 protected Language language;
72
73 protected LanguageStringBase() {
74 super();
75 }
76
77 protected LanguageStringBase(String text, Language language) {
78 super();
79 this.setLanguage(language);
80 this.setText(text);
81
82 }
83
84 public Language getLanguage(){
85 return this.language;
86 }
87 public void setLanguage(Language language){
88 this.language = language;
89 }
90
91 public String getText(){
92 return this.text;
93 }
94
95 public void setText(String text) {
96 this.text = text;
97 }
98
99 @Transient
100 public String getLanguageLabel(){
101 if (language != null){
102 return this.language.getRepresentation(Language.DEFAULT()).getLabel();
103 }else{
104 return null;
105 }
106 }
107
108 public String getLanguageLabel(Language lang){
109 if (language != null){
110 return this.language.getRepresentation(lang).getLabel();
111 }else{
112 return null;
113 }
114 }
115
116 @Override
117 public Object clone() throws CloneNotSupportedException{
118 LanguageStringBase result = (LanguageStringBase) super.clone();
119 //no changes to text and language
120 //result.setText(this.text);
121 //result.setLanguage(this.language);
122 return result;
123 }
124 }