diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-01-02 22:32:32 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-01-02 22:32:32 +0000 |
| commit | 98a94a032f08e9f1d0ad6a07ea45ef539dd8eac9 (patch) | |
| tree | c399c299fba1b7865a75f5455ef44a144e0eb0b8 /src/main/java/org/zwobble/mammoth/docx | |
| parent | 871df6bd1a1f7c45e750a49589c7a195c3506205 (diff) | |
Use Style class in Paragraph
Diffstat (limited to 'src/main/java/org/zwobble/mammoth/docx')
4 files changed, 12 insertions, 25 deletions
diff --git a/src/main/java/org/zwobble/mammoth/docx/BodyXml.java b/src/main/java/org/zwobble/mammoth/docx/BodyXml.java index 8aba487..df98fbc 100644 --- a/src/main/java/org/zwobble/mammoth/docx/BodyXml.java +++ b/src/main/java/org/zwobble/mammoth/docx/BodyXml.java @@ -1,10 +1,7 @@ package org.zwobble.mammoth.docx; import com.google.common.collect.ImmutableList; -import org.zwobble.mammoth.documents.DocumentElement; -import org.zwobble.mammoth.documents.ParagraphElement; -import org.zwobble.mammoth.documents.RunElement; -import org.zwobble.mammoth.documents.TextElement; +import org.zwobble.mammoth.documents.*; import org.zwobble.mammoth.xml.XmlElement; import org.zwobble.mammoth.xml.XmlElementLike; import org.zwobble.mammoth.xml.XmlNode; @@ -39,12 +36,13 @@ public class BodyXml { } private static ParagraphElement readParagraph(XmlElement element) { - return new ParagraphElement(readParagraphStyleId(element), readElements(element.children())); + return new ParagraphElement(readParagraphStyle(element), readElements(element.children())); } - private static Optional<String> readParagraphStyleId(XmlElement paragraph) { + private static Optional<Style> readParagraphStyle(XmlElement paragraph) { XmlElementLike properties = paragraph.findChildOrEmpty("w:pPr"); - return properties.findChildOrEmpty("w:pStyle").getAttributeOrNone("w:val"); + return properties.findChildOrEmpty("w:pStyle").getAttributeOrNone("w:val") + .map(styleId -> new Style(styleId, Optional.empty())); } private static List<DocumentElement> readElements(Iterable<XmlNode> nodes) { diff --git a/src/main/java/org/zwobble/mammoth/docx/Style.java b/src/main/java/org/zwobble/mammoth/docx/Style.java deleted file mode 100644 index 551a93f..0000000 --- a/src/main/java/org/zwobble/mammoth/docx/Style.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.zwobble.mammoth.docx; - -import java.util.Optional; - -public class Style { - private final Optional<String> name; - - public Style(Optional<String> name) { - this.name = name; - } - - public Optional<String> getName() { - return name; - } -} diff --git a/src/main/java/org/zwobble/mammoth/docx/Styles.java b/src/main/java/org/zwobble/mammoth/docx/Styles.java index 89098de..d2311fe 100644 --- a/src/main/java/org/zwobble/mammoth/docx/Styles.java +++ b/src/main/java/org/zwobble/mammoth/docx/Styles.java @@ -1,5 +1,7 @@ package org.zwobble.mammoth.docx; +import org.zwobble.mammoth.documents.Style; + import java.util.Map; import java.util.Optional; diff --git a/src/main/java/org/zwobble/mammoth/docx/StylesXml.java b/src/main/java/org/zwobble/mammoth/docx/StylesXml.java index 18061d1..f7a955d 100644 --- a/src/main/java/org/zwobble/mammoth/docx/StylesXml.java +++ b/src/main/java/org/zwobble/mammoth/docx/StylesXml.java @@ -1,9 +1,11 @@ package org.zwobble.mammoth.docx; +import org.zwobble.mammoth.documents.Style; import org.zwobble.mammoth.xml.XmlElement; import org.zwobble.mammoth.xml.XmlElementList; import java.util.Map; +import java.util.Optional; import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Maps.immutableEntry; @@ -24,8 +26,8 @@ public class StylesXml { } private static Map.Entry<String, Style> readStyle(XmlElement element) { - return immutableEntry( - element.getAttribute("w:styleId"), - new Style(element.findChildOrEmpty("w:name").getAttributeOrNone("w:val"))); + String styleId = element.getAttribute("w:styleId"); + Optional<String> styleName = element.findChildOrEmpty("w:name").getAttributeOrNone("w:val"); + return immutableEntry(styleId, new Style(styleId, styleName)); } } |
