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
/// The ObjectResolver interface provides a contract for resolving objects to create a run
11
/// with the resolved content. It includes methods to check if an object can be resolved
12
/// and to actually resolve an object to a run.
13
///
14
/// @author Joseph Verron
15
/// @version ${version}
16
/// @since 1.6.7
17
public interface ObjectResolver {
18
19
    /// A logger instance used for logging messages and events related to the operations
20
    /// performed within the ObjectResolver interface.
21
    /// This helps in tracking, debugging, and analyzing the execution of methods
22
    /// implemented by classes that use this interface.
23
    Logger LOGGER = LoggerFactory.getLogger(ObjectResolver.class);
24
25
    /// Resolves the expression in the given document with the provided object.
26
    ///
27
    /// @param document    the [WordprocessingMLPackage] document in
28
    ///                    which to resolve the expression
29
    /// @param placeholder the expression value to be replaced
30
    /// @param object      the object to be used for resolving the expression
31
    ///
32
    /// @return the resolved value for the expression
33
    ///
34
    /// @throws OfficeStamperException if no resolver is found for the object
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
    /// Resolves the expression in the given document with the provided object.
48
    ///
49
    /// Replace the previous [#resolve(WordprocessingMLPackage, String, Object)]
50
    ///
51
    /// @param docxPart   the [DocxPart] document in
52
    ///                   which to resolve the expression
53
    /// @param expression the expression value to be replaced
54
    /// @param object     the object to be used for resolving the expression
55
    ///
56
    /// @return the resolved value for the expression
57
    ///
58
    /// @throws OfficeStamperException if no resolver is found for the object
59
    default R resolve(DocxPart docxPart, String expression, Object object) {
60 1 1. resolve : replaced return value with null for pro/verron/officestamper/api/ObjectResolver::resolve → NO_COVERAGE
        return resolve(docxPart.document(), expression, object);
61
    }
62
63
    /// Resolves the expression in the given WordprocessingMLPackage document with the provided object.
64
    /// @deprecated This method is deprecated and should not be called directly. It exists only for legacy
65
    /// implementations that might still override it.
66
    ///
67
    /// @param document   the WordprocessingMLPackage document in which to resolve the expression
68
    /// @param expression the expression value to be replaced
69
    /// @param object     the object to be used for resolving the expression
70
    /// @return the resolved value for the expression
71
    /// @throws OfficeStamperException if this method is invoked directly
72
    @Deprecated(since = "2.3", forRemoval = true)
73
    default R resolve(WordprocessingMLPackage document, String expression, Object object) {
74
        throw new OfficeStamperException("Should not be called, only legacy implementation might still override this");
75
    }
76
77
    /// Checks if the given object can be resolved.
78
    ///
79
    /// @param object the object to be resolved
80
    ///
81
    /// @return true if the object can be resolved, false otherwise
82
    boolean canResolve(@Nullable Object object);
83
}

Mutations

44

1.1
Location : resolve
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#12]
replaced return value with null for pro/verron/officestamper/api/ObjectResolver::resolve → KILLED

60

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.21.0