summaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/mammoth/internal/docx/DocumentXmlReader.java
blob: 25855f3cdd661ee31c340c19362af05b5336d09e (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
package org.zwobble.mammoth.internal.docx;

import org.zwobble.mammoth.internal.documents.Comment;
import org.zwobble.mammoth.internal.documents.Document;
import org.zwobble.mammoth.internal.documents.Notes;
import org.zwobble.mammoth.internal.results.InternalResult;
import org.zwobble.mammoth.internal.xml.XmlElement;
import org.zwobble.mammoth.internal.xml.XmlElementLike;

import java.util.List;

public class DocumentXmlReader {
    private final BodyXmlReader bodyReader;
    private final Notes notes;
    private final List<Comment> comments;

    public DocumentXmlReader(BodyXmlReader bodyReader, Notes notes, List<Comment> comments) {
        this.bodyReader = bodyReader;
        this.notes = notes;
        this.comments = comments;
    }

    public InternalResult<Document> readElement(XmlElement element) {
        XmlElementLike body = element.findChildOrEmpty("w:body");
        return bodyReader.readElements(body.getChildren())
            .toResult()
            .map(children -> new Document(children, notes, comments));
    }
}