1
|
/**
|
2
|
* Copyright (C) 2015 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
|
package eu.etaxonomy.cdm.api.service.dto;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
import java.util.SortedSet;
|
14
|
|
15
|
import javax.swing.text.html.HTML;
|
16
|
|
17
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
18
|
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules;
|
19
|
import eu.etaxonomy.cdm.strategy.cache.TagEnum;
|
20
|
import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper;
|
21
|
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
|
22
|
|
23
|
/**
|
24
|
* A class representing a condensed distribution stored as as list of {@link TaggedText}
|
25
|
* with TaggedText being extended by an isBold indicator.
|
26
|
*
|
27
|
* The class offers a method representing a string representation which uses {@link HTML}
|
28
|
* tag < b> to indicate bold text.
|
29
|
*
|
30
|
* @author a.kohlbecker
|
31
|
* @author a.mueller
|
32
|
* @since Jun 25, 2015
|
33
|
*/
|
34
|
public class CondensedDistribution {
|
35
|
|
36
|
private List<TaggedText> taggedText = new ArrayList<>();
|
37
|
|
38
|
public static class DistributionTaggedText extends TaggedText{
|
39
|
private static final long serialVersionUID = 3904027767908153947L;
|
40
|
private boolean bold = false;
|
41
|
|
42
|
public static DistributionTaggedText NewInstance(TagEnum type, String text){
|
43
|
return new DistributionTaggedText(type, text, false);
|
44
|
}
|
45
|
|
46
|
private DistributionTaggedText(TagEnum type, String text, boolean bold) {
|
47
|
super(type, text);
|
48
|
this.bold = bold;
|
49
|
}
|
50
|
public boolean isBold() {
|
51
|
return bold;
|
52
|
}
|
53
|
public void setBold(boolean bold) {
|
54
|
this.bold = bold;
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public SortedSet<String> htmlTags(){
|
59
|
SortedSet<String> result = super.htmlTags();
|
60
|
if (bold){
|
61
|
result.add("b");
|
62
|
}
|
63
|
return result;
|
64
|
}
|
65
|
}
|
66
|
|
67
|
public void addStatusAndAreaTaggedText(String status, String area, boolean bold) {
|
68
|
addTaggedText(TagEnum.symbol, status, false);
|
69
|
if (CdmUtils.isNotBlank(status) && CdmUtils.isNotBlank(area)){
|
70
|
addTaggedText(TagEnum.separator,"",false);
|
71
|
}
|
72
|
addTaggedText(TagEnum.label, area, bold);
|
73
|
}
|
74
|
|
75
|
public void addSeparatorTaggedText(String sep){
|
76
|
addTaggedText(TagEnum.separator, sep, false);
|
77
|
}
|
78
|
public void addSeparatorTaggedText(String sep, boolean bold) {
|
79
|
addTaggedText(TagEnum.separator, sep, bold);
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* @see TagEnum#postSeparator
|
84
|
*/
|
85
|
public void addPostSeparatorTaggedText(String sep){
|
86
|
addTaggedText(TagEnum.postSeparator, sep, false);
|
87
|
}
|
88
|
|
89
|
public void addTaggedText(TagEnum type, String text, boolean bold) {
|
90
|
if (CdmUtils.isNotBlank(text)|| type.isSeparator() ){
|
91
|
DistributionTaggedText taggedText = DistributionTaggedText.NewInstance(type, text);
|
92
|
taggedText.bold = bold;
|
93
|
this.taggedText.add(taggedText);
|
94
|
}
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* @return <code>true</code> if no tagged text was added yet (the inner tagged text list is still empty).
|
99
|
*/
|
100
|
public boolean isEmpty() {
|
101
|
return this.taggedText.isEmpty();
|
102
|
}
|
103
|
|
104
|
public String getHtmlString(){
|
105
|
return toString();
|
106
|
}
|
107
|
|
108
|
public List<TaggedText> getTaggedText(){
|
109
|
return this.taggedText;
|
110
|
}
|
111
|
|
112
|
//***************** STRING **************************************/
|
113
|
|
114
|
@Override
|
115
|
public String toString(){
|
116
|
HTMLTagRules htmlTagRules = new HTMLTagRules();
|
117
|
htmlTagRules.setIncludeSingleInstanceHtml(true);
|
118
|
return TaggedCacheHelper.createString(this.taggedText, htmlTagRules);
|
119
|
}
|
120
|
}
|