From d5f51423cd58e17c81cb52b1471670d66a1de233 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 20 Feb 2016 11:35:56 +0000 Subject: Support conversion of images --- .../org/zwobble/mammoth/docx/DocumentReader.java | 38 +++++++++------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'src/main/java/org/zwobble/mammoth/docx/DocumentReader.java') 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 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 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 readNotes(DocxFile file, BodyReaders bodyReaders) { -- cgit v1.2.3