OfficeStamperConfigurations.java

1
package pro.verron.officestamper.preset;
2
3
import pro.verron.officestamper.api.ObjectResolver;
4
import pro.verron.officestamper.api.OfficeStamperConfiguration;
5
import pro.verron.officestamper.api.OfficeStamperException;
6
import pro.verron.officestamper.api.SecurityMode;
7
import pro.verron.officestamper.core.DocxStamperConfiguration;
8
import pro.verron.officestamper.preset.CommentProcessorFactory.*;
9
import pro.verron.officestamper.preset.processors.displayif.DisplayIfProcessor;
10
import pro.verron.officestamper.preset.processors.repeat.RepeatDocPartProcessor;
11
import pro.verron.officestamper.preset.processors.repeat.RepeatParagraphProcessor;
12
import pro.verron.officestamper.preset.processors.repeat.RepeatProcessor;
13
import pro.verron.officestamper.preset.processors.repeatrow.RepeatRowProcessor;
14
import pro.verron.officestamper.preset.processors.replacewith.ReplaceWithProcessor;
15
import pro.verron.officestamper.preset.processors.table.TableResolver;
16
17
import java.time.temporal.TemporalAccessor;
18
import java.util.List;
19
20
import static java.time.format.DateTimeFormatter.*;
21
import static java.time.format.FormatStyle.valueOf;
22
import static java.util.Locale.forLanguageTag;
23
24
25
/// Utility class providing factory methods for various pre-configured instances of [OfficeStamperConfiguration].
26
///
27
/// These configurations range from minimal to fully-featured, catering to different use cases for processing Office
28
/// documents.
29
public class OfficeStamperConfigurations {
30
31
    private OfficeStamperConfigurations() {
32
        throw new OfficeStamperException("Utility class should not be instantiated");
33
    }
34
35
    /// Creates a full [OfficeStamperConfiguration] with standard configurations, supplemented with additional pre- and
36
    /// post-processors for enhanced document handling.
37
    ///
38
    /// This configuration includes preprocessors to:
39
    /// - Remove language proof markings.
40
    /// - Remove language information.
41
    /// - Merge similar text runs.
42
    ///
43
    /// It also includes postprocessors to:
44
    /// - Remove orphaned footnotes.
45
    /// - Remove orphaned endnotes.
46
    ///
47
    /// @return a fully configured [OfficeStamperConfiguration] instance with the additional processors applied.
48
    public static OfficeStamperConfiguration full() {
49
        var configuration = standard();
50
51 1 1. full : removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → SURVIVED
        configuration.addPreprocessor(Preprocessors.removeLanguageProof());
52 1 1. full : removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → SURVIVED
        configuration.addPreprocessor(Preprocessors.removeLanguageInfo());
53 1 1. full : removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → SURVIVED
        configuration.addPreprocessor(Preprocessors.mergeSimilarRuns());
54
55 1 1. full : removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPostprocessor → KILLED
        configuration.addPostprocessor(Postprocessors.removeOrphanedFootnotes());
56 1 1. full : removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPostprocessor → KILLED
        configuration.addPostprocessor(Postprocessors.removeOrphanedEndnotes());
57
58 1 1. full : replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::full → KILLED
        return configuration;
59
    }
60
61
    /// Creates a standard [OfficeStamperConfiguration] instance with predefined settings.
62
    ///
63
    /// The configuration is extended with custom comment processing, resolvers, and additional preprocessors.
64
    ///
65
    /// It sets up a fallback resolver with the default value of a newline character ("`\n`") to handle placeholder
66
    /// resolution.
67
    ///
68
    /// @return a standard [OfficeStamperConfiguration] instance with pre-configured resolvers and processors
69
    public static OfficeStamperConfiguration standard() {
70
        var fallback = Resolvers.fallback("\n");
71 1 1. standard : replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::standard → KILLED
        return standard(fallback);
72
    }
73
74
    /// Creates a standard [OfficeStamperConfiguration] instance with a set of predefined comment processors, resolvers,
75
    /// and preprocessors.
76
    ///
77
    /// The configuration is extended with custom functions for date and time formatting, and permits the provision of a
78
    /// custom fallback resolver.
79
    ///
80
    /// @param fallback an [ObjectResolver] to serve as the additional fallback resolver for this
81
    ///         configuration.
82
    ///
83
    /// @return a configured [OfficeStamperConfiguration] object implementing standard processing and formatting
84
    ///         behaviors
85
    public static OfficeStamperConfiguration standard(ObjectResolver fallback) {
86
        var configuration = minimal();
87
88
        configuration.addCommentProcessor(IRepeatRowProcessor.class, RepeatRowProcessor::new);
89
        configuration.addCommentProcessor(IParagraphRepeatProcessor.class, RepeatParagraphProcessor::new);
90
        configuration.addCommentProcessor(IRepeatDocPartProcessor.class, RepeatDocPartProcessor::new);
91
        configuration.addCommentProcessor(IRepeatProcessor.class, RepeatProcessor::new);
92
        configuration.addCommentProcessor(ITableResolver.class, TableResolver::new);
93
        configuration.addCommentProcessor(IDisplayIfProcessor.class, DisplayIfProcessor::new);
94
        configuration.addCommentProcessor(IReplaceWithProcessor.class, ReplaceWithProcessor::new);
95
96
        configuration.setResolvers(List.of(Resolvers.image(),
97
                Resolvers.legacyDate(),
98
                Resolvers.isoDate(),
99
                Resolvers.isoTime(),
100
                Resolvers.isoDateTime(),
101
                Resolvers.nullToEmpty(),
102
                fallback));
103
104 1 1. standard : removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → SURVIVED
        configuration.addPreprocessor(Preprocessors.removeMalformedComments());
105
106
        var fdate = "fdate";
107
        var ftime = "ftime";
108
        var fdatetime = "fdatetime";
109
        var fpattern = "fpattern";
110
        var flocaldate = "flocaldate";
111
        var flocaltime = "flocaltime";
112
        var flocaldatetime = "flocaldatetime";
113
        var finstant = "finstant";
114
        var fordinaldate = "fordinaldate";
115
        var f1123datetime = "f1123datetime";
116
        var fbasicdate = "fbasicdate";
117
        var fweekdate = "fweekdate";
118
        var foffsetdatetime = "foffsetdatetime";
119
        var fzoneddatetime = "fzoneddatetime";
120
        var foffsetdate = "foffsetdate";
121
        var foffsettime = "foffsettime";
122
        configuration.addCustomFunction(fdate, TemporalAccessor.class)
123
                     .withImplementation(ISO_DATE::format)
124
                     .addCustomFunction(ftime, TemporalAccessor.class)
125
                     .withImplementation(ISO_TIME::format)
126
                     .addCustomFunction(fdatetime, TemporalAccessor.class)
127
                     .withImplementation(ISO_DATE_TIME::format)
128
                     .addCustomFunction(finstant, TemporalAccessor.class)
129
                     .withImplementation(ISO_INSTANT::format)
130
                     .addCustomFunction(fordinaldate, TemporalAccessor.class)
131
                     .withImplementation(ISO_ORDINAL_DATE::format)
132
                     .addCustomFunction(f1123datetime, TemporalAccessor.class)
133
                     .withImplementation(RFC_1123_DATE_TIME::format)
134
                     .addCustomFunction(fbasicdate, TemporalAccessor.class)
135
                     .withImplementation(BASIC_ISO_DATE::format)
136
                     .addCustomFunction(fweekdate, TemporalAccessor.class)
137
                     .withImplementation(ISO_WEEK_DATE::format)
138
                     .addCustomFunction(flocaldatetime, TemporalAccessor.class)
139
                     .withImplementation(ISO_LOCAL_DATE_TIME::format)
140
                     .addCustomFunction(flocaldatetime, TemporalAccessor.class, String.class)
141
                     .withImplementation(OfficeStamperConfigurations::flocaldatetime)
142
                     .addCustomFunction(flocaldatetime, TemporalAccessor.class, String.class, String.class)
143
                     .withImplementation(OfficeStamperConfigurations::flocaldatetime)
144
                     .addCustomFunction(foffsetdatetime, TemporalAccessor.class)
145
                     .withImplementation(ISO_OFFSET_DATE_TIME::format)
146
                     .addCustomFunction(fzoneddatetime, TemporalAccessor.class)
147
                     .withImplementation(ISO_ZONED_DATE_TIME::format)
148
                     .addCustomFunction(foffsetdate, TemporalAccessor.class)
149
                     .withImplementation(ISO_OFFSET_DATE::format)
150
                     .addCustomFunction(foffsettime, TemporalAccessor.class)
151
                     .withImplementation(ISO_OFFSET_TIME::format)
152
                     .addCustomFunction(flocaldate, TemporalAccessor.class)
153
                     .withImplementation(ISO_LOCAL_DATE::format)
154
                     .addCustomFunction(flocaldate, TemporalAccessor.class, String.class)
155
                     .withImplementation(OfficeStamperConfigurations::flocaldate)
156
                     .addCustomFunction(flocaltime, TemporalAccessor.class)
157
                     .withImplementation(ISO_LOCAL_TIME::format)
158
                     .addCustomFunction(flocaltime, TemporalAccessor.class, String.class)
159
                     .withImplementation(OfficeStamperConfigurations::flocaltime)
160
                     .addCustomFunction(fpattern, TemporalAccessor.class, String.class)
161
                     .withImplementation(OfficeStamperConfigurations::fpattern)
162
                     .addCustomFunction(fpattern, TemporalAccessor.class, String.class, String.class)
163
                     .withImplementation(OfficeStamperConfigurations::fpattern);
164
165 1 1. standard : replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::standard → KILLED
        return configuration;
166
    }
167
168
    /// Creates a minimal [OfficeStamperConfiguration] instance with essential settings to provide basic placeholder
169
    /// processing and fallback resolvers.
170
    ///
171
    /// This configuration includes:
172
    /// - A fallback resolver with a default value of a newline character ("`\n`").
173
    /// - A placeholder preprocessor that prepares placeholders matching a specific pattern.
174
    ///
175
    /// @return a minimally configured [OfficeStamperConfiguration] instance
176
    public static OfficeStamperConfiguration minimal() {
177
        var configuration = raw();
178
        configuration.addResolver(Resolvers.fallback("\n"));
179 1 1. minimal : removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → KILLED
        configuration.addPreprocessor(Preprocessors.preparePlaceholders("(\\$\\{([^{]+?)})", "placeholder"));
180 1 1. minimal : removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → KILLED
        configuration.addPreprocessor(Preprocessors.preparePlaceholders("(\\#\\{([^{]+?)})", "inlineProcessor"));
181 1 1. minimal : removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → KILLED
        configuration.addPreprocessor(Preprocessors.prepareCommentProcessor());
182 1 1. minimal : removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPostprocessor → KILLED
        configuration.addPostprocessor(Postprocessors.removeTags("officestamper"));
183 1 1. minimal : removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPostprocessor → KILLED
        configuration.addPostprocessor(Postprocessors.removeComments());
184 1 1. minimal : replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::minimal → KILLED
        return configuration;
185
    }
186
187
    private static Object flocaldatetime(TemporalAccessor date, String style) {
188 1 1. flocaldatetime : replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::flocaldatetime → NO_COVERAGE
        return ofLocalizedDateTime(valueOf(style)).format(date);
189
    }
190
191
    private static Object flocaldatetime(TemporalAccessor date, String dateStyle, String timeStyle) {
192 1 1. flocaldatetime : replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::flocaldatetime → NO_COVERAGE
        return ofLocalizedDateTime(valueOf(dateStyle), valueOf(timeStyle)).format(date);
193
    }
194
195
    private static Object flocaldate(TemporalAccessor date, String style) {
196 1 1. flocaldate : replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::flocaldate → NO_COVERAGE
        return ofLocalizedDate(valueOf(style)).format(date);
197
    }
198
199
    private static Object flocaltime(TemporalAccessor date, String style) {
200 1 1. flocaltime : replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::flocaltime → NO_COVERAGE
        return ofLocalizedTime(valueOf(style)).format(date);
201
    }
202
203
    private static Object fpattern(TemporalAccessor date, String pattern) {
204 1 1. fpattern : replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::fpattern → NO_COVERAGE
        return ofPattern(pattern).format(date);
205
    }
206
207
    private static Object fpattern(TemporalAccessor date, String pattern, String locale) {
208 1 1. fpattern : replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::fpattern → NO_COVERAGE
        return ofPattern(pattern, forLanguageTag(locale)).format(date);
209
    }
210
211
    /// Creates a [OfficeStamperConfiguration] instance without any configuration or resolvers, processors,
212
    /// preprocessors or postprocessors applied.
213
    ///
214
    /// @return a basic [OfficeStamperConfiguration] instance with no extra configurations
215
    public static OfficeStamperConfiguration raw() {
216
        var defaultFactory = EvaluationContextFactories.defaultFactory();
217
        var defaultExceptionResolver = ExceptionResolvers.throwing();
218
        var configuration = new DocxStamperConfiguration(defaultFactory, defaultExceptionResolver);
219
        // Honor system property: officestamper.spel.mode = restricted|permissive (default: restricted)
220
        var spelModeProp = System.getProperty("officestamper.spel.mode");
221 2 1. raw : negated conditional → NO_COVERAGE
2. raw : negated conditional → KILLED
        var spelPermissive = spelModeProp != null && spelModeProp.equalsIgnoreCase("permissive");
222 1 1. raw : negated conditional → RUN_ERROR
        configuration.setSpelSecurityMode(spelPermissive ? SecurityMode.PERMISSIVE : SecurityMode.RESTRICTED);
223 1 1. raw : negated conditional → RUN_ERROR
        if (spelPermissive) {
224
            configuration.setEvaluationContextFactory(EvaluationContextFactories.noopFactory());
225
        }
226
        // Honor system property: officestamper.svg.mode = restricted|permissive (default: restricted)
227
        var svgModeProp = System.getProperty("officestamper.svg.mode");
228 2 1. raw : negated conditional → NO_COVERAGE
2. raw : negated conditional → KILLED
        configuration.setSvgSecurityMode(svgModeProp != null && svgModeProp.equalsIgnoreCase("permissive")
229
                ? SecurityMode.PERMISSIVE
230
                : SecurityMode.RESTRICTED);
231 1 1. raw : replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::raw → KILLED
        return configuration;
232
    }
233
}

Mutations

51

1.1
Location : full
Killed by : none
removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → SURVIVED
Covering tests

52

1.1
Location : full
Killed by : none
removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → SURVIVED
Covering tests

53

1.1
Location : full
Killed by : none
removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → SURVIVED
Covering tests

55

1.1
Location : full
Killed by : pro.verron.officestamper.test.ProcessorDisplayIfTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorDisplayIfTest]/[test-template:conditionalDisplayOfFootnotes(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPostprocessor → KILLED

56

1.1
Location : full
Killed by : pro.verron.officestamper.test.ProcessorDisplayIfTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorDisplayIfTest]/[test-template:conditionalDisplayOfEndnotes(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#1]
removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPostprocessor → KILLED

58

1.1
Location : full
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#1]
replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::full → KILLED

71

1.1
Location : standard
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::standard → KILLED

104

1.1
Location : standard
Killed by : none
removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → SURVIVED
Covering tests

165

1.1
Location : standard
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::standard → KILLED

179

1.1
Location : minimal
Killed by : pro.verron.officestamper.test.NullPointerResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.NullPointerResolutionTest]/[test-template:nullPointerResolutionTest_testThrowingCase(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → KILLED

180

1.1
Location : minimal
Killed by : pro.verron.officestamper.test.SpelInjectionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.SpelInjectionTest]/[test-template:spelInjectionTest(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → KILLED

181

1.1
Location : minimal
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPreprocessor → KILLED

182

1.1
Location : minimal
Killed by : pro.verron.officestamper.test.CustomFunctionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.CustomFunctionTests]/[test-template:trifunctions(pro.verron.officestamper.test.utils.ContextFactory, java.lang.String, java.lang.String)]/[test-template-invocation:#12]
removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPostprocessor → KILLED

183

1.1
Location : minimal
Killed by : pro.verron.officestamper.test.ProcessorReplaceWithTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorReplaceWithTest]/[method:notWorking1()]
removed call to pro/verron/officestamper/api/OfficeStamperConfiguration::addPostprocessor → KILLED

184

1.1
Location : minimal
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::minimal → KILLED

188

1.1
Location : flocaldatetime
Killed by : none
replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::flocaldatetime → NO_COVERAGE

192

1.1
Location : flocaldatetime
Killed by : none
replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::flocaldatetime → NO_COVERAGE

196

1.1
Location : flocaldate
Killed by : none
replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::flocaldate → NO_COVERAGE

200

1.1
Location : flocaltime
Killed by : none
replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::flocaltime → NO_COVERAGE

204

1.1
Location : fpattern
Killed by : none
replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::fpattern → NO_COVERAGE

208

1.1
Location : fpattern
Killed by : none
replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::fpattern → NO_COVERAGE

221

1.1
Location : raw
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

2.2
Location : raw
Killed by : none
negated conditional → NO_COVERAGE

222

1.1
Location : raw
Killed by : none
negated conditional → RUN_ERROR

223

1.1
Location : raw
Killed by : none
negated conditional → RUN_ERROR

228

1.1
Location : raw
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

2.2
Location : raw
Killed by : none
negated conditional → NO_COVERAGE

231

1.1
Location : raw
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/preset/OfficeStamperConfigurations::raw → KILLED

Active mutators

Tests examined


Report generated by PIT 1.23.1 support