| 1 | package pro.verron.officestamper.core; | |
| 2 | ||
| 3 | ||
| 4 | import org.springframework.expression.EvaluationContext; | |
| 5 | import org.springframework.expression.ExpressionParser; | |
| 6 | import org.springframework.expression.spel.standard.SpelExpressionParser; | |
| 7 | import pro.verron.officestamper.api.*; | |
| 8 | import pro.verron.officestamper.api.CustomFunction.NeedsBiFunctionImpl; | |
| 9 | import pro.verron.officestamper.api.CustomFunction.NeedsFunctionImpl; | |
| 10 | import pro.verron.officestamper.api.CustomFunction.NeedsTriFunctionImpl; | |
| 11 | import pro.verron.officestamper.core.functions.BiFunctionBuilder; | |
| 12 | import pro.verron.officestamper.core.functions.FunctionBuilder; | |
| 13 | import pro.verron.officestamper.core.functions.TriFunctionBuilder; | |
| 14 | ||
| 15 | import java.util.ArrayList; | |
| 16 | import java.util.HashMap; | |
| 17 | import java.util.List; | |
| 18 | import java.util.Map; | |
| 19 | import java.util.function.Supplier; | |
| 20 | ||
| 21 | /// The [DocxStamperConfiguration] class represents the configuration for the [DocxStamper] class. | |
| 22 | /// | |
| 23 | /// It provides methods to customize the behavior of the stamper. | |
| 24 | /// | |
| 25 | /// @author Joseph Verron | |
| 26 | /// @author Tom Hombergs | |
| 27 | /// @version ${version} | |
| 28 | /// @since 1.0.3 | |
| 29 | public class DocxStamperConfiguration | |
| 30 | implements OfficeStamperConfiguration { | |
| 31 | private final Map<Class<?>, CommentProcessorFactory> commentProcessors; | |
| 32 | private final List<ObjectResolver> resolvers; | |
| 33 | private final Map<Class<?>, Object> expressionFunctions; | |
| 34 | private final List<PreProcessor> preprocessors; | |
| 35 | private final List<PostProcessor> postprocessors; | |
| 36 | private final List<CustomFunction> functions; | |
| 37 | private EvaluationContextFactory evaluationContextFactory; | |
| 38 | private ExpressionParser expressionParser; | |
| 39 | private ExceptionResolver exceptionResolver; | |
| 40 | ||
| 41 | /// Constructs a new instance of the [DocxStamperConfiguration] class and initializes its default configuration | |
| 42 | /// settings. | |
| 43 | /// | |
| 44 | /// This constructor sets up internal structures and default behaviors for managing document stamping | |
| 45 | /// configurations, including: | |
| 46 | /// - Initializing collections for processors, resolvers, and functions. | |
| 47 | /// - Setting default values for expression handling and evaluation. | |
| 48 | /// - Creating and configuring a default `SpelParserConfiguration`. | |
| 49 | /// - Establishing resolvers and exception handling strategies. | |
| 50 | /// | |
| 51 | /// @param evaluationContextFactory the factory used to create [EvaluationContext] instances. | |
| 52 | /// @param exceptionResolver the exception resolver to use for handling exceptions during stamping. | |
| 53 | public DocxStamperConfiguration( | |
| 54 | EvaluationContextFactory evaluationContextFactory, | |
| 55 | ExceptionResolver exceptionResolver | |
| 56 | ) { | |
| 57 | this.commentProcessors = new HashMap<>(); | |
| 58 | this.resolvers = new ArrayList<>(); | |
| 59 | this.expressionFunctions = new HashMap<>(); | |
| 60 | this.preprocessors = new ArrayList<>(); | |
| 61 | this.postprocessors = new ArrayList<>(); | |
| 62 | this.functions = new ArrayList<>(); | |
| 63 | this.evaluationContextFactory = evaluationContextFactory; | |
| 64 | this.expressionParser = new SpelExpressionParser(); | |
| 65 | this.exceptionResolver = exceptionResolver; | |
| 66 | } | |
| 67 | ||
| 68 | /// Exposes all methods of a given interface to the expression language. | |
| 69 | /// | |
| 70 | /// @param interfaceClass the interface holding methods to expose in the expression language. | |
| 71 | /// @param implementation the implementation to call to evaluate invocations of those methods, it must | |
| 72 | /// implement the mentioned interface. | |
| 73 | /// | |
| 74 | /// @return a [DocxStamperConfiguration] object | |
| 75 | @Override | |
| 76 | public DocxStamperConfiguration exposeInterfaceToExpressionLanguage( | |
| 77 | Class<?> interfaceClass, | |
| 78 | Object implementation | |
| 79 | ) { | |
| 80 | this.expressionFunctions.put(interfaceClass, implementation); | |
| 81 |
1
1. exposeInterfaceToExpressionLanguage : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::exposeInterfaceToExpressionLanguage → KILLED |
return this; |
| 82 | } | |
| 83 | ||
| 84 | /// Registers the specified [CommentProcessor] as an implementation of the specified interface. | |
| 85 | /// | |
| 86 | /// @param interfaceClass the interface, implemented by the commentProcessor. | |
| 87 | /// @param commentProcessorFactory the commentProcessor factory generating instances of the specified | |
| 88 | /// interface. | |
| 89 | /// | |
| 90 | /// @return a [DocxStamperConfiguration] object | |
| 91 | @Override | |
| 92 | public DocxStamperConfiguration addCommentProcessor( | |
| 93 | Class<?> interfaceClass, | |
| 94 | CommentProcessorFactory commentProcessorFactory | |
| 95 | ) { | |
| 96 | this.commentProcessors.put(interfaceClass, commentProcessorFactory); | |
| 97 |
1
1. addCommentProcessor : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::addCommentProcessor → KILLED |
return this; |
| 98 | } | |
| 99 | ||
| 100 | /// Adds a preprocessor to the configuration. | |
| 101 | /// | |
| 102 | /// @param preprocessor the preprocessor to add. | |
| 103 | @Override | |
| 104 | public void addPreprocessor(PreProcessor preprocessor) { | |
| 105 | preprocessors.add(preprocessor); | |
| 106 | } | |
| 107 | ||
| 108 | /// Retrieves the configured [EvaluationContextFactory] instance. | |
| 109 | /// | |
| 110 | /// @return an instance of [EvaluationContextFactory] used for creating evaluation contexts | |
| 111 | @Override | |
| 112 | public EvaluationContextFactory getEvaluationContextFactory() { | |
| 113 |
1
1. getEvaluationContextFactory : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::getEvaluationContextFactory → KILLED |
return evaluationContextFactory; |
| 114 | } | |
| 115 | ||
| 116 | /// Sets the [EvaluationContextFactory] which creates Spring [EvaluationContext] instances used for evaluating | |
| 117 | /// expressions in comments and text. | |
| 118 | /// | |
| 119 | /// @param evaluationContextFactory the factory to use. | |
| 120 | /// | |
| 121 | /// @return the configuration object for chaining. | |
| 122 | @Override | |
| 123 | public DocxStamperConfiguration setEvaluationContextFactory(EvaluationContextFactory evaluationContextFactory) { | |
| 124 | this.evaluationContextFactory = evaluationContextFactory; | |
| 125 |
1
1. setEvaluationContextFactory : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::setEvaluationContextFactory → KILLED |
return this; |
| 126 | } | |
| 127 | ||
| 128 | /// Retrieves the mapping of expression function classes to their corresponding function instances. | |
| 129 | /// | |
| 130 | /// @return a map where the keys are classes representing the function types, and the values are the function | |
| 131 | /// instances. | |
| 132 | @Override | |
| 133 | public Map<Class<?>, Object> getExpressionFunctions() { | |
| 134 |
1
1. getExpressionFunctions : replaced return value with Collections.emptyMap for pro/verron/officestamper/core/DocxStamperConfiguration::getExpressionFunctions → TIMED_OUT |
return expressionFunctions; |
| 135 | } | |
| 136 | ||
| 137 | /// Retrieves the map of comment processors associated with specific classes. | |
| 138 | /// | |
| 139 | /// @return a map where the key is the class associated with a specific type of placeholder, and the value is a | |
| 140 | /// function that creates a [CommentProcessor] for that placeholder. | |
| 141 | @Override | |
| 142 | public Map<Class<?>, CommentProcessorFactory> getCommentProcessors() { | |
| 143 |
1
1. getCommentProcessors : replaced return value with Collections.emptyMap for pro/verron/officestamper/core/DocxStamperConfiguration::getCommentProcessors → TIMED_OUT |
return commentProcessors; |
| 144 | } | |
| 145 | ||
| 146 | /// Retrieves the list of preprocessors. | |
| 147 | /// | |
| 148 | /// @return a list of [PreProcessor] objects. | |
| 149 | @Override | |
| 150 | public List<PreProcessor> getPreprocessors() { | |
| 151 |
1
1. getPreprocessors : replaced return value with Collections.emptyList for pro/verron/officestamper/core/DocxStamperConfiguration::getPreprocessors → KILLED |
return preprocessors; |
| 152 | } | |
| 153 | ||
| 154 | /// Retrieves the list of object resolvers. | |
| 155 | /// | |
| 156 | /// @return a list of [ObjectResolver] instances. | |
| 157 | @Override | |
| 158 | public List<ObjectResolver> getResolvers() { | |
| 159 |
1
1. getResolvers : replaced return value with Collections.emptyList for pro/verron/officestamper/core/DocxStamperConfiguration::getResolvers → TIMED_OUT |
return resolvers; |
| 160 | } | |
| 161 | ||
| 162 | /// Sets resolvers for resolving objects in the [DocxStamperConfiguration]. | |
| 163 | /// | |
| 164 | /// This method is the evolution of the method [#addResolver(ObjectResolver)], and the order in which the resolvers | |
| 165 | /// are ordered is determinant; the first resolvers in the list will be tried first. | |
| 166 | /// | |
| 167 | /// If a fallback resolver is desired, it should be placed last in the list. | |
| 168 | /// | |
| 169 | /// @param resolvers The list of [ObjectResolver] to be set. | |
| 170 | /// | |
| 171 | /// @return the configuration object for chaining. | |
| 172 | @Override | |
| 173 | public DocxStamperConfiguration setResolvers(List<ObjectResolver> resolvers) { | |
| 174 |
1
1. setResolvers : removed call to java/util/List::clear → TIMED_OUT |
this.resolvers.clear(); |
| 175 | this.resolvers.addAll(resolvers); | |
| 176 |
1
1. setResolvers : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::setResolvers → TIMED_OUT |
return this; |
| 177 | } | |
| 178 | ||
| 179 | /// Adds a resolver to the list of resolvers in the [DocxStamperConfiguration] object. | |
| 180 | /// | |
| 181 | /// Resolvers are used to resolve objects during the stamping process. | |
| 182 | /// | |
| 183 | /// @param resolver The resolver to be added. | |
| 184 | /// | |
| 185 | /// @return The modified [DocxStamperConfiguration] object, with the resolver added to the beginning of the resolver | |
| 186 | /// list. | |
| 187 | @Override | |
| 188 | public DocxStamperConfiguration addResolver(ObjectResolver resolver) { | |
| 189 |
1
1. addResolver : removed call to java/util/List::addFirst → TIMED_OUT |
resolvers.addFirst(resolver); |
| 190 |
1
1. addResolver : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::addResolver → KILLED |
return this; |
| 191 | } | |
| 192 | ||
| 193 | /// Retrieves the exception resolver. | |
| 194 | /// | |
| 195 | /// @return the current instance of [ExceptionResolver]. | |
| 196 | @Override | |
| 197 | public ExceptionResolver getExceptionResolver() { | |
| 198 |
1
1. getExceptionResolver : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::getExceptionResolver → KILLED |
return exceptionResolver; |
| 199 | } | |
| 200 | ||
| 201 | /// Configures the exception resolver for the [DocxStamperConfiguration]. | |
| 202 | /// | |
| 203 | /// @param exceptionResolver the [ExceptionResolver] to handle exceptions during processing | |
| 204 | /// | |
| 205 | /// @return the current instance of [DocxStamperConfiguration] | |
| 206 | @Override | |
| 207 | public DocxStamperConfiguration setExceptionResolver(ExceptionResolver exceptionResolver) { | |
| 208 | this.exceptionResolver = exceptionResolver; | |
| 209 |
1
1. setExceptionResolver : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::setExceptionResolver → KILLED |
return this; |
| 210 | } | |
| 211 | ||
| 212 | /// Retrieves a list of custom functions. | |
| 213 | /// | |
| 214 | /// @return a List containing [CustomFunction] objects. | |
| 215 | @Override | |
| 216 | public List<CustomFunction> customFunctions() { | |
| 217 |
1
1. customFunctions : replaced return value with Collections.emptyList for pro/verron/officestamper/core/DocxStamperConfiguration::customFunctions → TIMED_OUT |
return functions; |
| 218 | } | |
| 219 | ||
| 220 | /// Adds a custom function to the system, allowing integration of user-defined functionality. | |
| 221 | /// | |
| 222 | /// @param name The name of the custom function being added. This is used as the identifier for the function | |
| 223 | /// and must be unique across all defined functions. | |
| 224 | /// @param implementation A [Supplier] functional interface that provides the implementation of the custom | |
| 225 | /// function. When the function is called, the supplier's get method will be executed to return the result | |
| 226 | /// of the function. | |
| 227 | @Override | |
| 228 | public void addCustomFunction(String name, Supplier<?> implementation) { | |
| 229 |
2
1. lambda$addCustomFunction$0 : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::lambda$addCustomFunction$0 → KILLED 2. addCustomFunction : removed call to pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → KILLED |
this.addCustomFunction(new CustomFunction(name, List.of(), args -> implementation.get())); |
| 230 | } | |
| 231 | ||
| 232 | /// Adds a custom function to the list of functions. | |
| 233 | /// | |
| 234 | /// @param function the [CustomFunction] object to be added | |
| 235 | public void addCustomFunction(CustomFunction function) { | |
| 236 | this.functions.add(function); | |
| 237 | } | |
| 238 | ||
| 239 | /// Adds a custom function to the context with the specified name and type. | |
| 240 | /// | |
| 241 | /// @param name the name of the custom function | |
| 242 | /// @param class0 the class type of the custom function | |
| 243 | /// @param <T> the type of the input parameter | |
| 244 | /// | |
| 245 | /// @return an instance of [NeedsFunctionImpl] configured with the custom function | |
| 246 | @Override | |
| 247 | public <T> NeedsFunctionImpl<T> addCustomFunction(String name, Class<T> class0) { | |
| 248 |
1
1. addCustomFunction : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → KILLED |
return new FunctionBuilder<>(this, name, class0); |
| 249 | } | |
| 250 | ||
| 251 | /// Adds a custom function with the specified name and input types. | |
| 252 | /// | |
| 253 | /// @param name the name of the custom function to be added | |
| 254 | /// @param class0 the class type of the first input parameter of the custom function. | |
| 255 | /// @param class1 the class type of the second input parameter of the custom function. | |
| 256 | /// @param <T> the type of the first input parameter | |
| 257 | /// @param <U> the type of the second input parameter | |
| 258 | /// | |
| 259 | /// @return an instance of [NeedsBiFunctionImpl] for further configuration or usage of the custom function. | |
| 260 | @Override | |
| 261 | public <T, U> NeedsBiFunctionImpl<T, U> addCustomFunction(String name, Class<T> class0, Class<U> class1) { | |
| 262 |
1
1. addCustomFunction : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → KILLED |
return new BiFunctionBuilder<>(this, name, class0, class1); |
| 263 | } | |
| 264 | ||
| 265 | /// Adds a custom function to the current context by defining its name, and the classes associated with its argument | |
| 266 | /// types. | |
| 267 | /// | |
| 268 | /// @param name the name to assign to the custom function | |
| 269 | /// @param class0 the class of the first argument type | |
| 270 | /// @param class1 the class of the second argument type | |
| 271 | /// @param class2 the class of the third argument type | |
| 272 | /// @param <T> the type of the first argument | |
| 273 | /// @param <U> the type of the second argument | |
| 274 | /// @param <V> the type of the third argument | |
| 275 | /// | |
| 276 | /// @return an instance of [NeedsTriFunctionImpl] indicating the custom function implementation and usage context. | |
| 277 | @Override | |
| 278 | public <T, U, V> NeedsTriFunctionImpl<T, U, V> addCustomFunction( | |
| 279 | String name, | |
| 280 | Class<T> class0, | |
| 281 | Class<U> class1, | |
| 282 | Class<V> class2 | |
| 283 | ) { | |
| 284 |
1
1. addCustomFunction : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → KILLED |
return new TriFunctionBuilder<>(this, name, class0, class1, class2); |
| 285 | } | |
| 286 | ||
| 287 | /// Retrieves the list of postprocessors. | |
| 288 | /// | |
| 289 | /// @return a List of [PostProcessor] objects. | |
| 290 | @Override | |
| 291 | public List<PostProcessor> getPostprocessors() { | |
| 292 |
1
1. getPostprocessors : replaced return value with Collections.emptyList for pro/verron/officestamper/core/DocxStamperConfiguration::getPostprocessors → TIMED_OUT |
return postprocessors; |
| 293 | } | |
| 294 | ||
| 295 | /// Adds a given postprocessor to the list of postprocessors. | |
| 296 | /// | |
| 297 | /// @param postprocessor the [PostProcessor] instance to be added | |
| 298 | @Override | |
| 299 | public void addPostprocessor(PostProcessor postprocessor) { | |
| 300 | postprocessors.add(postprocessor); | |
| 301 | } | |
| 302 | ||
| 303 | @Override | |
| 304 | public ExpressionParser getExpressionParser() { | |
| 305 |
1
1. getExpressionParser : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::getExpressionParser → KILLED |
return expressionParser; |
| 306 | } | |
| 307 | ||
| 308 | /// Sets the expression parser used for expression evaluation. | |
| 309 | /// | |
| 310 | /// Note that the provided parser will be used for all expressions in the document, including expressions in | |
| 311 | /// comments. If you use SpEL, construct a `SpelExpressionParser` (optionally with a `SpelParserConfiguration`) and | |
| 312 | /// pass it here. | |
| 313 | /// | |
| 314 | /// @param expressionParser the parser to use. | |
| 315 | /// | |
| 316 | /// @return the configuration object for chaining. | |
| 317 | @Override | |
| 318 | public DocxStamperConfiguration setExpressionParser(ExpressionParser expressionParser) { | |
| 319 | this.expressionParser = expressionParser; | |
| 320 |
1
1. setExpressionParser : replaced return value with null for pro/verron/officestamper/core/DocxStamperConfiguration::setExpressionParser → KILLED |
return this; |
| 321 | } | |
| 322 | ||
| 323 | /// Resets all processors in the configuration. | |
| 324 | public void resetCommentProcessors() { | |
| 325 |
1
1. resetCommentProcessors : removed call to java/util/Map::clear → NO_COVERAGE |
this.commentProcessors.clear(); |
| 326 | } | |
| 327 | ||
| 328 | /// Resets all resolvers in the configuration. | |
| 329 | public void resetResolvers() { | |
| 330 |
1
1. resetResolvers : removed call to java/util/List::clear → NO_COVERAGE |
this.resolvers.clear(); |
| 331 | } | |
| 332 | } | |
Mutations | ||
| 81 |
1.1 |
|
| 97 |
1.1 |
|
| 113 |
1.1 |
|
| 125 |
1.1 |
|
| 134 |
1.1 |
|
| 143 |
1.1 |
|
| 151 |
1.1 |
|
| 159 |
1.1 |
|
| 174 |
1.1 |
|
| 176 |
1.1 |
|
| 189 |
1.1 |
|
| 190 |
1.1 |
|
| 198 |
1.1 |
|
| 209 |
1.1 |
|
| 217 |
1.1 |
|
| 229 |
1.1 2.2 |
|
| 248 |
1.1 |
|
| 262 |
1.1 |
|
| 284 |
1.1 |
|
| 292 |
1.1 |
|
| 305 |
1.1 |
|
| 320 |
1.1 |
|
| 325 |
1.1 |
|
| 330 |
1.1 |