2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.model
;
12 import java
.lang
.reflect
.InvocationTargetException
;
13 import java
.lang
.reflect
.Method
;
14 import java
.util
.Arrays
;
15 import java
.util
.List
;
18 import org
.apache
.commons
.lang
.StringUtils
;
19 import org
.hibernate
.LazyInitializationException
;
21 import eu
.etaxonomy
.cdm
.api
.service
.DefaultCategoricalDescriptionBuilder
;
22 import eu
.etaxonomy
.cdm
.api
.service
.DefaultQuantitativeDescriptionBuilder
;
23 import eu
.etaxonomy
.cdm
.api
.service
.DescriptionBuilder
;
24 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.Group
;
27 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
28 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
29 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
30 import eu
.etaxonomy
.cdm
.model
.common
.LanguageStringBase
;
31 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
32 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
33 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceBase
;
34 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
35 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipTermBase
;
36 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
37 import eu
.etaxonomy
.cdm
.model
.common
.User
;
38 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
39 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
40 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
41 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
42 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
43 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
44 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
45 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
46 import eu
.etaxonomy
.cdm
.model
.description
.KeyStatement
;
47 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
48 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
49 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
50 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
51 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
52 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
53 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
54 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
55 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
56 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
57 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
58 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
59 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
60 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
61 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
62 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
63 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationStatusBase
;
64 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
65 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
66 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
67 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
68 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
69 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
70 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
71 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
74 * <p>DescriptionHelper class.</p>
79 public class DescriptionHelper
{
82 * Returns whatever the element's title cache equivalent is,
83 * depending on its class.
85 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
86 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
87 * @return a {@link java.lang.String} object.
89 public static String
getCache(DescriptionElementBase element
,
92 String mainElementLabel
= null;
93 DescriptionBase
<?
> descr
= element
.getInDescription();
94 descr
= CdmBase
.deproxy(descr
, DescriptionBase
.class);
97 if (descr
.isInstanceOf(TaxonDescription
.class)){
98 Taxon taxon
= CdmBase
.deproxy(descr
, TaxonDescription
.class).getTaxon();
100 mainElementLabel
= taxon
.getTitleCache();
102 }else if (descr
.isInstanceOf(SpecimenDescription
.class)){
103 SpecimenOrObservationBase
<?
> specimen
= CdmBase
.deproxy(descr
, SpecimenDescription
.class).getDescribedSpecimenOrObservation();
104 if (specimen
!= null){
105 mainElementLabel
= specimen
.getTitleCache();
107 }else if (descr
.isInstanceOf(TaxonNameDescription
.class)){
108 TaxonName name
= CdmBase
.deproxy(descr
, TaxonNameDescription
.class).getTaxonName();
110 mainElementLabel
= name
.getTitleCache();
117 if (element
instanceof TextData
) {
118 //cache = ((TextData) element).getText(language);
121 if (element
instanceof CommonTaxonName
) {
122 cache
= ((CommonTaxonName
) element
).getName();
124 if (element
instanceof TaxonInteraction
) {
125 Taxon taxon2
= ((TaxonInteraction
) element
).getTaxon2();
126 if(taxon2
!= null && taxon2
.getName() != null){
127 cache
= taxon2
.getName().getTitleCache();
129 cache
= "No taxon chosen";
133 if (element
instanceof Distribution
) {
134 Distribution distribution
= (Distribution
) element
;
136 NamedArea area
= distribution
.getArea();
138 cache
= area
.getLabel();
140 PresenceAbsenceTerm status
= distribution
.getStatus();
142 cache
+= ", no status";
144 cache
+= ", " + status
.getLabel();
148 String result
= cache
== null ?
"" : cache
;
149 if (isNotBlank(mainElementLabel
)){
150 result
= CdmUtils
.concat(" ", result
, "(" + mainElementLabel
+ ")");
156 * Returns whatever the element's title cache equivalent is,
157 * depending on its class, using the default language.
159 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
160 * @return a {@link java.lang.String} object.
162 public static String
getCache(DescriptionElementBase element
) {
163 return getCache(element
, CdmStore
.getDefaultLanguage());
167 * Set whatever the element's title cache equivalent is,
168 * depending on its class.
170 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
171 * @param value a {@link java.lang.String} object.
172 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
174 public static void setCache(DescriptionElementBase element
,
175 String value
, Language language
) {
176 if (element
instanceof TextData
) {
177 ((TextData
) element
).putText(language
, value
);
179 }else if (element
instanceof CommonTaxonName
) {
180 ((CommonTaxonName
) element
).setName(value
);
182 }else if (element
instanceof TaxonInteraction
) {
184 }else if(element
instanceof Distribution
){
185 MessagingUtils
.warn(DescriptionHelper
.class, "trying to set cache on distribution, don't know what to do at the moment.");
188 MessagingUtils
.warn(DescriptionHelper
.class, "No matching subclass found for DescriptionElementBase object, 'cache' not set.");
193 * Set whatever the element's title cache equivalent is,
194 * depending on its class, using the default language.
196 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
197 * @param value a {@link java.lang.String} object.
199 public static void setCache(DescriptionElementBase element
,
201 setCache(element
, value
, CdmStore
.getDefaultLanguage());
206 * <p>getObjectDescription</p>
208 * @param element a {@link java.lang.Object} object.
209 * @return a {@link java.lang.String} object.
211 public static String
getObjectDescription(Object element
) {
212 String resultString
= null;
213 if (element
instanceof IdentifiableEntity
) {
215 resultString
= ((IdentifiableEntity
) element
).getTitleCache();
216 }catch(LazyInitializationException e
){
217 String result
= "No Session to initialize title cache for IdentifiableEntity";
218 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
219 resultString
= "TODO: " + result
;
221 }else if (element
instanceof OriginalSourceBase
) {
223 OriginalSourceBase
<?
> originalSource
= (OriginalSourceBase
<?
>) element
;
224 // ISourceable sourcedObject = originalSource.getSourcedObj();
225 //due to #5743 the bidirectionality for sourced object had to be removed
226 String sourceObjectTitle
= "sourced object data not available (#5743)";
227 // if(sourcedObject instanceof IIdentifiableEntity){
228 // sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
229 // }else if(sourcedObject instanceof DescriptionElementBase){
230 // sourceObjectTitle = "Element for description: " + ((DescriptionElementBase) sourcedObject).getInDescription().getTitleCache();
232 // throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
235 resultString
= CdmUtils
.concat("; ", new String
[]{originalSource
.getIdNamespace(), originalSource
.getIdInSource(), sourceObjectTitle
});
236 }catch(LazyInitializationException e
){
237 String result
= "Error initializing title cache for ISourceable of an OriginalSourceBase";
238 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
239 resultString
= "TODO: " + result
;
241 }else if (element
instanceof LanguageStringBase
) {
242 resultString
= ((LanguageStringBase
) element
).getText();
243 }else if (element
instanceof DescriptionElementBase
) {
244 resultString
= getCache((DescriptionElementBase
) element
);
245 }else if (element
instanceof RelationshipBase
<?
, ?
, ?
>) {
246 resultString
= getCache((RelationshipBase
<?
, ?
, ?
>) element
);
247 }else if (element
instanceof TypeDesignationBase
<?
>) {
248 resultString
= getCache((TypeDesignationBase
<?
>) element
);
249 }else if (element
instanceof HomotypicalGroup
) {
250 resultString
= getCache((HomotypicalGroup
) element
);
251 }else if (element
instanceof TaxonNode
) {
252 resultString
= getCache((TaxonNode
) element
);
253 }else if (element
instanceof DeterminationEvent
) {
254 resultString
= getCache((DeterminationEvent
) element
);
255 }else if (element
instanceof Marker
) {
256 Marker marker
= (Marker
) element
;
257 MarkerType type
= marker
.getMarkerType();
258 resultString
= (type
== null ?
"- no marker type -" : marker
.getMarkerType().getLabel()) + " (" + marker
.getFlag() + ")";
259 }else if (element
instanceof User
) {
260 User user
= (User
) element
;
261 resultString
= user
.getUsername();
262 }else if (element
instanceof Group
) {
263 Group group
= (Group
) element
;
264 resultString
= group
.getName();
265 }else if (element
instanceof KeyStatement
) {
266 KeyStatement keyStatement
= (KeyStatement
) element
;
267 resultString
= getCache(keyStatement
);
269 // TODO write return texts for HomotypicalGroup, etc.
270 resultString
= element
.toString();
273 if (resultString
== null){
274 resultString
= element
.toString();
280 private static String
getCache(DeterminationEvent detEvent
) {
282 String taxonStr
= null;
283 TaxonName taxonName
= detEvent
.getTaxonName();
284 TaxonBase
<?
> taxon
= detEvent
.getTaxon();
285 if (taxonName
!= null){
286 taxonStr
= taxonName
.getTitleCache();
288 if (isBlank(taxonStr
) && taxon
!= null){
289 taxonStr
= taxon
.getTitleCache();
291 if (isBlank(taxonStr
)){
292 taxonStr
= "no or unlabled taxon";
297 SpecimenOrObservationBase
<?
> unit
= detEvent
.getIdentifiedUnit();
300 unitStr
= unit
.getTitleCache();
301 if (isBlank(unitStr
)){
302 unitStr
= "Unlabled unit";
308 String result
= CdmUtils
.concat(" determined as ", unitStr
, taxonStr
);
313 private static String
getCache(TaxonNode taxonNode
) {
315 Classification classification
= taxonNode
.getClassification();
316 if (classification
!= null){
317 String classificationStr
= classification
.getName() == null ?
"" : classification
.getName().getText();
318 result
= CdmUtils
.concat("" , result
, classificationStr
);
319 if (isBlank(result
)){
320 result
= classification
.toString();
324 TaxonNode parentNode
= taxonNode
.getParent();
325 if (parentNode
== null){
326 parentStr
= "no parent";
328 Taxon parentTaxon
= parentNode
.getTaxon();
329 if (parentTaxon
== null){
330 parentStr
= "no parent taxon";
332 TaxonName parentName
= parentTaxon
.getName();
333 if (parentName
== null){
334 parentStr
= "child of " + parentTaxon
.getTitleCache();
336 parentStr
= "child of " + parentName
.getTitleCache();
340 result
= CdmUtils
.concat(": ", result
, parentStr
);
345 private static String
getCache(TypeDesignationBase
<?
> designation
) {
346 designation
= CdmBase
.deproxy(designation
);
347 TypeDesignationStatusBase
<?
> status
= designation
.getTypeStatus();
349 IdentifiableEntity
<?
> to
;
350 from
= designation
.getTypifiedNames();
351 if (designation
.isInstanceOf(SpecimenTypeDesignation
.class)){
352 to
= ((SpecimenTypeDesignation
)designation
).getTypeSpecimen();
353 }else if (designation
.isInstanceOf(NameTypeDesignation
.class)){
354 to
= ((NameTypeDesignation
)designation
).getTypeName();
356 throw new RuntimeException("Type Designation class not supported: " + designation
.getClass().getName());
358 String typeLabel
= null;
360 Representation typeRepr
= status
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
361 if (typeRepr
!= null){
362 typeLabel
= typeRepr
.getAbbreviatedLabel();
364 if (isBlank(typeLabel
) && typeRepr
!= null){
365 typeLabel
= typeRepr
.getLabel();
367 if (isBlank(typeLabel
) ){
368 typeLabel
= status
.getSymbol();
370 if (isBlank(typeLabel
)){
371 typeLabel
= status
.getTitleCache();
374 if (isBlank(typeLabel
)){
377 String fromString
= "";
378 for (TaxonName name
: from
){
379 CdmUtils
.concat(",", fromString
, name
.getTitleCache());
381 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : fromString
,
382 typeLabel
, to
== null?
null : to
.getTitleCache()});
386 private static String
getCache(RelationshipBase
<?
, ?
, ?
> rel
) {
387 rel
= CdmBase
.deproxy(rel
);
388 RelationshipTermBase
<?
> type
= rel
.getType();
389 IdentifiableEntity
<?
> from
;
390 IdentifiableEntity
<?
> to
;
391 if (rel
.isInstanceOf(NameRelationship
.class)){
392 from
= ((NameRelationship
)rel
).getFromName();
393 to
= ((NameRelationship
)rel
).getToName();
394 }else if (rel
.isInstanceOf(HybridRelationship
.class)){
395 from
= ((HybridRelationship
)rel
).getParentName();
396 to
= ((HybridRelationship
)rel
).getHybridName();
397 }else if (rel
.isInstanceOf(TaxonRelationship
.class)){
398 from
= ((TaxonRelationship
)rel
).getFromTaxon();
399 to
= ((TaxonRelationship
)rel
).getToTaxon();
402 Method fromMethod
= rel
.getClass().getMethod("getRelatedFrom");
403 Method toMethod
= rel
.getClass().getMethod("getRelatedFrom");
404 fromMethod
.setAccessible(true);
405 toMethod
.setAccessible(true);
406 from
= (IdentifiableEntity
<?
>)fromMethod
.invoke(rel
);
407 to
= (IdentifiableEntity
<?
>)toMethod
.invoke(rel
);
408 } catch (NoSuchMethodException
| SecurityException
| IllegalAccessException
409 | IllegalArgumentException
| InvocationTargetException e
) {
410 throw new RuntimeException(e
);
413 String typeLabel
= null;
415 Representation typeRepr
= type
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
416 if (typeRepr
!= null){
417 typeLabel
= typeRepr
.getAbbreviatedLabel();
419 if (isBlank(typeLabel
) && typeRepr
!= null){
420 typeLabel
= typeRepr
.getLabel();
422 if (isBlank(typeLabel
) ){
423 typeLabel
= type
.getSymbol();
425 if (isBlank(typeLabel
)){
426 typeLabel
= type
.getTitleCache();
429 if (isBlank(typeLabel
)){
432 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : from
.getTitleCache(),
433 typeLabel
, to
== null?
null : to
.getTitleCache()});
438 private static String
getCache(HomotypicalGroup hg
) {
440 for (TaxonName tnb
: hg
.getTypifiedNames()){
441 result
= CdmUtils
.concat(", ", result
, tnb
.getTitleCache());
443 if (isBlank(result
)){
444 result
= "No typified names";
449 private static String
getCache(KeyStatement ks
) {
452 result
= "KeyStatement";
458 * <p>getObjectClassname</p>
460 * @param element a {@link java.lang.Object} object.
461 * @return a {@link java.lang.String} object.
463 public static String
getObjectClassname(Object element
) {
464 return element
.getClass().getSimpleName();
468 * <p>getFeatureNodeContainerText</p>
470 * @param element a {@link eu.etaxonomy.taxeditor.model.FeatureNodeContainer} object.
471 * @return a {@link java.lang.String} object.
473 public static String
getFeatureNodeContainerText(FeatureNodeContainer element
) {
474 String result
= null;
475 if(element
.getFeatureNode() != null && element
.getFeatureNode().getFeature() != null){
476 result
= element
.getFeatureNode().getFeature().getLabel(CdmStore
.getDefaultLanguage());
478 return "No label set";
481 result
= element
.getFeatureNode().getFeature().getLabel();
487 * <p>getQuantitativeDataText</p>
489 * @param element a {@link eu.etaxonomy.cdm.model.description.QuantitativeData} object.
490 * @return a {@link java.lang.String} object.
492 public static String
getQuantitativeDataText(QuantitativeData element
) {
493 TextData textData
= quantitativeDescriptionBuilder
.build(element
, getLanguageList());
495 return textData
.getText(CdmStore
.getDefaultLanguage());
499 * <p>getCategoricalDataText</p>
501 * @param element a {@link eu.etaxonomy.cdm.model.description.CategoricalData} object.
502 * @return a {@link java.lang.String} object.
504 public static String
getCategoricalDataText(CategoricalData element
) {
505 TextData textData
= categoricalDescriptionBuilder
.build(element
, getLanguageList());
507 return textData
.getText(CdmStore
.getDefaultLanguage());
510 private static List
<Language
> getLanguageList(){
511 return Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
514 private static DescriptionBuilder
<QuantitativeData
> quantitativeDescriptionBuilder
= new DefaultQuantitativeDescriptionBuilder();
515 private static DescriptionBuilder
<CategoricalData
> categoricalDescriptionBuilder
= new DefaultCategoricalDescriptionBuilder();
519 * <p>getDistributionText</p>
521 * @param element a {@link eu.etaxonomy.cdm.model.description.Distribution} object.
522 * @return a {@link java.lang.String} object.
524 public static String
getDistributionText(Distribution element
) {
526 String text
= "EMPTY";
528 Distribution distribution
= element
;
530 NamedArea area
= distribution
.getArea();
533 text
= NamedArea
.labelWithLevel(area
, CdmStore
.getDefaultLanguage());
535 PresenceAbsenceTerm status
= distribution
.getStatus();
537 if (status
!= null) {
538 text
+= ", " + status
.getLabel();
540 text
+= ", NO STATUS";
547 * <p>getImageText</p>
549 * @param media a {@link eu.etaxonomy.cdm.model.media.Media} object.
550 * @return a {@link java.lang.String} object.
552 public static String
getImageText(Media media
) {
553 LanguageString title
= media
.getTitle(CdmStore
.getDefaultLanguage());
555 return title
.getText();
563 * <p>getElementText</p>
565 * @param element a {@link eu.etaxonomy.cdm.model.description.TextData} object.
566 * @return a {@link java.lang.String} object.
568 public static String
getElementText(TextData element
) {
570 if(element
.getFeature().equals(Feature
.CITATION())){
572 for(DescriptionElementSource source
: element
.getSources()){
573 if(source
.getCitation() != null){
574 text
+= source
.getCitation().getTitleCache();
576 if(source
.getNameUsedInSource() != null){
577 text
+= " [ " + source
.getNameUsedInSource().getTitleCache() + " ]";
581 text
= "No sources provided";
584 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
585 LanguageString languageString
= element
.getPreferredLanguageString(languages
);
586 text
= languageString
!= null ? languageString
.getText() : null;
588 return isBlank(text
) ?
"No text provided" : text
;
592 * <p>getTaxonInteractionText</p>
594 * @param element a {@link eu.etaxonomy.cdm.model.description.TaxonInteraction} object.
595 * @return a {@link java.lang.String} object.
597 public static String
getTaxonInteractionText(TaxonInteraction element
) {
599 Taxon taxon2
= element
.getTaxon2();
600 if(taxon2
!= null && taxon2
.getName() != null){
601 text
= taxon2
.getName().getTitleCache();
603 text
= "No taxon chosen";
610 * <p>getCommonNameText</p>
612 * @param commonName a {@link eu.etaxonomy.cdm.model.description.CommonTaxonName} object.
613 * @return a {@link java.lang.String} object.
615 public static String
getCommonNameText(CommonTaxonName commonName
) {
616 String name
= commonName
.getName();
617 if (name
== null || name
.length() == 0) {
618 name
= "No name provided";
620 Language language
= commonName
.getLanguage();
621 if (language
== null) {
622 name
+= " (No language provided)";
624 name
+= " (" + language
.getDescription() + ")";
630 * <p>getDescriptionText</p>
632 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
633 * @return a {@link java.lang.String} object.
635 public static String
getDescriptionText(DescriptionBase element
) {
636 String text
= element
.getTitleCache();
637 if (text
== null || text
.length() == 0) {
638 text
= "No label provided";
645 * <p>getIndividualsAssociationText</p>
647 * @param element a {@link eu.etaxonomy.cdm.model.description.IndividualsAssociation} object.
648 * @return a {@link java.lang.String} object.
650 public static String
getIndividualsAssociationText(IndividualsAssociation element
) {
651 SpecimenOrObservationBase derivedUnit
= element
.getAssociatedSpecimenOrObservation();
652 if(derivedUnit
!= null){
653 return derivedUnit
.getTitleCache();
655 return "No unit chosen";
661 * @param element a {@link java.lang.Object} object.
662 * @return a {@link java.lang.String} object.
664 public static String
getLabel(Object element
){
665 String noLabelString
= "[no label]";
666 if (element
instanceof FeatureNodeContainer
){
667 return getFeatureNodeContainerText((FeatureNodeContainer
) element
);
669 else if (element
instanceof DescriptionBase
) {
670 return getDescriptionText((DescriptionBase
) element
);
672 else if(element
instanceof CategoricalData
){
673 String categoricalDataText
= getCategoricalDataText((CategoricalData
) element
);
674 if(categoricalDataText
==null || categoricalDataText
.isEmpty()){
675 categoricalDataText
= noLabelString
;
677 return categoricalDataText
;
679 else if (element
instanceof CommonTaxonName
) {
680 return getCommonNameText((CommonTaxonName
) element
);
682 else if (element
instanceof Distribution
) {
683 return getDistributionText((Distribution
) element
);
685 else if (element
instanceof IndividualsAssociation
) {
686 return getIndividualsAssociationText((IndividualsAssociation
) element
);
688 else if (element
instanceof QuantitativeData
) {
689 String quantitativeDataText
= getQuantitativeDataText((QuantitativeData
) element
);
690 if(quantitativeDataText
==null || quantitativeDataText
.isEmpty()){
691 quantitativeDataText
= noLabelString
;
693 return quantitativeDataText
;
695 else if (element
instanceof TaxonInteraction
) {
696 return getTaxonInteractionText((TaxonInteraction
) element
);
698 else if (element
instanceof TextData
) {
699 return getElementText((TextData
) element
);
702 return element
.toString();
706 private static boolean isNotBlank(String str
){
707 return StringUtils
.isNotBlank(str
);
710 private static boolean isBlank(String str
){
711 return StringUtils
.isBlank(str
);