aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/mammoth/docx/DocumentXmlReader.java
blob: 5e94e2fc1bb9048f28f4f2068bfd098d4af83fa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package org.zwobble.mammoth.docx;

import org.zwobble.mammoth.documents.Document;
import org.zwobble.mammoth.documents.Notes;
import org.zwobble.mammoth.results.Result;
import org.zwobble.mammoth.xml.XmlElement;

public class DocumentXmlReader {
    private final BodyXmlReader bodyReader;
    private final Notes notes;

    public DocumentXmlReader(BodyXmlReader bodyReader, Notes notes) {
        this.bodyReader = bodyReader;
        this.notes = notes;
    }

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