| 1 | package pro.verron.officestamper.preset.resolvers.image; | |
| 2 | ||
| 3 | import org.docx4j.openpackaging.packages.WordprocessingMLPackage; | |
| 4 | import org.jspecify.annotations.Nullable; | |
| 5 | import pro.verron.officestamper.api.DocxPart; | |
| 6 | import pro.verron.officestamper.api.Insert; | |
| 7 | import pro.verron.officestamper.api.ObjectResolver; | |
| 8 | import pro.verron.officestamper.api.OfficeStamperException; | |
| 9 | import pro.verron.officestamper.preset.Image; | |
| 10 | ||
| 11 | /// This [ObjectResolver] allows context objects to return objects of type [Image]. An expression that resolves to an | |
| 12 | /// [Image] object will be replaced by an actual image in the resulting .docx document. The image will be put as an | |
| 13 | /// inline into the surrounding paragraph of text. | |
| 14 | /// | |
| 15 | /// @author Joseph Verron | |
| 16 | /// @version ${version} | |
| 17 | /// @since 1.6.7 | |
| 18 | public class ImageResolver | |
| 19 | implements ObjectResolver { | |
| 20 | ||
| 21 | @Override | |
| 22 | public Insert resolve(DocxPart part, String expression, @Nullable Object object) { | |
| 23 |
2
1. resolve : replaced return value with null for pro/verron/officestamper/preset/resolvers/image/ImageResolver::resolve → TIMED_OUT 2. resolve : negated conditional → TIMED_OUT |
if (object instanceof Image image) return resolve(part, image); |
| 24 | String message = "Expected %s to be an Image".formatted(object); | |
| 25 | throw new OfficeStamperException(message); | |
| 26 | } | |
| 27 | ||
| 28 | @Override | |
| 29 | public boolean canResolve(@Nullable Object object) { | |
| 30 |
2
1. canResolve : replaced boolean return with true for pro/verron/officestamper/preset/resolvers/image/ImageResolver::canResolve → TIMED_OUT 2. canResolve : replaced boolean return with false for pro/verron/officestamper/preset/resolvers/image/ImageResolver::canResolve → TIMED_OUT |
return object instanceof Image; |
| 31 | } | |
| 32 | ||
| 33 | /// Resolves an image and adds it to a [WordprocessingMLPackage] document. | |
| 34 | /// | |
| 35 | /// @param image The image to be resolved and added | |
| 36 | /// | |
| 37 | /// @return The run containing the added image | |
| 38 | /// | |
| 39 | /// @throws OfficeStamperException If an error occurs while adding the image to the document | |
| 40 | private Insert resolve(DocxPart part, Image image) { | |
| 41 | try { | |
| 42 |
1
1. resolve : replaced return value with null for pro/verron/officestamper/preset/resolvers/image/ImageResolver::resolve → TIMED_OUT |
return new Insert(image.newRun(part)); |
| 43 | } catch (Exception e) { | |
| 44 | throw new OfficeStamperException("Error while adding image to document!", e); | |
| 45 | } | |
| 46 | } | |
| 47 | ||
| 48 | } | |
Mutations | ||
| 23 |
1.1 2.2 |
|
| 30 |
1.1 2.2 |
|
| 42 |
1.1 |