1 | package fr.sii.ogham.template.thymeleaf.common.adapter; | |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.Arrays; | |
5 | import java.util.List; | |
6 | ||
7 | import org.thymeleaf.templateresolver.ITemplateResolver; | |
8 | ||
9 | import fr.sii.ogham.core.resource.resolver.ResourceResolver; | |
10 | import fr.sii.ogham.template.exception.NoResolverAdapterException; | |
11 | import fr.sii.ogham.template.thymeleaf.common.TemplateResolverOptions; | |
12 | ||
13 | /** | |
14 | * Decorator that will ask each resolver adapter if it is able to handle the | |
15 | * template resolver. If the resolver adapter supports it, then this | |
16 | * implementation asks the resolver adapter to provide the Thymeleaf template | |
17 | * resolver. | |
18 | * | |
19 | * Only the first resolver adapter that can handle the template resolver is | |
20 | * used. | |
21 | * | |
22 | * @author Aurélien Baudet | |
23 | */ | |
24 | public class FirstSupportingResolverAdapter implements TemplateResolverAdapter { | |
25 | ||
26 | /** | |
27 | * The list of adapters used to convert the general resolvers into Thymeleaf | |
28 | * specific resolvers | |
29 | */ | |
30 | private List<TemplateResolverAdapter> adapters; | |
31 | ||
32 | /** | |
33 | * Initialize the decorator with none, one or several resolver adapter | |
34 | * implementations. The registration order may be important. | |
35 | * | |
36 | * @param adapters | |
37 | * the adapters to register | |
38 | */ | |
39 | public FirstSupportingResolverAdapter(TemplateResolverAdapter... adapters) { | |
40 | this(new ArrayList<>(Arrays.asList(adapters))); | |
41 | } | |
42 | ||
43 | /** | |
44 | * Initialize the decorator with the provided resolver adapter | |
45 | * implementations. The registration order may be important. | |
46 | * | |
47 | * @param adapters | |
48 | * the adapters to register | |
49 | */ | |
50 | public FirstSupportingResolverAdapter(List<TemplateResolverAdapter> adapters) { | |
51 | super(); | |
52 | this.adapters = adapters; | |
53 | } | |
54 | ||
55 | public FirstSupportingResolverAdapter() { | |
56 | this(new ArrayList<>()); | |
57 | } | |
58 | ||
59 | @Override | |
60 | public boolean supports(ResourceResolver resolver) { | |
61 | for (TemplateResolverAdapter adapter : adapters) { | |
62 |
2
1. supports : negated conditional → NO_COVERAGE 2. supports : negated conditional → KILLED |
if (adapter.supports(resolver)) { |
63 |
2
1. supports : replaced boolean return with false for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::supports → NO_COVERAGE 2. supports : replaced boolean return with false for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::supports → KILLED |
return true; |
64 | } | |
65 | } | |
66 |
2
1. supports : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::supports → NO_COVERAGE 2. supports : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::supports → KILLED |
return false; |
67 | } | |
68 | ||
69 | @Override | |
70 | public ITemplateResolver adapt(ResourceResolver resolver) throws NoResolverAdapterException { | |
71 | for (TemplateResolverAdapter adapter : adapters) { | |
72 |
5
1. adapt : negated conditional → TIMED_OUT 2. adapt : negated conditional → KILLED 3. adapt : negated conditional → KILLED 4. adapt : negated conditional → KILLED 5. adapt : negated conditional → KILLED |
if (adapter.supports(resolver)) { |
73 |
5
1. adapt : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → TIMED_OUT 2. adapt : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → KILLED 3. adapt : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → KILLED 4. adapt : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → KILLED 5. adapt : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → KILLED |
return adapter.adapt(resolver); |
74 | } | |
75 | } | |
76 | throw new NoResolverAdapterException("No resolver adapter found for the provided resolver: " + resolver.getClass().getSimpleName(), resolver); | |
77 | } | |
78 | ||
79 | /** | |
80 | * Register a new adapter. The adapter is added at the end. | |
81 | * | |
82 | * @param adapter | |
83 | * the adapter to register | |
84 | */ | |
85 | public void addAdapter(TemplateResolverAdapter adapter) { | |
86 | adapters.add(adapter); | |
87 | } | |
88 | ||
89 | public List<TemplateResolverAdapter> getAdapters() { | |
90 |
1
1. getAdapters : replaced return value with Collections.emptyList for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::getAdapters → NO_COVERAGE |
return adapters; |
91 | } | |
92 | ||
93 | @Override | |
94 | public void setOptions(TemplateResolverOptions options) { | |
95 | for (TemplateResolverAdapter adapter : adapters) { | |
96 |
6
1. setOptions : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → NO_COVERAGE 2. setOptions : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → TIMED_OUT 3. setOptions : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → KILLED 4. setOptions : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → KILLED 5. setOptions : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → KILLED 6. setOptions : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → KILLED |
adapter.setOptions(options); |
97 | } | |
98 | } | |
99 | } | |
Mutations | ||
62 |
1.1 2.2 |
|
63 |
1.1 2.2 |
|
66 |
1.1 2.2 |
|
72 |
1.1 2.2 3.3 4.4 5.5 |
|
73 |
1.1 2.2 3.3 4.4 5.5 |
|
90 |
1.1 |
|
96 |
1.1 2.2 3.3 4.4 5.5 6.6 |