blob: 729625f810f2b8f95c0cc43a803c81209dc7596d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package org.zwobble.mammoth.internal.html;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.zwobble.mammoth.internal.util.Sets.set;
public class HtmlElement implements HtmlNode {
private final HtmlTag tag;
private final List<HtmlNode> children;
public HtmlElement(HtmlTag tag, List<HtmlNode> children) {
this.tag = tag;
this.children = children;
}
public HtmlTag getTag() {
return tag;
}
public List<String> getTagNames() {
return tag.getTagNames();
}
public String getTagName() {
return getTagNames().get(0);
}
public Map<String, String> getAttributes() {
return tag.getAttributes();
}
public List<HtmlNode> getChildren() {
return children;
}
public boolean isCollapsible() {
return tag.isCollapsible();
}
public String getSeparator() {
return tag.getSeparator();
}
public boolean isVoid() {
return children.isEmpty() && isVoidTag(getTagName());
}
private static final Set<String> VOID_TAG_NAMES = set("br", "hr", "img", "input");
private static boolean isVoidTag(String tagName) {
return VOID_TAG_NAMES.contains(tagName);
}
@Override
public void accept(Visitor visitor) {
visitor.visit(this);
}
@Override
public <T> T accept(Mapper<T> visitor) {
return visitor.visit(this);
}
}
|