blob: a8b724602d926108a1fa9bcb415073ec3e98ef7b (
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
|
package org.zwobble.mammoth.docx;
import com.google.common.collect.ImmutableList;
import org.zwobble.mammoth.documents.DocumentElement;
import org.zwobble.mammoth.documents.RunElement;
import org.zwobble.mammoth.documents.TextElement;
import org.zwobble.mammoth.xml.XmlElement;
import org.zwobble.mammoth.xml.XmlNode;
import java.util.List;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
public class BodyXml {
public static DocumentElement readBodyXmlElement(XmlElement element) {
switch (element.getName()) {
case "w:t":
return new TextElement(element.innerText());
case "w:r":
return new RunElement(readElements(element.children()));
default:
throw new UnsupportedOperationException();
}
}
private static List<DocumentElement> readElements(Iterable<XmlNode> nodes) {
return ImmutableList.copyOf(
transform(
filter(nodes, XmlElement.class),
BodyXml::readBodyXmlElement));
}
}
|