1 | package fr.sii.ogham.spring.v1.template.thymeleaf; | |
2 | ||
3 | import java.util.Map; | |
4 | import java.util.Map.Entry; | |
5 | ||
6 | import org.slf4j.Logger; | |
7 | import org.slf4j.LoggerFactory; | |
8 | import org.thymeleaf.context.AbstractContext; | |
9 | import org.thymeleaf.context.IContext; | |
10 | ||
11 | import fr.sii.ogham.spring.template.thymeleaf.ContextMerger; | |
12 | ||
13 | /** | |
14 | * Add additional variables to an existing Thymeleaf context. It only works if | |
15 | * the {@link IContext} instance extends {@link AbstractContext}. | |
16 | * | |
17 | * It updates the original context in place returning the same instance. | |
18 | * | |
19 | * If you need to set variables on an instance that doesn't inherit from | |
20 | * {@link AbstractContext}, you have to provide another implementation. | |
21 | * | |
22 | * @author Aurélien Baudet | |
23 | * | |
24 | */ | |
25 | public class UpdateCurrentContextMerger implements ContextMerger { | |
26 | private static final Logger LOG = LoggerFactory.getLogger(UpdateCurrentContextMerger.class); | |
27 | ||
28 | @Override | |
29 | public IContext mergeVariables(IContext base, Map<String, Object> additionalVariables) { | |
30 |
1
1. mergeVariables : negated conditional → TIMED_OUT |
if (base instanceof AbstractContext) { |
31 |
1
1. mergeVariables : removed call to org/thymeleaf/context/AbstractContext::setVariables → TIMED_OUT |
((AbstractContext) base).setVariables(additionalVariables); |
32 | } else { | |
33 | LOG.debug("Not an AbstractContext => skip additional variables"); | |
34 | } | |
35 |
1
1. mergeVariables : replaced return value with null for fr/sii/ogham/spring/v1/template/thymeleaf/UpdateCurrentContextMerger::mergeVariables → TIMED_OUT |
return base; |
36 | } | |
37 | ||
38 | @Override | |
39 | public IContext merge(IContext base, IContext other) { | |
40 | for (Entry<String, Object> variable : other.getVariables().entrySet()) { | |
41 |
1
1. merge : negated conditional → TIMED_OUT |
if (base instanceof AbstractContext) { |
42 |
1
1. merge : removed call to org/thymeleaf/context/AbstractContext::setVariable → TIMED_OUT |
((AbstractContext) base).setVariable(variable.getKey(), variable.getValue()); |
43 | } else { | |
44 | LOG.debug("Not an AbstractContext => skip additional variables"); | |
45 | } | |
46 | } | |
47 |
1
1. merge : replaced return value with null for fr/sii/ogham/spring/v1/template/thymeleaf/UpdateCurrentContextMerger::merge → TIMED_OUT |
return base; |
48 | } | |
49 | } | |
Mutations | ||
30 |
1.1 |
|
31 |
1.1 |
|
35 |
1.1 |
|
41 |
1.1 |
|
42 |
1.1 |
|
47 |
1.1 |