Project

General

Profile

Download (5.53 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.taxeditor.model;
11

    
12
import java.util.List;
13
import java.util.Map;
14

    
15
import eu.etaxonomy.cdm.model.common.Language;
16
import eu.etaxonomy.cdm.model.common.LanguageString;
17
import eu.etaxonomy.cdm.model.common.MultilanguageTextHelper;
18
import eu.etaxonomy.cdm.model.common.TermBase;
19

    
20
/**
21
 * <p>MultiLanguageText class.</p>
22
 *
23
 * @author n.hoffmann
24
 * @created Oct 8, 2010
25
 * @version 1.0
26
 */
27
public class MultiLanguageText {
28
	
29
	private Map<Language, LanguageString> languageTextMap;
30
	
31
	/**
32
	 * <p>Constructor for MultiLanguageText.</p>
33
	 *
34
	 * @param languageTextMap a {@link java.util.Map} object.
35
	 */
36
	public MultiLanguageText (Map<Language, LanguageString> languageTextMap){
37
		this.languageTextMap = languageTextMap;
38
	}
39
	
40
    /**
41
     * Returns the multilanguage text with the content of <i>this</i> text data.
42
     * The different {@link LanguageString language strings} (texts) contained in the
43
     * multilanguage text should all have the same meaning.
44
     *
45
     * @see	#getText(Language)
46
     * @return a {@link java.util.Map} object.
47
     */
48
    public Map<Language, LanguageString> getMultilanguageText(){
49
    	return languageTextMap;
50
    }
51
    
52
    /**
53
     * <p>setMultilanguageText</p>
54
     *
55
     * @param multilanguageText a {@link java.util.Map} object.
56
     */
57
    public void setMultilanguageText(Map<Language,LanguageString> multilanguageText){
58
    	this.languageTextMap = multilanguageText;
59
    }
60
    
61
    /**
62
     * Returns the multilanguage text with the content of <i>this</i> IMultiLanguageTextHolder for
63
     * a specific language.
64
     *
65
     * @param language the language in which the text string looked for is formulated
66
     * @return a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
67
     */
68
    public LanguageString getLanguageText(Language language){
69
    	return languageTextMap.get(language);
70
    }
71

    
72
	/**
73
	 * Returns the text string in the given {@link Language language} with the content
74
	 * of <i>this</i> IMultiLanguageTextHolder.
75
	 *
76
	 * @param language	the language in which the text string looked for is formulated
77
	 * @see				#getMultilanguageText(Language)
78
	 * @return a {@link java.lang.String} object.
79
	 */
80
	public String getText(Language language){
81
		return getLanguageText(language).getText();
82
	}
83
	
84
	/**
85
	 * Creates a {@link LanguageString language string} based on the given text string
86
	 * and the given {@link Language language}, returns it and adds it to the multilanguage
87
	 * text representing the content of <i>this</i> IMultiLanguageTextHolder.
88
	 *
89
	 * @param text		the string representing the content of the IMultiLanguageTextHolder
90
	 * 					in a particular language
91
	 * @param language	the language in which the text string is formulated
92
	 * @return			the language string
93
	 * @see    	   		#getMultilanguageText()
94
	 * @see    	   		#putText(LanguageString)
95
	 * @see    	   		#getMultilanguageText()
96
	 * @see    	   		#putText(LanguageString)
97
	 */
98
	public LanguageString putText(String text, Language language){
99
		return languageTextMap.put(language, LanguageString.NewInstance(text, language));
100
	}
101
	
102
	/**
103
	 * Adds a translated {@link LanguageString text in a particular language}
104
	 * to the multilanguage text representing the content of <i>this</i> IMultiLanguageTextHolder.
105
	 * The given language string will be returned.
106
	 *
107
	 * @param languageString	the language string representing the content of
108
	 * 							the IMultiLanguageTextHolder in a particular language
109
	 * @return					the language string
110
	 * @see    	   				#getMultilanguageText()
111
	 * @see    	   				#putText(String, Language)
112
	 * @see    	   				#getMultilanguageText()
113
	 * @see    	   				#putText(String, Language)
114
	 */
115
	public LanguageString putText(LanguageString languageString){
116
		return languageTextMap.put(languageString.getLanguage(), languageString);
117
	}
118
	
119
	/**
120
	 * Returns the LanguageString in the preferred language. Preferred languages
121
	 * are specified by the parameter languages, which receives a list of
122
	 * Language instances in the order of preference. If no representation in
123
	 * any preferred languages is found the method falls back to return the
124
	 * Representation in Language.DEFAULT() and if neccesary further falls back
125
	 * to return the first element found if any.
126
	 *
127
	 * Implementors should always consider calling {@link MultilanguageTextHelper#getPreferredLanguageString(Map, List)}
128
	 * in their implementation of this method
129
	 *
130
	 * TODO think about this fall-back strategy &
131
	 * see also {@link TermBase#getPreferredRepresentation(List)}
132
	 *
133
	 * @param languages a {@link java.util.List} object.
134
	 * @return a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
135
	 */
136
	public LanguageString getPreferredLanguageString(List<Language> languages){
137
		return MultilanguageTextHelper.getPreferredLanguageString(languageTextMap, languages);
138
	}
139
	
140
	/**
141
	 * Removes from the multilanguage representing the content of
142
	 * <i>this</i> IMultiLanguageTextHolder the one {@link LanguageString language string}
143
	 * with the given {@link Language language}. Returns the removed
144
	 * language string.
145
	 *
146
	 * @param  language	the language in which the language string to be removed
147
	 * 					has been formulated
148
	 * @return			the language string associated with the given language
149
	 * @see     		#getMultilanguageText()
150
	 */
151
	public LanguageString removeText(Language language){
152
		return languageTextMap.remove(language);
153
	}
154
}
(33-33/41)