diff --git a/core/src/main/java/org/opencdmp/filetransformer/docx/service/wordfiletransformer/word/WordBuilderImpl.java b/core/src/main/java/org/opencdmp/filetransformer/docx/service/wordfiletransformer/word/WordBuilderImpl.java index e4f8799..68cbfc1 100644 --- a/core/src/main/java/org/opencdmp/filetransformer/docx/service/wordfiletransformer/word/WordBuilderImpl.java +++ b/core/src/main/java/org/opencdmp/filetransformer/docx/service/wordfiletransformer/word/WordBuilderImpl.java @@ -12,6 +12,7 @@ import org.opencdmp.commonmodels.models.dmp.DmpModel; import org.opencdmp.commonmodels.models.dmpreference.DmpReferenceModel; import org.opencdmp.commonmodels.models.reference.ReferenceFieldModel; import org.opencdmp.commonmodels.models.reference.ReferenceModel; +import org.opencdmp.filetransformer.docx.service.storage.FileStorageService; import org.opencdmp.filetransformer.docx.service.storage.FileStorageServiceProperties; import org.opencdmp.filetransformer.docx.service.wordfiletransformer.WordFileTransformerServiceProperties; import org.opencdmp.filetransformer.docx.model.PidLink; @@ -27,6 +28,7 @@ import org.apache.xmlbeans.XmlObject; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.NodeTraversor; +import org.opencdmp.filetransformerbase.interfaces.FileTransformerConfiguration; import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,17 +64,17 @@ public class WordBuilderImpl implements WordBuilder { private Integer indent; private Integer imageCount; private final CTAbstractNum cTAbstractNum; - private final FileStorageServiceProperties fileStorageServiceProperties; + private final FileStorageService fileStorageService; private final WordFileTransformerServiceProperties wordFileTransformerServiceProperties; private final PidService pidService; private final Map> options = new HashMap<>(); private final Map> optionsInTable = new HashMap<>(); - public WordBuilderImpl(FileStorageServiceProperties fileStorageServiceProperties, WordFileTransformerServiceProperties wordFileTransformerServiceProperties, PidService pidService) { - this.fileStorageServiceProperties = fileStorageServiceProperties; - this.wordFileTransformerServiceProperties = wordFileTransformerServiceProperties; + public WordBuilderImpl(FileStorageService fileStorageService, WordFileTransformerServiceProperties wordFileTransformerServiceProperties, PidService pidService) { + this.fileStorageService = fileStorageService; + this.wordFileTransformerServiceProperties = wordFileTransformerServiceProperties; this.pidService = pidService; - this.cTAbstractNum = CTAbstractNum.Factory.newInstance(); + this.cTAbstractNum = CTAbstractNum.Factory.newInstance(); this.cTAbstractNum.setAbstractNumId(BigInteger.valueOf(1)); this.indent = 0; this.imageCount = 0; @@ -208,15 +210,14 @@ public class WordBuilderImpl implements WordBuilder { String fileType = itemTyped.getMimeType(); int format; format = IMAGE_TYPE_MAP.getOrDefault(fileType, 0); - - InputStream image; - ImageInputStream iis; - if (itemTyped.getFile() == null) { - throw new RuntimeException("Not implemented"); + byte[] file; + if (this.wordFileTransformerServiceProperties.isUseSharedStorage() && itemTyped.getFileRef() != null && !itemTyped.getFileRef().isBlank()) { + file = this.fileStorageService.readFile(itemTyped.getFileRef()); } else { - image = new ByteArrayInputStream(itemTyped.getFile()); - iis = ImageIO.createImageInputStream(new ByteArrayInputStream(itemTyped.getFile())); + file = itemTyped.getFile(); } + InputStream image = new ByteArrayInputStream(file); + ImageInputStream iis = ImageIO.createImageInputStream(new ByteArrayInputStream(file)); Iterator readers = ImageIO.getImageReaders(iis); if (readers.hasNext()) { ImageReader reader = readers.next(); @@ -268,8 +269,12 @@ public class WordBuilderImpl implements WordBuilder { } private int toIntFormBigInteger(Object object){ - if (object instanceof BigInteger) return ((BigInteger)object).intValue(); - return (int) object; + try { + if (object instanceof BigInteger) return ((BigInteger) object).intValue(); + return (int) object; + } catch (Exception e){ + return 0; + } } @Override