Class DocxStamperConfiguration
- All Implemented Interfaces:
OfficeStamperConfiguration
The DocxStamperConfiguration class represents the configuration for the DocxStamper class.
It provides methods to customize the behavior of the stamper.
- Since:
- 1.0.3
- Version:
- ${version}
- Author:
- Joseph Verron, Tom Hombergs
-
Constructor Summary
ConstructorsConstructorDescriptionDocxStamperConfiguration(EvaluationContextFactory evaluationContextFactory, ExceptionResolver exceptionResolver) Constructs a new instance of theDocxStamperConfigurationclass and initializes its default configuration settings. -
Method Summary
Modifier and TypeMethodDescriptionaddCommentProcessor(Class<?> interfaceClass, CommentProcessorFactory commentProcessorFactory) Registers the specifiedCommentProcessoras an implementation of the specified interface.addCustomFunction(String name, Class<T> class0) Adds a custom function to the context with the specified name and type.<T,U> CustomFunction.NeedsBiFunctionImpl <T, U> addCustomFunction(String name, Class<T> class0, Class<U> class1) Adds a custom function with the specified name and input types.<T,U, V> CustomFunction.NeedsTriFunctionImpl <T, U, V> addCustomFunction(String name, Class<T> class0, Class<U> class1, Class<V> class2) Adds a custom function to the current context by defining its name, and the classes associated with its argument types.voidaddCustomFunction(String name, Supplier<?> implementation) Adds a custom function to the system, allowing integration of user-defined functionality.voidaddCustomFunction(CustomFunction function) Adds a custom function to the list of functions.voidaddPostprocessor(PostProcessor postprocessor) Adds a given postprocessor to the list of postprocessors.voidaddPreprocessor(PreProcessor preprocessor) Adds a preprocessor to the configuration.addResolver(ObjectResolver resolver) Adds a resolver to the list of resolvers in theDocxStamperConfigurationobject.Retrieves a list of custom functions.exposeInterfaceToExpressionLanguage(Class<?> interfaceClass, Object implementation) Exposes all methods of a given interface to the expression language.Retrieves the map of comment processors associated with specific classes.Retrieves the configuredEvaluationContextFactoryinstance.Retrieves the exception resolver.Retrieves the mapping of expression function classes to their corresponding function instances.org.springframework.expression.ExpressionParserRetrieves the expression parser used by the office stamper.Retrieves the list of postprocessors.Retrieves the list of preprocessors.Retrieves the list of object resolvers.voidResets all processors in the configuration.voidResets all resolvers in the configuration.setEvaluationContextFactory(EvaluationContextFactory evaluationContextFactory) Sets theEvaluationContextFactorywhich creates SpringEvaluationContextinstances used for evaluating expressions in comments and text.setExceptionResolver(ExceptionResolver exceptionResolver) Configures the exception resolver for theDocxStamperConfiguration.setExpressionParser(org.springframework.expression.ExpressionParser expressionParser) Sets the expression parser used for expression evaluation.setResolvers(List<ObjectResolver> resolvers) Sets resolvers for resolving objects in theDocxStamperConfiguration.
-
Constructor Details
-
DocxStamperConfiguration
public DocxStamperConfiguration(EvaluationContextFactory evaluationContextFactory, ExceptionResolver exceptionResolver) Constructs a new instance of the
DocxStamperConfigurationclass and initializes its default configuration settings.This constructor sets up internal structures and default behaviors for managing document stamping configurations, including:
- Initializing collections for processors, resolvers, and functions.
- Setting default values for expression handling and evaluation.
- Creating and configuring a default
SpelParserConfiguration. - Establishing resolvers and exception handling strategies.
- Parameters:
evaluationContextFactory- the factory used to createEvaluationContextinstances.exceptionResolver- the exception resolver to use for handling exceptions during stamping.
-
-
Method Details
-
exposeInterfaceToExpressionLanguage
public DocxStamperConfiguration exposeInterfaceToExpressionLanguage(Class<?> interfaceClass, Object implementation) Exposes all methods of a given interface to the expression language.- Specified by:
exposeInterfaceToExpressionLanguagein interfaceOfficeStamperConfiguration- Parameters:
interfaceClass- the interface holding methods to expose in the expression language.implementation- the implementation to call to evaluate invocations of those methods, it must implement the mentioned interface.- Returns:
- a
DocxStamperConfigurationobject
-
addCommentProcessor
public DocxStamperConfiguration addCommentProcessor(Class<?> interfaceClass, CommentProcessorFactory commentProcessorFactory) Registers the specifiedCommentProcessoras an implementation of the specified interface.- Specified by:
addCommentProcessorin interfaceOfficeStamperConfiguration- Parameters:
interfaceClass- the interface, implemented by the commentProcessor.commentProcessorFactory- the commentProcessor factory generating instances of the specified interface.- Returns:
- a
DocxStamperConfigurationobject
-
addPreprocessor
Adds a preprocessor to the configuration.- Specified by:
addPreprocessorin interfaceOfficeStamperConfiguration- Parameters:
preprocessor- the preprocessor to add.
-
getEvaluationContextFactory
Retrieves the configuredEvaluationContextFactoryinstance.- Specified by:
getEvaluationContextFactoryin interfaceOfficeStamperConfiguration- Returns:
- an instance of
EvaluationContextFactoryused for creating evaluation contexts
-
setEvaluationContextFactory
public DocxStamperConfiguration setEvaluationContextFactory(EvaluationContextFactory evaluationContextFactory) Sets theEvaluationContextFactorywhich creates SpringEvaluationContextinstances used for evaluating expressions in comments and text.- Specified by:
setEvaluationContextFactoryin interfaceOfficeStamperConfiguration- Parameters:
evaluationContextFactory- the factory to use.- Returns:
- the configuration object for chaining.
-
getExpressionFunctions
Retrieves the mapping of expression function classes to their corresponding function instances.- Specified by:
getExpressionFunctionsin interfaceOfficeStamperConfiguration- Returns:
- a map where the keys are classes representing the function types, and the values are the function instances.
-
getCommentProcessors
Retrieves the map of comment processors associated with specific classes.- Specified by:
getCommentProcessorsin interfaceOfficeStamperConfiguration- Returns:
- a map where the key is the class associated with a specific type of placeholder, and the value is a
function that creates a
CommentProcessorfor that placeholder.
-
getPreprocessors
Retrieves the list of preprocessors.- Specified by:
getPreprocessorsin interfaceOfficeStamperConfiguration- Returns:
- a list of
PreProcessorobjects.
-
getResolvers
Retrieves the list of object resolvers.- Specified by:
getResolversin interfaceOfficeStamperConfiguration- Returns:
- a list of
ObjectResolverinstances.
-
setResolvers
Sets resolvers for resolving objects in the
DocxStamperConfiguration.This method is the evolution of the method
addResolver(ObjectResolver), and the order in which the resolvers are ordered is determinant; the first resolvers in the list will be tried first.If a fallback resolver is desired, it should be placed last in the list.
- Specified by:
setResolversin interfaceOfficeStamperConfiguration- Parameters:
resolvers- The list ofObjectResolverto be set.- Returns:
- the configuration object for chaining.
-
addResolver
Adds a resolver to the list of resolvers in the
DocxStamperConfigurationobject.Resolvers are used to resolve objects during the stamping process.
- Specified by:
addResolverin interfaceOfficeStamperConfiguration- Parameters:
resolver- The resolver to be added.- Returns:
- The modified
DocxStamperConfigurationobject, with the resolver added to the beginning of the resolver list.
-
getExceptionResolver
Retrieves the exception resolver.- Specified by:
getExceptionResolverin interfaceOfficeStamperConfiguration- Returns:
- the current instance of
ExceptionResolver.
-
setExceptionResolver
Configures the exception resolver for theDocxStamperConfiguration.- Specified by:
setExceptionResolverin interfaceOfficeStamperConfiguration- Parameters:
exceptionResolver- theExceptionResolverto handle exceptions during processing- Returns:
- the current instance of
DocxStamperConfiguration
-
customFunctions
Retrieves a list of custom functions.- Specified by:
customFunctionsin interfaceOfficeStamperConfiguration- Returns:
- a List containing
CustomFunctionobjects.
-
addCustomFunction
Adds a custom function to the system, allowing integration of user-defined functionality.- Specified by:
addCustomFunctionin interfaceOfficeStamperConfiguration- Parameters:
name- The name of the custom function being added. This is used as the identifier for the function and must be unique across all defined functions.implementation- ASupplierfunctional interface that provides the implementation of the custom function. When the function is called, the supplier's get method will be executed to return the result of the function.
-
addCustomFunction
Adds a custom function to the list of functions.- Parameters:
function- theCustomFunctionobject to be added
-
addCustomFunction
Adds a custom function to the context with the specified name and type.- Specified by:
addCustomFunctionin interfaceOfficeStamperConfiguration- Type Parameters:
T- the type of the input parameter- Parameters:
name- the name of the custom functionclass0- the class type of the custom function- Returns:
- an instance of
CustomFunction.NeedsFunctionImplconfigured with the custom function
-
addCustomFunction
public <T,U> CustomFunction.NeedsBiFunctionImpl<T,U> addCustomFunction(String name, Class<T> class0, Class<U> class1) Adds a custom function with the specified name and input types.- Specified by:
addCustomFunctionin interfaceOfficeStamperConfiguration- Type Parameters:
T- the type of the first input parameterU- the type of the second input parameter- Parameters:
name- the name of the custom function to be addedclass0- the class type of the first input parameter of the custom function.class1- the class type of the second input parameter of the custom function.- Returns:
- an instance of
CustomFunction.NeedsBiFunctionImplfor further configuration or usage of the custom function.
-
addCustomFunction
public <T,U, CustomFunction.NeedsTriFunctionImpl<T,V> U, addCustomFunctionV> (String name, Class<T> class0, Class<U> class1, Class<V> class2) Adds a custom function to the current context by defining its name, and the classes associated with its argument types.- Specified by:
addCustomFunctionin interfaceOfficeStamperConfiguration- Type Parameters:
T- the type of the first argumentU- the type of the second argumentV- the type of the third argument- Parameters:
name- the name to assign to the custom functionclass0- the class of the first argument typeclass1- the class of the second argument typeclass2- the class of the third argument type- Returns:
- an instance of
CustomFunction.NeedsTriFunctionImplindicating the custom function implementation and usage context.
-
getPostprocessors
Retrieves the list of postprocessors.- Specified by:
getPostprocessorsin interfaceOfficeStamperConfiguration- Returns:
- a List of
PostProcessorobjects.
-
addPostprocessor
Adds a given postprocessor to the list of postprocessors.- Specified by:
addPostprocessorin interfaceOfficeStamperConfiguration- Parameters:
postprocessor- thePostProcessorinstance to be added
-
getExpressionParser
public org.springframework.expression.ExpressionParser getExpressionParser()Description copied from interface:OfficeStamperConfigurationRetrieves the expression parser used by the office stamper.- Specified by:
getExpressionParserin interfaceOfficeStamperConfiguration- Returns:
- the
ExpressionParserinstance.
-
setExpressionParser
public DocxStamperConfiguration setExpressionParser(org.springframework.expression.ExpressionParser expressionParser) Sets the expression parser used for expression evaluation.
Note that the provided parser will be used for all expressions in the document, including expressions in comments. If you use SpEL, construct a
SpelExpressionParser(optionally with aSpelParserConfiguration) and pass it here.- Specified by:
setExpressionParserin interfaceOfficeStamperConfiguration- Parameters:
expressionParser- the parser to use.- Returns:
- the configuration object for chaining.
-
resetCommentProcessors
public void resetCommentProcessors()Resets all processors in the configuration. -
resetResolvers
public void resetResolvers()Resets all resolvers in the configuration.
-