| 1 | package fr.sii.ogham.html.inliner; | |
| 2 | ||
| 3 | import java.util.Arrays; | |
| 4 | ||
| 5 | import fr.sii.ogham.core.resource.path.ResourcePath; | |
| 6 | import fr.sii.ogham.html.translator.InlineImageTranslator; | |
| 7 | ||
| 8 | /** | |
| 9 | * A simple object that represents an image to be usable by the | |
| 10 | * {@link InlineImageTranslator}. The aim is to decouple the translator | |
| 11 | * implementation from the general system. | |
| 12 | * | |
| 13 | * @author Aurélien Baudet | |
| 14 | * | |
| 15 | */ | |
| 16 | public class ImageResource { | |
| 17 | private final String name; | |
| 18 | ||
| 19 | private final String srcUrl; | |
| 20 | ||
| 21 | private final ResourcePath path; | |
| 22 | ||
| 23 | private final byte[] content; | |
| 24 | ||
| 25 | private final String mimetype; | |
| 26 | ||
| 27 | /** | |
| 28 | * Initialize the resource with the name of the image, the path of the image | |
| 29 | * found in the HTML, the content of the image as array of bytes and the | |
| 30 | * mimetype of the image. The bytes for the content of the image are copied | |
| 31 | * into a new array to prevent security leaks. | |
| 32 | * | |
| 33 | * @param name | |
| 34 | * the name of the image | |
| 35 | * @param srcUrl | |
| 36 | * the URL of the image used in the html content | |
| 37 | * @param path | |
| 38 | * the path to the image | |
| 39 | * @param content | |
| 40 | * the content of the image | |
| 41 | * @param mimetype | |
| 42 | * the mimetype of the image | |
| 43 | */ | |
| 44 | public ImageResource(String name, String srcUrl, ResourcePath path, byte[] content, String mimetype) { | |
| 45 | super(); | |
| 46 | this.name = name; | |
| 47 | this.srcUrl = srcUrl; | |
| 48 | this.path = path; | |
| 49 | this.content = Arrays.copyOf(content, content.length); | |
| 50 | this.mimetype = mimetype; | |
| 51 | } | |
| 52 | ||
| 53 | public String getSrcUrl() { | |
| 54 |
3
1. getSrcUrl : replaced return value with "" for fr/sii/ogham/html/inliner/ImageResource::getSrcUrl → NO_COVERAGE 2. getSrcUrl : replaced return value with "" for fr/sii/ogham/html/inliner/ImageResource::getSrcUrl → KILLED 3. getSrcUrl : replaced return value with "" for fr/sii/ogham/html/inliner/ImageResource::getSrcUrl → KILLED |
return srcUrl; |
| 55 | } | |
| 56 | ||
| 57 | public ResourcePath getPath() { | |
| 58 |
1
1. getPath : replaced return value with null for fr/sii/ogham/html/inliner/ImageResource::getPath → NO_COVERAGE |
return path; |
| 59 | } | |
| 60 | ||
| 61 | public byte[] getContent() { | |
| 62 |
3
1. getContent : replaced return value with null for fr/sii/ogham/html/inliner/ImageResource::getContent → NO_COVERAGE 2. getContent : replaced return value with null for fr/sii/ogham/html/inliner/ImageResource::getContent → KILLED 3. getContent : replaced return value with null for fr/sii/ogham/html/inliner/ImageResource::getContent → KILLED |
return content; |
| 63 | } | |
| 64 | ||
| 65 | public String getMimetype() { | |
| 66 |
3
1. getMimetype : replaced return value with "" for fr/sii/ogham/html/inliner/ImageResource::getMimetype → NO_COVERAGE 2. getMimetype : replaced return value with "" for fr/sii/ogham/html/inliner/ImageResource::getMimetype → KILLED 3. getMimetype : replaced return value with "" for fr/sii/ogham/html/inliner/ImageResource::getMimetype → KILLED |
return mimetype; |
| 67 | } | |
| 68 | ||
| 69 | public String getName() { | |
| 70 |
3
1. getName : replaced return value with "" for fr/sii/ogham/html/inliner/ImageResource::getName → NO_COVERAGE 2. getName : replaced return value with "" for fr/sii/ogham/html/inliner/ImageResource::getName → KILLED 3. getName : replaced return value with "" for fr/sii/ogham/html/inliner/ImageResource::getName → KILLED |
return name; |
| 71 | } | |
| 72 | | |
| 73 | @Override | |
| 74 | public String toString() { | |
| 75 | StringBuilder builder = new StringBuilder(); | |
| 76 | builder.append("ImageResource(") | |
| 77 | .append("src=").append(srcUrl).append(", ") | |
| 78 | .append("path=").append(path).append(", ") | |
| 79 | .append("name=").append(name).append(", ") | |
| 80 | .append("mimetype=").append(mimetype).append(")"); | |
| 81 |
1
1. toString : replaced return value with "" for fr/sii/ogham/html/inliner/ImageResource::toString → NO_COVERAGE |
return builder.toString(); |
| 82 | } | |
| 83 | } | |
Mutations | ||
| 54 |
1.1 2.2 3.3 |
|
| 58 |
1.1 |
|
| 62 |
1.1 2.2 3.3 |
|
| 66 |
1.1 2.2 3.3 |
|
| 70 |
1.1 2.2 3.3 |
|
| 81 |
1.1 |