diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-02-20 11:35:56 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-02-20 11:35:56 +0000 |
| commit | d5f51423cd58e17c81cb52b1471670d66a1de233 (patch) | |
| tree | b535cfc9583b6db03789172c44c3c4f01d9ae46d /src/main/java/org/zwobble/mammoth/docx/DocumentReader.java | |
| parent | e7bbba7e069c1e55e9267bac3d7f23cb7bbeac01 (diff) | |
Support conversion of images
Diffstat (limited to 'src/main/java/org/zwobble/mammoth/docx/DocumentReader.java')
| -rw-r--r-- | src/main/java/org/zwobble/mammoth/docx/DocumentReader.java | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/main/java/org/zwobble/mammoth/docx/DocumentReader.java b/src/main/java/org/zwobble/mammoth/docx/DocumentReader.java index e361ac3..6d5af48 100644 --- a/src/main/java/org/zwobble/mammoth/docx/DocumentReader.java +++ b/src/main/java/org/zwobble/mammoth/docx/DocumentReader.java @@ -6,10 +6,8 @@ import org.zwobble.mammoth.results.Result; import org.zwobble.mammoth.util.MammothLists; import org.zwobble.mammoth.xml.XmlElement; -import java.io.File; import java.io.IOException; import java.util.Optional; -import java.util.zip.ZipFile; import static org.zwobble.mammoth.util.MammothLists.list; @@ -19,26 +17,22 @@ public class DocumentReader { BodyXmlReader forName(String name); } - public static Result<Document> readDocument(File file) { - try (DocxFile zipFile = new ZippedDocxFile(new ZipFile(file))) { - Styles styles = readStyles(zipFile); - Numbering numbering = Numbering.EMPTY; - ContentTypes contentTypes = ContentTypes.DEFAULT; - FileReader fileReader = uri -> { - throw new UnsupportedOperationException(); - }; - BodyReaders bodyReaders = name -> { - Relationships relationships = readRelationships(zipFile, name); - return new BodyXmlReader(styles, numbering, relationships, contentTypes, zipFile, fileReader); - }; - return readNotes(zipFile, bodyReaders) - .flatMap(notes -> { - DocumentXmlReader reader = new DocumentXmlReader(bodyReaders.forName("document"), notes); - return reader.readElement(parseOfficeXml(zipFile, "word/document.xml")); - }); - } catch (IOException e) { - throw new UnsupportedOperationException("Should return a result of failure"); - } + public static Result<Document> readDocument(DocxFile zipFile) { + Styles styles = readStyles(zipFile); + Numbering numbering = Numbering.EMPTY; + ContentTypes contentTypes = ContentTypes.DEFAULT; + FileReader fileReader = uri -> { + throw new UnsupportedOperationException(); + }; + BodyReaders bodyReaders = name -> { + Relationships relationships = readRelationships(zipFile, name); + return new BodyXmlReader(styles, numbering, relationships, contentTypes, zipFile, fileReader); + }; + return readNotes(zipFile, bodyReaders) + .flatMap(notes -> { + DocumentXmlReader reader = new DocumentXmlReader(bodyReaders.forName("document"), notes); + return reader.readElement(parseOfficeXml(zipFile, "word/document.xml")); + }); } private static Result<Notes> readNotes(DocxFile file, BodyReaders bodyReaders) { |
