| 1 | package fr.sii.ogham.html.inliner.impl.regexp; | |
| 2 | ||
| 3 | import static fr.sii.ogham.email.attachment.ContentDisposition.INLINE; | |
| 4 | import static fr.sii.ogham.html.inliner.impl.regexp.CssImageInlinerConstants.InlineModes.ATTACH; | |
| 5 | import static java.text.MessageFormat.format; | |
| 6 | ||
| 7 | import java.util.ArrayList; | |
| 8 | import java.util.List; | |
| 9 | ||
| 10 | import fr.sii.ogham.core.id.generator.IdGenerator; | |
| 11 | import fr.sii.ogham.core.resource.ByteResource; | |
| 12 | import fr.sii.ogham.email.attachment.Attachment; | |
| 13 | import fr.sii.ogham.html.inliner.ContentWithImages; | |
| 14 | import fr.sii.ogham.html.inliner.ImageInliner; | |
| 15 | import fr.sii.ogham.html.inliner.ImageResource; | |
| 16 | import fr.sii.ogham.html.inliner.impl.regexp.CssImageInlinerConstants.InlineModes; | |
| 17 | ||
| 18 | /** | |
| 19 | * Image inliner that loads the image and attaches it to the mail. The image is | |
| 20 | * referenced using a content ID. The content ID is automatically generated. | |
| 21 | * | |
| 22 | * <p> | |
| 23 | * The inlining using attach mode is only applied if the attribute | |
| 24 | * {@link CssImageInlinerConstants#INLINE_MODE_PROPERTY} is set to | |
| 25 | * {@link InlineModes#ATTACH}. | |
| 26 | * </p> | |
| 27 | * | |
| 28 | * @author Aurélien Baudet | |
| 29 | * | |
| 30 | */ | |
| 31 | public class RegexAttachBackgroudImageInliner implements ImageInliner { | |
| 32 | private static final String CONTENT_ID = "<{0}>"; | |
| 33 | private static final String URL_VALUE = "cid:{0}"; | |
| 34 | ||
| 35 | private IdGenerator idGenerator; | |
| 36 | ||
| 37 | public RegexAttachBackgroudImageInliner(IdGenerator idGenerator) { | |
| 38 | super(); | |
| 39 | this.idGenerator = idGenerator; | |
| 40 | } | |
| 41 | ||
| 42 | @Override | |
| 43 | public ContentWithImages inline(String htmlContent, List<ImageResource> images) { | |
| 44 | List<Attachment> attachments = new ArrayList<>(images.size()); | |
| 45 |
3
1. lambda$inline$0 : replaced return value with "" for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::lambda$inline$0 → NO_COVERAGE 2. lambda$inline$0 : replaced return value with "" for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::lambda$inline$0 → KILLED 3. lambda$inline$0 : replaced return value with "" for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::lambda$inline$0 → KILLED |
String inlined = CssImageInlineUtils.inline(htmlContent, images, ATTACH, decl -> attachImage(decl.getUrl().getUrl(), decl.getImage(), attachments)); |
| 46 |
3
1. inline : replaced return value with null for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::inline → NO_COVERAGE 2. inline : replaced return value with null for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::inline → KILLED 3. inline : replaced return value with null for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::inline → KILLED |
return new ContentWithImages(inlined, attachments); |
| 47 | } | |
| 48 | ||
| 49 | private String attachImage(String url, ImageResource image, List<Attachment> attachments) { | |
| 50 | Attachment alreadyAttached = getAttachmentForUrl(url, attachments); | |
| 51 |
3
1. attachImage : negated conditional → NO_COVERAGE 2. attachImage : negated conditional → KILLED 3. attachImage : negated conditional → KILLED |
if (alreadyAttached != null) { |
| 52 | String cid = alreadyAttached.getContentId(); | |
| 53 |
4
1. attachImage : replaced return value with "" for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::attachImage → NO_COVERAGE 2. attachImage : Replaced integer subtraction with addition → NO_COVERAGE 3. attachImage : replaced return value with "" for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::attachImage → KILLED 4. attachImage : Replaced integer subtraction with addition → KILLED |
return format(URL_VALUE, cid.substring(1, cid.length() - 1)); |
| 54 | } | |
| 55 | String contentId = idGenerator.generate(image.getName()); | |
| 56 | Attachment attachment = new Attachment(new ByteResource(image.getName(), image.getContent()), url, INLINE, format(CONTENT_ID, contentId)); | |
| 57 | attachments.add(attachment); | |
| 58 |
3
1. attachImage : replaced return value with "" for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::attachImage → NO_COVERAGE 2. attachImage : replaced return value with "" for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::attachImage → KILLED 3. attachImage : replaced return value with "" for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::attachImage → KILLED |
return format(URL_VALUE, contentId); |
| 59 | } | |
| 60 | ||
| 61 | private static Attachment getAttachmentForUrl(String url, List<Attachment> attachments) { | |
| 62 | // @formatter:off | |
| 63 |
3
1. getAttachmentForUrl : replaced return value with null for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::getAttachmentForUrl → SURVIVED 2. getAttachmentForUrl : replaced return value with null for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::getAttachmentForUrl → NO_COVERAGE 3. getAttachmentForUrl : replaced return value with null for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::getAttachmentForUrl → KILLED |
return attachments.stream() |
| 64 |
4
1. lambda$getAttachmentForUrl$1 : replaced boolean return with false for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::lambda$getAttachmentForUrl$1 → NO_COVERAGE 2. lambda$getAttachmentForUrl$1 : replaced boolean return with true for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::lambda$getAttachmentForUrl$1 → NO_COVERAGE 3. lambda$getAttachmentForUrl$1 : replaced boolean return with false for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::lambda$getAttachmentForUrl$1 → KILLED 4. lambda$getAttachmentForUrl$1 : replaced boolean return with true for fr/sii/ogham/html/inliner/impl/regexp/RegexAttachBackgroudImageInliner::lambda$getAttachmentForUrl$1 → KILLED |
.filter(a -> url.equals(a.getDescription())) |
| 65 | .findFirst() | |
| 66 | .orElse(null); | |
| 67 | // @formatter:on | |
| 68 | } | |
| 69 | } | |
Mutations | ||
| 45 |
1.1 2.2 3.3 |
|
| 46 |
1.1 2.2 3.3 |
|
| 51 |
1.1 2.2 3.3 |
|
| 53 |
1.1 2.2 3.3 4.4 |
|
| 58 |
1.1 2.2 3.3 |
|
| 63 |
1.1 2.2 3.3 |
|
| 64 |
1.1 2.2 3.3 4.4 |