1
|
package eu.dnetlib.data.transform.xml;
|
2
|
|
3
|
import java.util.Map;
|
4
|
|
5
|
import org.apache.commons.lang.StringUtils;
|
6
|
|
7
|
import com.google.common.collect.Maps;
|
8
|
|
9
|
public class Element {
|
10
|
|
11
|
private String text;
|
12
|
private Map<String, String> attributes;
|
13
|
|
14
|
public Element(final String text, final Map<String, String> attributes) {
|
15
|
this.text = text;
|
16
|
this.attributes = attributes;
|
17
|
}
|
18
|
|
19
|
public Element(final String text) {
|
20
|
this.text = text;
|
21
|
this.attributes = Maps.newHashMap();
|
22
|
}
|
23
|
|
24
|
public Element() {
|
25
|
this.text = "";
|
26
|
this.attributes = Maps.newHashMap();
|
27
|
}
|
28
|
|
29
|
public String getText() {
|
30
|
return text;
|
31
|
}
|
32
|
|
33
|
public void setText(final String text) {
|
34
|
this.text = text;
|
35
|
}
|
36
|
|
37
|
public Map<String, String> getAttributes() {
|
38
|
return attributes;
|
39
|
}
|
40
|
|
41
|
public String getAttributeValue(final String attributeName) {
|
42
|
return getAttributes().get(attributeName);
|
43
|
}
|
44
|
|
45
|
public void setAttributes(final Map<String, String> attributes) {
|
46
|
this.attributes = attributes;
|
47
|
}
|
48
|
|
49
|
public boolean isEmpty() {
|
50
|
return !(hasText() || hasAttributes());
|
51
|
}
|
52
|
|
53
|
private boolean hasAttributes() {
|
54
|
return (getAttributes() != null) && !getAttributes().isEmpty();
|
55
|
}
|
56
|
|
57
|
public boolean hasText() {
|
58
|
return (getText() != null) && !getText().isEmpty();
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
public String toString() {
|
63
|
return "{ " + StringUtils.left(text, 20) + attributes.toString() + " }";
|
64
|
}
|
65
|
}
|