Class DocxStamperConfiguration

java.lang.Object
org.wickedsource.docxstamper.DocxStamperConfiguration

public class DocxStamperConfiguration extends Object
The DocxStamperConfiguration class represents the configuration for the DocxStamper class. It provides methods to customize the behavior of the stamper.
  • Constructor Details

    • DocxStamperConfiguration

      public DocxStamperConfiguration()
      Creates a new configuration with default values.
  • Method Details

    • nullReplacementValue

      @Deprecated(since="1.6.7") public Optional<String> 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-stamper
      Retrieves the default replacement value for null values.
      Returns:
      the Optional containing the default replacement value, or an empty Optional if no default replacement value is found
    • isFailOnUnresolvedExpression

      public boolean isFailOnUnresolvedExpression()

      isFailOnUnresolvedExpression.

      Returns:
      a boolean
    • setFailOnUnresolvedExpression

      public DocxStamperConfiguration setFailOnUnresolvedExpression(boolean failOnUnresolvedExpression)
      If set to true, stamper will throw an DocxStamperException if 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 DocxStamperConfiguration object
    • 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 use addResolver(ObjectResolver) and Resolvers.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 use addResolver(ObjectResolver) and Resolvers.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 DocxStamperConfiguration object
      See Also:
      • replaceUnresolvedExpressions
    • replaceUnresolvedExpressions

      public DocxStamperConfiguration replaceUnresolvedExpressions(boolean 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 DocxStamperConfiguration object
    • leaveEmptyOnExpressionError

      public DocxStamperConfiguration 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.
      Parameters:
      leaveEmpty - true to replace expressions with empty string when an error is caught while evaluating
      Returns:
      a DocxStamperConfiguration object
    • 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 the addResolver(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 DocxStamperConfiguration object
    • 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 DocxStamperConfiguration object
    • 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 DocxStamperConfiguration object
    • build

      @Deprecated(forRemoval=true, since="1.6.4") public <T> DocxStamper<T> build()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates a DocxStamper instance configured with this configuration.
      Type Parameters:
      T - a T class
      Returns:
      a DocxStamper object
    • addPreprocessor

      public void addPreprocessor(PreProcessor preprocessor)
      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

      public String getUnresolvedExpressionsDefaultValue()

      Getter for the field unresolvedExpressionsDefaultValue.

      Returns:
      a String object
    • getLineBreakPlaceholder

      public String getLineBreakPlaceholder()

      Getter for the field lineBreakPlaceholder.

      Returns:
      a String object
    • setLineBreakPlaceholder

      public DocxStamperConfiguration setLineBreakPlaceholder(String lineBreakPlaceholder)
      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

      public EvaluationContextConfigurer getEvaluationContextConfigurer()

      Getter for the field evaluationContextConfigurer.

      Returns:
      a EvaluationContextConfigurer object
    • setEvaluationContextConfigurer

      public DocxStamperConfiguration setEvaluationContextConfigurer(EvaluationContextConfigurer evaluationContextConfigurer)
      Provides an EvaluationContextConfigurer which may change the configuration of a Spring EvaluationContext which is used for evaluating expressions in comments and text.
      Parameters:
      evaluationContextConfigurer - the configurer to use.
      Returns:
      a DocxStamperConfiguration object
    • getSpelParserConfiguration

      public org.springframework.expression.spel.SpelParserConfiguration getSpelParserConfiguration()

      Getter for the field spelParserConfiguration.

      Returns:
      a SpelParserConfiguration object
    • setSpelParserConfiguration

      public DocxStamperConfiguration setSpelParserConfiguration(org.springframework.expression.spel.SpelParserConfiguration spelParserConfiguration)
      Sets the SpelParserConfiguration to 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 DocxStamperConfiguration object
    • getExpressionFunctions

      public Map<Class<?>,Object> getExpressionFunctions()

      Getter for the field expressionFunctions.

      Returns:
      a Map object
    • 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.7
      Retrieves the map of type resolvers.
      Returns:
      the map of type resolvers
    • getDefaultTypeResolver

      @Deprecated(since="1.6.7", forRemoval=true) public ITypeResolver<Object> 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 through addResolver(ObjectResolver) by putting your default first in the list, or by using setResolvers(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

      public Map<Class<?>,CommentProcessorBuilder> getCommentProcessors()

      Getter for the field commentProcessors.

      Returns:
      a Map object
    • isReplaceNullValues

      @Deprecated(since="1.6.7", forRemoval=true) public boolean 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:
      true if null values should be replaced, false otherwise.
    • getNullValuesDefault

      @Deprecated(since="1.6.7", forRemoval=true) public String 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

      public List<PreProcessor> getPreprocessors()

      Getter for the field preprocessors.

      Returns:
      a List object
    • getResolvers

      public List<ObjectResolver> getResolvers()
      Retrieves the list of resolvers.
      Returns:
      The list of object resolvers.
    • setResolvers

      public DocxStamperConfiguration setResolvers(List<ObjectResolver> resolvers)
      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

      public DocxStamperConfiguration addResolver(ObjectResolver resolver)
      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.