aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-20 15:23:54 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-20 15:23:54 +0000
commit7ecf37adc3faff67781bdf46e624b54a35da9a54 (patch)
treeca77a5b94006b4e60983a773c2b260ca2fa763d6 /src/main/java
parent32aee86473c4e0865e9ad181be2b8418cd93c9a0 (diff)
Return result from document conversion
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/zwobble/mammoth/DocumentConverter.java16
-rw-r--r--src/main/java/org/zwobble/mammoth/Mammoth.java2
2 files changed, 13 insertions, 5 deletions
diff --git a/src/main/java/org/zwobble/mammoth/DocumentConverter.java b/src/main/java/org/zwobble/mammoth/DocumentConverter.java
index d04d012..294e403 100644
--- a/src/main/java/org/zwobble/mammoth/DocumentConverter.java
+++ b/src/main/java/org/zwobble/mammoth/DocumentConverter.java
@@ -7,6 +7,8 @@ import com.google.common.io.ByteStreams;
import org.zwobble.mammoth.documents.*;
import org.zwobble.mammoth.html.Html;
import org.zwobble.mammoth.html.HtmlNode;
+import org.zwobble.mammoth.results.Result;
+import org.zwobble.mammoth.results.Warning;
import org.zwobble.mammoth.styles.StyleMap;
import org.zwobble.mammoth.util.MammothLists;
@@ -20,9 +22,11 @@ import static org.zwobble.mammoth.util.MammothLists.*;
import static org.zwobble.mammoth.util.MammothMaps.map;
public class DocumentConverter {
- public static List<HtmlNode> convertToHtml(String idPrefix, boolean preserveEmptyParagraphs, StyleMap styleMap, Document document) {
+ public static Result<List<HtmlNode>> convertToHtml(String idPrefix, boolean preserveEmptyParagraphs, StyleMap styleMap, Document document) {
DocumentConverter documentConverter = new DocumentConverter(idPrefix, preserveEmptyParagraphs, styleMap);
- return documentConverter.convertToHtml(document);
+ return new Result<>(
+ documentConverter.convertToHtml(document),
+ documentConverter.warnings.build());
}
private static List<Note> findNotes(Document document, Iterable<NoteReference> noteReferences) {
@@ -32,14 +36,18 @@ public class DocumentConverter {
reference -> document.getNotes().findNote(reference.getNoteType(), reference.getNoteId()).get()));
}
- public static List<HtmlNode> convertToHtml(String idPrefix, boolean preserveEmptyParagraphs, StyleMap styleMap, DocumentElement element) {
- return new DocumentConverter(idPrefix, preserveEmptyParagraphs, styleMap).convertToHtml(element);
+ public static Result<List<HtmlNode>> convertToHtml(String idPrefix, boolean preserveEmptyParagraphs, StyleMap styleMap, DocumentElement element) {
+ DocumentConverter documentConverter = new DocumentConverter(idPrefix, preserveEmptyParagraphs, styleMap);
+ return new Result<>(
+ documentConverter.convertToHtml(element),
+ documentConverter.warnings.build());
}
private final String idPrefix;
private final boolean preserveEmptyParagraphs;
private final StyleMap styleMap;
private final List<NoteReference> noteReferences = new ArrayList<>();
+ private final ImmutableList.Builder<Warning> warnings = ImmutableList.builder();
private DocumentConverter(String idPrefix, boolean preserveEmptyParagraphs, StyleMap styleMap) {
this.idPrefix = idPrefix;
diff --git a/src/main/java/org/zwobble/mammoth/Mammoth.java b/src/main/java/org/zwobble/mammoth/Mammoth.java
index 6db7308..b6bba55 100644
--- a/src/main/java/org/zwobble/mammoth/Mammoth.java
+++ b/src/main/java/org/zwobble/mammoth/Mammoth.java
@@ -49,7 +49,7 @@ public class Mammoth {
public static Result<String> convertToHtml(File file, Options options) {
return withDocxFile(file, zipFile ->
readDocument(zipFile)
- .map(nodes -> DocumentConverter.convertToHtml(options.idPrefix, options.preserveEmptyParagraphs, StyleMap.EMPTY, nodes))
+ .flatMap(nodes -> DocumentConverter.convertToHtml(options.idPrefix, options.preserveEmptyParagraphs, StyleMap.EMPTY, nodes))
.map(Html::stripEmpty)
.map(Html::collapse)
.map(Html::write));