had to rename the packages to make them compliant with buckminster
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / model / MultiLanguageText.java
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MultiLanguageText.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MultiLanguageText.java
new file mode 100644 (file)
index 0000000..718b0d7
--- /dev/null
@@ -0,0 +1,155 @@
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy 
+* http://www.e-taxonomy.eu
+* 
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.model;
+
+import java.util.List;
+import java.util.Map;
+
+import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.LanguageString;
+import eu.etaxonomy.cdm.model.common.MultilanguageTextHelper;
+import eu.etaxonomy.cdm.model.common.TermBase;
+
+/**
+ * <p>MultiLanguageText class.</p>
+ *
+ * @author n.hoffmann
+ * @created Oct 8, 2010
+ * @version 1.0
+ */
+public class MultiLanguageText {
+       
+       private Map<Language, LanguageString> languageTextMap;
+       
+       /**
+        * <p>Constructor for MultiLanguageText.</p>
+        *
+        * @param languageTextMap a {@link java.util.Map} object.
+        */
+       public MultiLanguageText (Map<Language, LanguageString> languageTextMap){
+               this.languageTextMap = languageTextMap;
+       }
+       
+    /**
+     * Returns the multilanguage text with the content of <i>this</i> text data.
+     * The different {@link LanguageString language strings} (texts) contained in the
+     * multilanguage text should all have the same meaning.
+     *
+     * @see    #getText(Language)
+     * @return a {@link java.util.Map} object.
+     */
+    public Map<Language, LanguageString> getMultilanguageText(){
+       return languageTextMap;
+    }
+    
+    /**
+     * <p>setMultilanguageText</p>
+     *
+     * @param multilanguageText a {@link java.util.Map} object.
+     */
+    public void setMultilanguageText(Map<Language,LanguageString> multilanguageText){
+       this.languageTextMap = multilanguageText;
+    }
+    
+    /**
+     * Returns the multilanguage text with the content of <i>this</i> IMultiLanguageTextHolder for
+     * a specific language.
+     *
+     * @param language the language in which the text string looked for is formulated
+     * @return a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
+     */
+    public LanguageString getLanguageText(Language language){
+       return languageTextMap.get(language);
+    }
+
+       /**
+        * Returns the text string in the given {@link Language language} with the content
+        * of <i>this</i> IMultiLanguageTextHolder.
+        *
+        * @param language      the language in which the text string looked for is formulated
+        * @see                         #getMultilanguageText(Language)
+        * @return a {@link java.lang.String} object.
+        */
+       public String getText(Language language){
+               return getLanguageText(language).getText();
+       }
+       
+       /**
+        * Creates a {@link LanguageString language string} based on the given text string
+        * and the given {@link Language language}, returns it and adds it to the multilanguage
+        * text representing the content of <i>this</i> IMultiLanguageTextHolder.
+        *
+        * @param text          the string representing the content of the IMultiLanguageTextHolder
+        *                                      in a particular language
+        * @param language      the language in which the text string is formulated
+        * @return                      the language string
+        * @see                         #getMultilanguageText()
+        * @see                         #putText(LanguageString)
+        * @see                         #getMultilanguageText()
+        * @see                         #putText(LanguageString)
+        */
+       public LanguageString putText(String text, Language language){
+               return languageTextMap.put(language, LanguageString.NewInstance(text, language));
+       }
+       
+       /**
+        * Adds a translated {@link LanguageString text in a particular language}
+        * to the multilanguage text representing the content of <i>this</i> IMultiLanguageTextHolder.
+        * The given language string will be returned.
+        *
+        * @param languageString        the language string representing the content of
+        *                                                      the IMultiLanguageTextHolder in a particular language
+        * @return                                      the language string
+        * @see                                         #getMultilanguageText()
+        * @see                                         #putText(String, Language)
+        * @see                                         #getMultilanguageText()
+        * @see                                         #putText(String, Language)
+        */
+       public LanguageString putText(LanguageString languageString){
+               return languageTextMap.put(languageString.getLanguage(), languageString);
+       }
+       
+       /**
+        * Returns the LanguageString in the preferred language. Preferred languages
+        * are specified by the parameter languages, which receives a list of
+        * Language instances in the order of preference. If no representation in
+        * any preferred languages is found the method falls back to return the
+        * Representation in Language.DEFAULT() and if neccesary further falls back
+        * to return the first element found if any.
+        *
+        * Implementors should always consider calling {@link MultilanguageTextHelper#getPreferredLanguageString(Map, List)}
+        * in their implementation of this method
+        *
+        * TODO think about this fall-back strategy &
+        * see also {@link TermBase#getPreferredRepresentation(List)}
+        *
+        * @param languages a {@link java.util.List} object.
+        * @return a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
+        */
+       public LanguageString getPreferredLanguageString(List<Language> languages){
+               return MultilanguageTextHelper.getPreferredLanguageString(languageTextMap, languages);
+       }
+       
+       /**
+        * Removes from the multilanguage representing the content of
+        * <i>this</i> IMultiLanguageTextHolder the one {@link LanguageString language string}
+        * with the given {@link Language language}. Returns the removed
+        * language string.
+        *
+        * @param  language     the language in which the language string to be removed
+        *                                      has been formulated
+        * @return                      the language string associated with the given language
+        * @see                 #getMultilanguageText()
+        */
+       public LanguageString removeText(Language language){
+               return languageTextMap.remove(language);
+       }
+}