Class DocxStamperConfiguration
DocxStamperConfiguration class represents the configuration for the DocxStamper class.
It provides methods to customize the behavior of the stamper.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddCommentProcessor(Class<?> interfaceClass, CommentProcessorBuilder commentProcessorFactory) Registers the specified ICommentProcessor as an implementation of the specified interface.voidaddPreprocessor(PreProcessor preprocessor) Adds a preprocessor to the configuration.addResolver(ObjectResolver resolver) Adds a resolver to the list of resolvers in the `DocxStamperConfiguration` object.addTypeResolver(Class<T> resolvedType, ITypeResolver<T> resolver) Deprecated, for removal: This API element is subject to removal in a future version.This method has been deprecated since version 1.6.7, and it is scheduled for removal.<T> DocxStamper<T> build()Deprecated, for removal: This API element is subject to removal in a future version.use newDocxStamper(DocxStamperConfiguration)insteadexposeInterfaceToExpressionLanguage(Class<?> interfaceClass, Object implementation) Exposes all methods of a given interface to the expression language.Getter for the fieldcommentProcessors.Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated since version 1.6.7 and is scheduled for removal.Getter for the fieldevaluationContextConfigurer.Getter for the fieldexpressionFunctions.Getter for the fieldlineBreakPlaceholder.Deprecated, for removal: This API element is subject to removal in a future version.This method has been deprecated since version 1.6.7 and is scheduled for removal.Getter for the fieldpreprocessors.Retrieves the list of resolvers.org.springframework.expression.spel.SpelParserConfigurationGetter for the fieldspelParserConfiguration.Map<Class<?>, ITypeResolver<?>> Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated since version 1.6.7Getter for the fieldunresolvedExpressionsDefaultValue.booleanisFailOnUnresolvedExpression.booleanisLeaveEmptyOnExpressionError.booleanDeprecated, for removal: This API element is subject to removal in a future version.This method is deprecated since version 1.6.7 and will be removed in a future release.booleanisReplaceUnresolvedExpressions.leaveEmptyOnExpressionError(boolean leaveEmpty) If an error is caught while evaluating an expression the expression will be replaced with an empty string instead of leaving the original expression in the document.Deprecated.This method is deprecated since version 1.6.7.nullValuesDefault(String nullValuesDefault) Deprecated, for removal: This API element is subject to removal in a future version.This method has been deprecated since version 1.6.7.replaceNullValues(boolean replaceNullValues) Deprecated, for removal: This API element is subject to removal in a future version.This method has been deprecated since version 1.6.7.replaceUnresolvedExpressions(boolean replaceUnresolvedExpressions) Indicates if expressions that doesn't resolve should be replaced by a default value.setDefaultTypeResolver(ITypeResolver<? super Object> defaultResolver) Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated and scheduled for removal in version 1.6.7.setEvaluationContextConfigurer(EvaluationContextConfigurer evaluationContextConfigurer) Provides anEvaluationContextConfigurerwhich may change the configuration of a SpringEvaluationContextwhich is used for evaluating expressions in comments and text.setFailOnUnresolvedExpression(boolean failOnUnresolvedExpression) If set to true, stamper will throw anDocxStamperExceptionif a variable expression or processor expression within the document or within the comments is encountered that cannot be resolved.setLineBreakPlaceholder(String lineBreakPlaceholder) The String provided as lineBreakPlaceholder will be replaced with a line break when stamping a document.setResolvers(List<ObjectResolver> resolvers) Sets the resolvers for resolving objects in the DocxStamperConfiguration.setSpelParserConfiguration(org.springframework.expression.spel.SpelParserConfiguration spelParserConfiguration) Sets theSpelParserConfigurationto use for expression parsing.unresolvedExpressionsDefaultValue(String unresolvedExpressionsDefaultValue) Indicates the default value to use for expressions that doesn't resolve.
-
Constructor Details
-
DocxStamperConfiguration
public DocxStamperConfiguration()Creates a new configuration with default values.
-
-
Method Details
-
nullReplacementValue
Deprecated.This method is deprecated since version 1.6.7. You shouldn't have to use it, it was a crutch use for inner workinf of docx-stamperRetrieves the default replacement value for null values. -
isFailOnUnresolvedExpression
public boolean isFailOnUnresolvedExpression()isFailOnUnresolvedExpression.
- Returns:
- a boolean
-
setFailOnUnresolvedExpression
If set to true, stamper will throw anDocxStamperExceptionif a variable expression or processor expression within the document or within the comments is encountered that cannot be resolved. Is set to true by default.- Parameters:
failOnUnresolvedExpression- a boolean- Returns:
- a
DocxStamperConfigurationobject
-
nullValuesDefault
@Deprecated(since="1.6.7", forRemoval=true) public DocxStamperConfiguration nullValuesDefault(String nullValuesDefault) Deprecated, for removal: This API element is subject to removal in a future version.This method has been deprecated since version 1.6.7. It is recommended to useaddResolver(ObjectResolver)andResolvers.nullToDefault(String)instead.Sets the default value for null values in the document.- Parameters:
nullValuesDefault- The default value for null values.- Returns:
- The updated DocxStamperConfiguration object.
-
replaceNullValues
@Deprecated(since="1.6.7", forRemoval=true) public DocxStamperConfiguration replaceNullValues(boolean replaceNullValues) Deprecated, for removal: This API element is subject to removal in a future version.This method has been deprecated since version 1.6.7. It is recommended to useaddResolver(ObjectResolver)andResolvers.nullToDefault(String)instead.Replaces null values with either empty string or a placeholder value, based on the given flag.- Parameters:
replaceNullValues- Flag indicating whether to replace null values or not.- Returns:
- The updated DocxStamperConfiguration object.
-
unresolvedExpressionsDefaultValue
public DocxStamperConfiguration unresolvedExpressionsDefaultValue(String unresolvedExpressionsDefaultValue) Indicates the default value to use for expressions that doesn't resolve.- Parameters:
unresolvedExpressionsDefaultValue- value to use instead for expression that doesn't resolve- Returns:
- a
DocxStamperConfigurationobject - See Also:
-
replaceUnresolvedExpressions
Indicates if expressions that doesn't resolve should be replaced by a default value.- Parameters:
replaceUnresolvedExpressions- true to replace null value expression with resolved value (which is null), false to leave the expression as is- Returns:
- a
DocxStamperConfigurationobject
-
leaveEmptyOnExpressionError
If an error is caught while evaluating an expression the expression will be replaced with an empty string instead of leaving the original expression in the document.- Parameters:
leaveEmpty- true to replace expressions with empty string when an error is caught while evaluating- Returns:
- a
DocxStamperConfigurationobject
-
addTypeResolver
@Deprecated(since="1.6.7", forRemoval=true) public <T> DocxStamperConfiguration addTypeResolver(Class<T> resolvedType, ITypeResolver<T> resolver) Deprecated, for removal: This API element is subject to removal in a future version.This method has been deprecated since version 1.6.7, and it is scheduled for removal. It's recommended to use theaddResolver(ObjectResolver)method for adding resolvers.Registers the given ITypeResolver for the given class. The registered ITypeResolver's resolve() method will only be called with objects of the specified class.
Note that each type can only be resolved by ONE ITypeResolver implementation. Multiple calls to addTypeResolver() with the same resolvedType parameter will override earlier calls.
- Type Parameters:
T- the type resolved by the ITypeResolver.- Parameters:
resolvedType- the class whose objects are to be passed to the given ITypeResolver.resolver- the resolver to resolve objects of the given type.- Returns:
- a
DocxStamperConfigurationobject
-
exposeInterfaceToExpressionLanguage
public DocxStamperConfiguration exposeInterfaceToExpressionLanguage(Class<?> interfaceClass, Object implementation) Exposes all methods of a given interface to the expression language.- Parameters:
interfaceClass- the interface whose methods should be exposed in the expression language.implementation- the implementation that should be called to evaluate invocations of the interface methods within the expression language. Must implement the interface above.- Returns:
- a
DocxStamperConfigurationobject
-
addCommentProcessor
public DocxStamperConfiguration addCommentProcessor(Class<?> interfaceClass, CommentProcessorBuilder commentProcessorFactory) Registers the specified ICommentProcessor as an implementation of the specified interface.- Parameters:
interfaceClass- the Interface which is implemented by the commentProcessor.commentProcessorFactory- the commentProcessor factory generating the specified interface.- Returns:
- a
DocxStamperConfigurationobject
-
build
Deprecated, for removal: This API element is subject to removal in a future version.use newDocxStamper(DocxStamperConfiguration)insteadCreates aDocxStamperinstance configured with this configuration.- Type Parameters:
T- a T class- Returns:
- a
DocxStamperobject
-
addPreprocessor
Adds a preprocessor to the configuration.- Parameters:
preprocessor- the preprocessor to add.
-
isReplaceUnresolvedExpressions
public boolean isReplaceUnresolvedExpressions()isReplaceUnresolvedExpressions.
- Returns:
- a boolean
-
isLeaveEmptyOnExpressionError
public boolean isLeaveEmptyOnExpressionError()isLeaveEmptyOnExpressionError.
- Returns:
- a boolean
-
getUnresolvedExpressionsDefaultValue
Getter for the field
unresolvedExpressionsDefaultValue.- Returns:
- a
Stringobject
-
getLineBreakPlaceholder
Getter for the field
lineBreakPlaceholder.- Returns:
- a
Stringobject
-
setLineBreakPlaceholder
The String provided as lineBreakPlaceholder will be replaced with a line break when stamping a document. If no lineBreakPlaceholder is provided, no replacement will take place.- Parameters:
lineBreakPlaceholder- the String that should be replaced with line breaks during stamping.- Returns:
- the configuration object for chaining.
-
getEvaluationContextConfigurer
Getter for the field
evaluationContextConfigurer.- Returns:
- a
EvaluationContextConfigurerobject
-
setEvaluationContextConfigurer
public DocxStamperConfiguration setEvaluationContextConfigurer(EvaluationContextConfigurer evaluationContextConfigurer) Provides anEvaluationContextConfigurerwhich may change the configuration of a SpringEvaluationContextwhich is used for evaluating expressions in comments and text.- Parameters:
evaluationContextConfigurer- the configurer to use.- Returns:
- a
DocxStamperConfigurationobject
-
getSpelParserConfiguration
public org.springframework.expression.spel.SpelParserConfiguration getSpelParserConfiguration()Getter for the field
spelParserConfiguration.- Returns:
- a
SpelParserConfigurationobject
-
setSpelParserConfiguration
public DocxStamperConfiguration setSpelParserConfiguration(org.springframework.expression.spel.SpelParserConfiguration spelParserConfiguration) Sets theSpelParserConfigurationto use for expression parsing.Note that this configuration will be used for all expressions in the document, including expressions in comments!
- Parameters:
spelParserConfiguration- the configuration to use.- Returns:
- a
DocxStamperConfigurationobject
-
getExpressionFunctions
Getter for the field
expressionFunctions.- Returns:
- a
Mapobject
-
getTypeResolvers
@Deprecated(since="1.6.7", forRemoval=true) public Map<Class<?>,ITypeResolver<?>> getTypeResolvers()Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated since version 1.6.7Retrieves the map of type resolvers.- Returns:
- the map of type resolvers
-
getDefaultTypeResolver
Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated since version 1.6.7 and is scheduled for removal. You should not have to use it, it was a clutch for previosu version of docx-stamper.Returns the default type resolver.This method returns the default type resolver from a list of resolvers. It filters the resolvers to only include instances of
ITypeResolver, and returns the first one found. If no type resolver is found, null is returned.- Returns:
- the default type resolver, or null if not found
-
setDefaultTypeResolver
@Deprecated(since="1.6.7", forRemoval=true) public DocxStamperConfiguration setDefaultTypeResolver(ITypeResolver<? super Object> defaultResolver) Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated and scheduled for removal in version 1.6.7. Please set your "default" resolver throughaddResolver(ObjectResolver)by putting your default first in the list, or by usingsetResolvers(List)} and putting your fallback resolvers in the last place.Sets the default type resolver for the DocxStamperConfiguration.- Parameters:
defaultResolver- The default type resolver to set.- Returns:
- The updated DocxStamperConfiguration instance.
-
getCommentProcessors
Getter for the field
commentProcessors.- Returns:
- a
Mapobject
-
isReplaceNullValues
Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated since version 1.6.7 and will be removed in a future release. You shouldn't have to use it, it was a clutch for docx-stamper workings.Gets the flag indicating whether null values should be replaced.- Returns:
trueif null values should be replaced,falseotherwise.
-
getNullValuesDefault
Deprecated, for removal: This API element is subject to removal in a future version.This method has been deprecated since version 1.6.7 and is scheduled for removal. You shouldn't have to use it, it was a clutch for docx-stamper workings.Retrieves the default value used for representing null values.- Returns:
- the default value for null values
-
getPreprocessors
Getter for the field
preprocessors.- Returns:
- a
Listobject
-
getResolvers
Retrieves the list of resolvers.- Returns:
- The list of object resolvers.
-
setResolvers
Sets the resolvers for resolving objects in the DocxStamperConfiguration.This method is the evolution of the method
addTypeResolver, 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.- Parameters:
resolvers- The list of ObjectResolvers to be set.- Returns:
- The updated DocxStamperConfiguration instance.
-
addResolver
Adds a resolver to the list of resolvers in the `DocxStamperConfiguration` object. Resolvers are used to resolve objects during the stamping process.- Parameters:
resolver- The resolver to be added. This resolver should implement the `ObjectResolver` interface.- Returns:
- The modified `DocxStamperConfiguration` object, with the resolver added to the beginning of the resolver list.
-