Skip to content

Commit

Permalink
Handle IOException in @image placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOellerer committed Jun 11, 2024
1 parent af06346 commit 29dfb56
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group 'com.docutools'
version = '3.0.1'
version = '3.0.2'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static XWPFPicture insertImage(XWPFParagraph paragraph, Path path, ImageS
.addPicture(in, contentType, path.getFileName().toString(), dim.width, dim.height);
} catch (InvalidFormatException | IOException e) {
logger.error("Could not insert image from given Path %s.".formatted(path), e);
throw new IllegalArgumentException("Could not insert image form given Path.", e);
throw new IllegalArgumentException("Could not insert image from given Path.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.docutools.jocument.GenerationOptions;
import com.docutools.jocument.impl.word.CustomWordPlaceholderData;
import com.docutools.jocument.impl.word.ElementRemovalException;
import com.docutools.jocument.impl.word.WordImageUtils;
import com.docutools.jocument.impl.word.WordUtilities;
import java.io.IOException;
Expand Down Expand Up @@ -37,6 +38,10 @@ protected void transform(IBodyElement placeholder, IBody part, Locale locale, Ge
var paragraph = part.insertNewParagraph(WordUtilities.openCursor(placeholder).orElseThrow());
WordImageUtils.insertImage(paragraph, path, options.imageStrategy());
WordUtilities.removeIfExists(placeholder);
} catch (IllegalArgumentException e) {
logger.error("Could not insert image", e);
} catch (ElementRemovalException e) {
logger.error("Could not remove placeholder paragraph", e);
} finally {
if (path != null && !path.equals(imagePath)) {
try {
Expand Down

0 comments on commit 29dfb56

Please sign in to comment.