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