1
|
/**
|
2
|
* Copyright (C) 2007 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.strategy.cache;
|
10
|
|
11
|
import java.io.Serializable;
|
12
|
import java.util.SortedSet;
|
13
|
import java.util.TreeSet;
|
14
|
|
15
|
import org.apache.commons.lang3.StringUtils;
|
16
|
|
17
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
18
|
import eu.etaxonomy.cdm.ref.TypedEntityReference;
|
19
|
|
20
|
/**
|
21
|
* @author a.kohlbecker
|
22
|
* @author m.doering
|
23
|
* @since 11.12.2007
|
24
|
*/
|
25
|
public class TaggedText implements Serializable{
|
26
|
|
27
|
private static final long serialVersionUID = -3553949743902449813L;
|
28
|
|
29
|
private String text;
|
30
|
private TagEnum type;
|
31
|
private TypedEntityReference<?> entityReference;
|
32
|
|
33
|
|
34
|
public static TaggedText NewWhitespaceInstance(){
|
35
|
return new TaggedText(TagEnum.separator, " ");
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* @see TagEnum#separator
|
40
|
*/
|
41
|
public static TaggedText NewSeparatorInstance(String separator){
|
42
|
return new TaggedText(TagEnum.separator, separator);
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* @see TagEnum#postSeparator
|
47
|
*/
|
48
|
public static TaggedText NewPostSeparatorInstance(String separator){
|
49
|
return new TaggedText(TagEnum.postSeparator, separator);
|
50
|
}
|
51
|
|
52
|
public static TaggedText NewInstance(TagEnum type, String text){
|
53
|
return new TaggedText(type, text);
|
54
|
}
|
55
|
|
56
|
|
57
|
public TaggedText() {
|
58
|
super();
|
59
|
}
|
60
|
|
61
|
public TaggedText(TagEnum type, String text, TypedEntityReference<?> entityReference) {
|
62
|
super();
|
63
|
this.text = text;
|
64
|
this.type = type;
|
65
|
this.entityReference = entityReference;
|
66
|
}
|
67
|
|
68
|
public TaggedText(TagEnum type, String text) {
|
69
|
this(type, text, null);
|
70
|
}
|
71
|
|
72
|
public String getText() {
|
73
|
return text;
|
74
|
}
|
75
|
public void setText(String text) {
|
76
|
this.text = text;
|
77
|
}
|
78
|
|
79
|
public TagEnum getType() {
|
80
|
return type;
|
81
|
}
|
82
|
public void setType(TagEnum type) {
|
83
|
this.type = type;
|
84
|
}
|
85
|
|
86
|
public TypedEntityReference<?> getEntityReference() {
|
87
|
return entityReference;
|
88
|
}
|
89
|
public void setEntityReference(TypedEntityReference<?> entityReference) {
|
90
|
this.entityReference = entityReference;
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* To be overridden by subclasses if needed.
|
95
|
*/
|
96
|
public SortedSet<String> htmlTags() {
|
97
|
return new TreeSet<>();
|
98
|
}
|
99
|
|
100
|
// **************************** EQUALS ***********************************/
|
101
|
|
102
|
@Override
|
103
|
public boolean equals(Object obj) {
|
104
|
if (this == obj) {
|
105
|
return true;
|
106
|
}
|
107
|
if (obj == null) {
|
108
|
return false;
|
109
|
}
|
110
|
if (getClass() != obj.getClass()) {
|
111
|
return false;
|
112
|
}
|
113
|
TaggedText other = (TaggedText) obj;
|
114
|
if (!CdmUtils.nullSafeEqual(entityReference, other.entityReference)) {
|
115
|
return false;
|
116
|
}
|
117
|
if (!CdmUtils.nullSafeEqual(text, other.text)) {
|
118
|
return false;
|
119
|
}
|
120
|
if (!CdmUtils.nullSafeEqual(type, other.type)) {
|
121
|
return false;
|
122
|
}
|
123
|
return true;
|
124
|
}
|
125
|
|
126
|
|
127
|
@Override
|
128
|
public int hashCode() {
|
129
|
final int prime = 31;
|
130
|
int result = 1;
|
131
|
result = prime * result + ((entityReference == null) ? 0 : entityReference.hashCode());
|
132
|
result = prime * result + ((text == null) ? 0 : text.hashCode());
|
133
|
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
134
|
return result;
|
135
|
}
|
136
|
|
137
|
// **************************** TO STRING ***********************************/
|
138
|
|
139
|
@Override
|
140
|
public String toString(){
|
141
|
String result = CdmUtils.concat(":", type.toString(), text);
|
142
|
if (StringUtils.isBlank(result)){
|
143
|
return super.toString();
|
144
|
}else{
|
145
|
return result;
|
146
|
}
|
147
|
}
|
148
|
|
149
|
|
150
|
|
151
|
}
|