| 1 | package fr.sii.ogham.core.resource.resolver; | |
| 2 | ||
| 3 | import static java.nio.charset.StandardCharsets.UTF_8; | |
| 4 | ||
| 5 | import java.util.List; | |
| 6 | ||
| 7 | import fr.sii.ogham.core.exception.resource.ResourceResolutionException; | |
| 8 | import fr.sii.ogham.core.resource.Resource; | |
| 9 | import fr.sii.ogham.core.resource.SimpleResource; | |
| 10 | import fr.sii.ogham.core.resource.path.ResolvedPath; | |
| 11 | import fr.sii.ogham.core.resource.path.ResolvedString; | |
| 12 | import fr.sii.ogham.core.resource.path.ResourcePath; | |
| 13 | ||
| 14 | /** | |
| 15 | * Resource resolver that just wraps the resource string into a {@link Resource} | |
| 16 | * | |
| 17 | * @author Aurélien Baudet | |
| 18 | * | |
| 19 | */ | |
| 20 | public class StringResourceResolver extends AbstractPrefixedLookupPathResolver { | |
| 21 | ||
| 22 | public StringResourceResolver(List<String> lookups) { | |
| 23 | super(lookups); | |
| 24 | } | |
| 25 | ||
| 26 | public StringResourceResolver(String... lookups) { | |
| 27 | super(lookups); | |
| 28 | } | |
| 29 | ||
| 30 | @Override | |
| 31 | protected Resource getResource(ResolvedPath resourcePath) throws ResourceResolutionException { | |
| 32 | // no lookup used | |
| 33 |
1
1. getResource : negated conditional → RUN_ERROR |
if(resourcePath instanceof ResolvedString) { |
| 34 |
1
1. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/StringResourceResolver::getResource → NO_COVERAGE |
return new SimpleResource(((ResolvedString) resourcePath).getContent().getBytes(UTF_8)); |
| 35 | } | |
| 36 | // when lookup is used | |
| 37 |
1
1. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/StringResourceResolver::getResource → RUN_ERROR |
return new SimpleResource(resourcePath.getResolvedPath().getBytes(UTF_8)); |
| 38 | } | |
| 39 | ||
| 40 | @Override | |
| 41 | public boolean supports(ResourcePath path) { | |
| 42 |
3
1. supports : negated conditional → RUN_ERROR 2. supports : negated conditional → RUN_ERROR 3. supports : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/StringResourceResolver::supports → RUN_ERROR |
return path instanceof ResolvedString || super.supports(path); |
| 43 | } | |
| 44 | ||
| 45 | @Override | |
| 46 | public ResolvedPath resolve(ResourcePath path) { | |
| 47 | // no lookup used | |
| 48 |
1
1. resolve : negated conditional → RUN_ERROR |
if (path instanceof ResolvedString) { |
| 49 |
1
1. resolve : replaced return value with null for fr/sii/ogham/core/resource/resolver/StringResourceResolver::resolve → NO_COVERAGE |
return (ResolvedString) path; |
| 50 | } | |
| 51 | // when lookup is used | |
| 52 |
1
1. resolve : replaced return value with null for fr/sii/ogham/core/resource/resolver/StringResourceResolver::resolve → RUN_ERROR |
return super.resolve(path); |
| 53 | } | |
| 54 | ||
| 55 | } | |
Mutations | ||
| 33 |
1.1 |
|
| 34 |
1.1 |
|
| 37 |
1.1 |
|
| 42 |
1.1 2.2 3.3 |
|
| 48 |
1.1 |
|
| 49 |
1.1 |
|
| 52 |
1.1 |