1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.model;
|
12
|
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.common.Language;
|
17
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
18
|
import eu.etaxonomy.cdm.model.common.MultilanguageTextHelper;
|
19
|
import eu.etaxonomy.cdm.model.common.TermBase;
|
20
|
|
21
|
/**
|
22
|
* <p>MultiLanguageText class.</p>
|
23
|
*
|
24
|
* @author n.hoffmann
|
25
|
* @created Oct 8, 2010
|
26
|
* @version 1.0
|
27
|
*/
|
28
|
public class MultiLanguageText {
|
29
|
|
30
|
private Map<Language, LanguageString> languageTextMap;
|
31
|
|
32
|
/**
|
33
|
* <p>Constructor for MultiLanguageText.</p>
|
34
|
*
|
35
|
* @param languageTextMap a {@link java.util.Map} object.
|
36
|
*/
|
37
|
public MultiLanguageText (Map<Language, LanguageString> languageTextMap){
|
38
|
this.languageTextMap = languageTextMap;
|
39
|
}
|
40
|
|
41
|
/**
|
42
|
* Returns the multilanguage text with the content of <i>this</i> text data.
|
43
|
* The different {@link LanguageString language strings} (texts) contained in the
|
44
|
* multilanguage text should all have the same meaning.
|
45
|
*
|
46
|
* @see #getText(Language)
|
47
|
* @return a {@link java.util.Map} object.
|
48
|
*/
|
49
|
public Map<Language, LanguageString> getMultilanguageText(){
|
50
|
return languageTextMap;
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* <p>setMultilanguageText</p>
|
55
|
*
|
56
|
* @param multilanguageText a {@link java.util.Map} object.
|
57
|
*/
|
58
|
public void setMultilanguageText(Map<Language,LanguageString> multilanguageText){
|
59
|
this.languageTextMap = multilanguageText;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Returns the multilanguage text with the content of <i>this</i> IMultiLanguageTextHolder for
|
64
|
* a specific language.
|
65
|
*
|
66
|
* @param language the language in which the text string looked for is formulated
|
67
|
* @return a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
|
68
|
*/
|
69
|
public LanguageString getLanguageText(Language language){
|
70
|
return languageTextMap.get(language);
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* Returns the text string in the given {@link Language language} with the content
|
75
|
* of <i>this</i> IMultiLanguageTextHolder.
|
76
|
*
|
77
|
* @param language the language in which the text string looked for is formulated
|
78
|
* @see #getMultilanguageText(Language)
|
79
|
* @return a {@link java.lang.String} object.
|
80
|
*/
|
81
|
public String getText(Language language){
|
82
|
return getLanguageText(language).getText();
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* Creates a {@link LanguageString language string} based on the given text string
|
87
|
* and the given {@link Language language}, returns it and adds it to the multilanguage
|
88
|
* text representing the content of <i>this</i> IMultiLanguageTextHolder.
|
89
|
*
|
90
|
* @param text the string representing the content of the IMultiLanguageTextHolder
|
91
|
* in a particular language
|
92
|
* @param language the language in which the text string is formulated
|
93
|
* @return the language string
|
94
|
* @see #getMultilanguageText()
|
95
|
* @see #putText(LanguageString)
|
96
|
* @see #getMultilanguageText()
|
97
|
* @see #putText(LanguageString)
|
98
|
*/
|
99
|
public LanguageString putText(String text, Language language){
|
100
|
return languageTextMap.put(language, LanguageString.NewInstance(text, language));
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* Adds a translated {@link LanguageString text in a particular language}
|
105
|
* to the multilanguage text representing the content of <i>this</i> IMultiLanguageTextHolder.
|
106
|
* The given language string will be returned.
|
107
|
*
|
108
|
* @param languageString the language string representing the content of
|
109
|
* the IMultiLanguageTextHolder in a particular language
|
110
|
* @return the language string
|
111
|
* @see #getMultilanguageText()
|
112
|
* @see #putText(String, Language)
|
113
|
* @see #getMultilanguageText()
|
114
|
* @see #putText(String, Language)
|
115
|
*/
|
116
|
public LanguageString putText(LanguageString languageString){
|
117
|
return languageTextMap.put(languageString.getLanguage(), languageString);
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* Returns the LanguageString in the preferred language. Preferred languages
|
122
|
* are specified by the parameter languages, which receives a list of
|
123
|
* Language instances in the order of preference. If no representation in
|
124
|
* any preferred languages is found the method falls back to return the
|
125
|
* Representation in Language.DEFAULT() and if neccesary further falls back
|
126
|
* to return the first element found if any.
|
127
|
*
|
128
|
* Implementors should always consider calling {@link MultilanguageTextHelper#getPreferredLanguageString(Map, List)}
|
129
|
* in their implementation of this method
|
130
|
*
|
131
|
* TODO think about this fall-back strategy &
|
132
|
* see also {@link TermBase#getPreferredRepresentation(List)}
|
133
|
*
|
134
|
* @param languages a {@link java.util.List} object.
|
135
|
* @return a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
|
136
|
*/
|
137
|
public LanguageString getPreferredLanguageString(List<Language> languages){
|
138
|
return MultilanguageTextHelper.getPreferredLanguageString(languageTextMap, languages);
|
139
|
}
|
140
|
|
141
|
/**
|
142
|
* Removes from the multilanguage representing the content of
|
143
|
* <i>this</i> IMultiLanguageTextHolder the one {@link LanguageString language string}
|
144
|
* with the given {@link Language language}. Returns the removed
|
145
|
* language string.
|
146
|
*
|
147
|
* @param language the language in which the language string to be removed
|
148
|
* has been formulated
|
149
|
* @return the language string associated with the given language
|
150
|
* @see #getMultilanguageText()
|
151
|
*/
|
152
|
public LanguageString removeText(Language language){
|
153
|
return languageTextMap.remove(language);
|
154
|
}
|
155
|
}
|