3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.model
;
13 import org
.apache
.log4j
.Logger
;
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
;
26 public class DescriptionHelper
{
27 private static final Logger logger
= Logger
28 .getLogger(DescriptionHelper
.class);
31 * Returns whatever the element's title cache equivalent is,
32 * depending on its class.
38 public static String
getCache(DescriptionElementBase element
,
41 if (element
instanceof TextData
) {
42 cache
= ((TextData
) element
).getText(language
);
44 if (element
instanceof CommonTaxonName
) {
45 cache
= ((CommonTaxonName
) element
).getName();
47 return cache
== null ?
"" : cache
;
51 * Returns whatever the element's title cache equivalent is,
52 * depending on its class, using the default language.
57 public static String
getCache(DescriptionElementBase element
) {
58 return getCache(element
, Language
.DEFAULT());
62 * Set whatever the element's title cache equivalent is,
63 * depending on its class.
69 public static void setCache(DescriptionElementBase element
,
70 String value
, Language language
) {
71 if (element
instanceof TextData
) {
72 ((TextData
) element
).putText(value
, language
);
75 if (element
instanceof CommonTaxonName
) {
76 ((CommonTaxonName
) element
).setName(value
);
79 if(element
instanceof Distribution
){
80 logger
.warn("trying to set cache on distribution, don't know what to do at the moment.");
83 logger
.warn("No matching subclass found for DescriptionElementBase object, 'cache' not set.");
87 * Set whatever the element's title cache equivalent is,
88 * depending on its class, using the default language.
93 public static void setCache(DescriptionElementBase element
,
95 setCache(element
, value
, Language
.DEFAULT());