Project

General

Profile

1
package eu.dnetlib.data.transform.xml;
2

    
3
import java.util.Map;
4

    
5
import org.apache.commons.lang3.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 void setAttributes(final Map<String, String> attributes) {
42
		this.attributes = attributes;
43
	}
44

    
45
	public boolean isEmpty() {
46
		return !(hasText() || hasAttributes());
47
	}
48

    
49
	private boolean hasAttributes() {
50
		return (getAttributes() != null) && !getAttributes().isEmpty();
51
	}
52

    
53
	public boolean hasText() {
54
		return (getText() != null) && !getText().isEmpty();
55
	}
56

    
57
	@Override
58
	public String toString() {
59
		return "{ " + StringUtils.left(text, 20) + attributes.toString() + " }";
60
	}
61
}
(4-4/9)