summaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-01-03 11:53:34 +0000
committerMichael Williamson <mike@zwobble.org>2016-01-03 11:53:34 +0000
commit8733a942ec5e53a1f4d5ac78ffaaf8badfdee2cf (patch)
tree4bad0320d2f462d83ed0e50a9431ad149dee2433 /src/main/java/org
parentdf0e65ca725de5fb471abdd7ff8621904e41a209 (diff)
Add reading of notes XML
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/zwobble/mammoth/documents/Note.java13
-rw-r--r--src/main/java/org/zwobble/mammoth/docx/NotesXmlReader.java41
2 files changed, 54 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/mammoth/documents/Note.java b/src/main/java/org/zwobble/mammoth/documents/Note.java
new file mode 100644
index 0000000..1a0d3c0
--- /dev/null
+++ b/src/main/java/org/zwobble/mammoth/documents/Note.java
@@ -0,0 +1,13 @@
+package org.zwobble.mammoth.documents;
+
+import java.util.List;
+
+public class Note {
+ private final String id;
+ private final List<DocumentElement> body;
+
+ public Note(String id, List<DocumentElement> body) {
+ this.id = id;
+ this.body = body;
+ }
+}
diff --git a/src/main/java/org/zwobble/mammoth/docx/NotesXmlReader.java b/src/main/java/org/zwobble/mammoth/docx/NotesXmlReader.java
new file mode 100644
index 0000000..06d17ca
--- /dev/null
+++ b/src/main/java/org/zwobble/mammoth/docx/NotesXmlReader.java
@@ -0,0 +1,41 @@
+package org.zwobble.mammoth.docx;
+
+import com.google.common.collect.ImmutableList;
+import org.zwobble.mammoth.documents.Note;
+import org.zwobble.mammoth.xml.XmlElement;
+
+import java.util.List;
+
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Iterables.transform;
+
+public class NotesXmlReader {
+ private final BodyXmlReader bodyReader;
+ private final String noteType;
+
+ public NotesXmlReader(BodyXmlReader bodyReader, String noteType) {
+ this.bodyReader = bodyReader;
+ this.noteType = noteType;
+ }
+
+ public List<Note> readElement(XmlElement element) {
+ Iterable<XmlElement> elements = filter(element.findChildren("w:" + noteType), this::isNoteElement);
+ return ImmutableList.copyOf(transform(elements, this::readNoteElement));
+ }
+
+ private boolean isNoteElement(XmlElement element) {
+ return element.getAttributeOrNone("w:type")
+ .map(type -> !isSeparatorType(type))
+ .orElse(true);
+ }
+
+ private boolean isSeparatorType(String type) {
+ return type.equals("continuationSeparator") || type.equals("separator");
+ }
+
+ private Note readNoteElement(XmlElement element) {
+ return new Note(
+ element.getAttribute("w:id"),
+ bodyReader.readElements(element.children()));
+ }
+}