implemented user management, fixes #803. Minor refactorings.
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / model / DescriptionHelper.java
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 org.apache.log4j.Logger;
14
15 import eu.etaxonomy.cdm.model.common.Language;
16 import eu.etaxonomy.cdm.model.description.CommonTaxonName;
17 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
18 import eu.etaxonomy.cdm.model.description.Distribution;
19 import eu.etaxonomy.cdm.model.description.TextData;
20
21 /**
22 * @author p.ciardelli
23 * @created 02.04.2009
24 * @version 1.0
25 */
26 public class DescriptionHelper {
27 private static final Logger logger = Logger
28 .getLogger(DescriptionHelper.class);
29
30 /**
31 * Returns whatever the element's title cache equivalent is,
32 * depending on its class.
33 *
34 * @param element
35 * @param language
36 * @return
37 */
38 public static String getCache(DescriptionElementBase element,
39 Language language) {
40 String cache = null;
41 if (element instanceof TextData) {
42 cache = ((TextData) element).getText(language);
43 }
44 if (element instanceof CommonTaxonName) {
45 cache = ((CommonTaxonName) element).getName();
46 }
47 return cache == null ? "" : cache;
48 }
49
50 /**
51 * Returns whatever the element's title cache equivalent is,
52 * depending on its class, using the default language.
53 *
54 * @param element
55 * @return
56 */
57 public static String getCache(DescriptionElementBase element) {
58 return getCache(element, Language.DEFAULT());
59 }
60
61 /**
62 * Set whatever the element's title cache equivalent is,
63 * depending on its class.
64 *
65 * @param element
66 * @param value
67 * @param language
68 */
69 public static void setCache(DescriptionElementBase element,
70 String value, Language language) {
71 if (element instanceof TextData) {
72 ((TextData) element).putText(value, language);
73 return;
74 }
75 if (element instanceof CommonTaxonName) {
76 ((CommonTaxonName) element).setName(value);
77 return;
78 }
79 if(element instanceof Distribution){
80 logger.warn("trying to set cache on distribution, don't know what to do at the moment.");
81 return;
82 }
83 logger.warn("No matching subclass found for DescriptionElementBase object, 'cache' not set.");
84 }
85
86 /**
87 * Set whatever the element's title cache equivalent is,
88 * depending on its class, using the default language.
89 *
90 * @param element
91 * @param value
92 */
93 public static void setCache(DescriptionElementBase element,
94 String value) {
95 setCache(element, value, Language.DEFAULT());
96 }
97 }