ObjectResolver.java

1
package pro.verron.officestamper.api;
2
3
import org.docx4j.TextUtils;
4
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
5
import org.docx4j.wml.R;
6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
8
import org.springframework.lang.Nullable;
9
10
/**
11
 * The ObjectResolver interface provides a contract for resolving objects to create a run
12
 * with the resolved content. It includes methods to check if an object can be resolved
13
 * and to actually resolve an object to a run.
14
 *
15
 * @author Joseph Verron
16
 * @version ${version}
17
 * @since 1.6.7
18
 */
19
public interface ObjectResolver {
20
21
    Logger LOGGER = LoggerFactory.getLogger(ObjectResolver.class);
22
23
    /**
24
     * Resolves the expression in the given document with the provided object.
25
     *
26
     * @param document    the {@link WordprocessingMLPackage} document in
27
     *                    which to resolve the expression
28
     * @param placeholder the expression value to be replaced
29
     * @param object      the object to be used for resolving the expression
30
     *
31
     * @return the resolved value for the expression
32
     *
33
     * @throws OfficeStamperException if no resolver is found for the object
34
     */
35
    default R resolve(DocxPart document, Placeholder placeholder, Object object) {
36
        R resolution = resolve(document, placeholder.content(), object);
37
        if (LOGGER.isDebugEnabled()) {
38
            var message = "Expression '{}' replaced by '{}' with resolver {}";
39
            var expression = placeholder.expression();
40
            var text = TextUtils.getText(resolution);
41
            var resolverName = getClass().getSimpleName();
42
            LOGGER.debug(message, expression, text, resolverName);
43
        }
44 1 1. resolve : replaced return value with null for pro/verron/officestamper/api/ObjectResolver::resolve → KILLED
        return resolution;
45
    }
46
47
    /**
48
     * Resolves the expression in the given document with the provided object.
49
     * <p>
50
     * Replace the previous {@link #resolve(WordprocessingMLPackage, String, Object)}
51
     *
52
     * @param docxPart   the {@link DocxPart} document in
53
     *                   which to resolve the expression
54
     * @param expression the expression value to be replaced
55
     * @param object     the object to be used for resolving the expression
56
     *
57
     * @return the resolved value for the expression
58
     *
59
     * @throws OfficeStamperException if no resolver is found for the object
60
     */
61
    default R resolve(DocxPart docxPart, String expression, Object object) {
62 1 1. resolve : replaced return value with null for pro/verron/officestamper/api/ObjectResolver::resolve → NO_COVERAGE
        return resolve(docxPart.document(), expression, object);
63
    }
64
65
    /**
66
     * @deprecated replaced by {@link #resolve(DocxPart, String, Object)}
67
     */
68
    @Deprecated(since = "2.3", forRemoval = true)
69
    default R resolve(WordprocessingMLPackage document, String expression, Object object) {
70
        throw new OfficeStamperException("Should not be called, only legacy implementation might still override this");
71
    }
72
73
    /**
74
     * Checks if the given object can be resolved.
75
     *
76
     * @param object the object to be resolved
77
     *
78
     * @return true if the object can be resolved, false otherwise
79
     */
80
    boolean canResolve(@Nullable Object object);
81
82
}

Mutations

44

1.1
Location : resolve
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#25]
replaced return value with null for pro/verron/officestamper/api/ObjectResolver::resolve → KILLED

62

1.1
Location : resolve
Killed by : none
replaced return value with null for pro/verron/officestamper/api/ObjectResolver::resolve → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.17.0