diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-01-02 22:49:32 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-01-02 22:49:32 +0000 |
| commit | 77cc4cba4a6adf6fa35513c9700b745139dba12b (patch) | |
| tree | 71274df6173bcb9a9fb06976cc2182ffe0cff936 /src/main/java/org | |
| parent | 98a94a032f08e9f1d0ad6a07ea45ef539dd8eac9 (diff) | |
Pass styles into body reader
Diffstat (limited to 'src/main/java/org')
| -rw-r--r-- | src/main/java/org/zwobble/mammoth/docx/BodyXml.java | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/main/java/org/zwobble/mammoth/docx/BodyXml.java b/src/main/java/org/zwobble/mammoth/docx/BodyXml.java index df98fbc..1796367 100644 --- a/src/main/java/org/zwobble/mammoth/docx/BodyXml.java +++ b/src/main/java/org/zwobble/mammoth/docx/BodyXml.java @@ -14,11 +14,13 @@ 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) { - return readElement(element).get(0); + private final Styles styles; + + public BodyXml(Styles styles) { + this.styles = styles; } - private static List<DocumentElement> readElement(XmlElement element) { + public List<DocumentElement> readElement(XmlElement element) { switch (element.getName()) { case "w:t": return ImmutableList.of(new TextElement(element.innerText())); @@ -35,21 +37,21 @@ public class BodyXml { } } - private static ParagraphElement readParagraph(XmlElement element) { + private ParagraphElement readParagraph(XmlElement element) { return new ParagraphElement(readParagraphStyle(element), readElements(element.children())); } - private static Optional<Style> readParagraphStyle(XmlElement paragraph) { + private Optional<Style> readParagraphStyle(XmlElement paragraph) { XmlElementLike properties = paragraph.findChildOrEmpty("w:pPr"); return properties.findChildOrEmpty("w:pStyle").getAttributeOrNone("w:val") - .map(styleId -> new Style(styleId, Optional.empty())); + .map(styleId -> styles.findParagraphStyleById(styleId).orElse(new Style(styleId, Optional.empty()))); } - private static List<DocumentElement> readElements(Iterable<XmlNode> nodes) { + private List<DocumentElement> readElements(Iterable<XmlNode> nodes) { return ImmutableList.copyOf( concat( transform( filter(nodes, XmlElement.class), - BodyXml::readElement))); + this::readElement))); } } |
