1
|
/**
|
2
|
* Copyright (C) 2009 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
|
package eu.etaxonomy.cdm.remote.l10n;
|
10
|
|
11
|
import java.util.List;
|
12
|
import java.util.Set;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.hibernate.Hibernate;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
18
|
import eu.etaxonomy.cdm.model.common.Language;
|
19
|
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
|
20
|
import eu.etaxonomy.cdm.model.common.Representation;
|
21
|
import eu.etaxonomy.cdm.model.common.TermBase;
|
22
|
import eu.etaxonomy.cdm.model.common.TermType;
|
23
|
import eu.etaxonomy.cdm.persistence.dto.ITermRepresentation_L10n;
|
24
|
|
25
|
/**
|
26
|
* @author l.morris & a.kohlbecker
|
27
|
* @date Feb 22, 2013
|
28
|
*
|
29
|
*/
|
30
|
public class TermRepresentation_L10n implements ITermRepresentation_L10n {
|
31
|
|
32
|
public static final Logger logger = Logger.getLogger(TermRepresentation_L10n.class);
|
33
|
|
34
|
String label = null;
|
35
|
String abbreviatedLabel = null;
|
36
|
|
37
|
public TermRepresentation_L10n() {
|
38
|
|
39
|
}
|
40
|
|
41
|
public TermRepresentation_L10n(TermBase term, boolean useInverseRepresentation) {
|
42
|
|
43
|
localize(term, useInverseRepresentation);
|
44
|
}
|
45
|
|
46
|
/* (non-Javadoc)
|
47
|
* @see eu.etaxonomy.cdm.remote.l10n.ITermRepresentation_L10n#localize(eu.etaxonomy.cdm.model.common.TermBase, boolean)
|
48
|
*/
|
49
|
@Override
|
50
|
public void localize(TermBase term, boolean useInverseRepresentation) {
|
51
|
|
52
|
List<Language> languages = LocaleContext.getLanguages();
|
53
|
|
54
|
if(useInverseRepresentation){
|
55
|
RelationshipTermBase<?> relationshipTerm = (RelationshipTermBase<?>)term;
|
56
|
if(Hibernate.isInitialized(relationshipTerm.getInverseRepresentations())){
|
57
|
Representation representation = relationshipTerm.getPreferredInverseRepresentation(languages);
|
58
|
setRepresentations(representation);
|
59
|
} else {
|
60
|
logger.debug("inverse representations of term not initialized " + term.getUuid().toString());
|
61
|
}
|
62
|
|
63
|
} else {
|
64
|
if(Hibernate.isInitialized(term.getRepresentations())){
|
65
|
Representation representation = term.getPreferredRepresentation(languages);
|
66
|
setRepresentations(representation);
|
67
|
} else {
|
68
|
logger.debug("representations of term not initialized " + term.getUuid().toString());
|
69
|
}
|
70
|
}
|
71
|
}
|
72
|
|
73
|
@Override
|
74
|
public void localize(Set<Representation> representations) {
|
75
|
DefinedTerm tmpTerm = DefinedTerm.NewInstance(TermType.Unknown, null, null, null);
|
76
|
tmpTerm.getRepresentations().clear(); // removes the null representation added throught the constructor
|
77
|
tmpTerm.getRepresentations().addAll(representations);
|
78
|
List<Language> languages = LocaleContext.getLanguages();
|
79
|
Representation representation = tmpTerm.getPreferredRepresentation(languages);
|
80
|
setRepresentations(representation);
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* @param representation
|
85
|
*/
|
86
|
private void setRepresentations(Representation representation) {
|
87
|
if(representation != null){
|
88
|
if(representation.getLabel() != null && representation.getLabel().length() != 0){
|
89
|
label = representation.getLabel();
|
90
|
} else if (representation.getText() != null && representation.getText().length() !=0) {
|
91
|
label = representation.getText();
|
92
|
} else {
|
93
|
label = representation.getAbbreviatedLabel();
|
94
|
}
|
95
|
|
96
|
abbreviatedLabel = representation.getAbbreviatedLabel();
|
97
|
}
|
98
|
}
|
99
|
|
100
|
/* (non-Javadoc)
|
101
|
* @see eu.etaxonomy.cdm.remote.l10n.ITermRepresentation_L10n#getLabel()
|
102
|
*/
|
103
|
@Override
|
104
|
public String getLabel() {
|
105
|
return label;
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* @param label the label to set
|
110
|
*/
|
111
|
public void setLabel(String label) {
|
112
|
this.label = label;
|
113
|
}
|
114
|
|
115
|
/* (non-Javadoc)
|
116
|
* @see eu.etaxonomy.cdm.remote.l10n.ITermRepresentation_L10n#getAbbreviatedLabel()
|
117
|
*/
|
118
|
@Override
|
119
|
public String getAbbreviatedLabel() {
|
120
|
return abbreviatedLabel;
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* @param abbreviatedLabel the abbreviatedLabel to set
|
125
|
*/
|
126
|
public void setAbbreviatedLabel(String abbreviatedLabel) {
|
127
|
this.abbreviatedLabel = abbreviatedLabel;
|
128
|
}
|
129
|
|
130
|
|
131
|
|
132
|
}
|