Class DocxStamperConfiguration

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

public class DocxStamperConfiguration extends Object
Provides configuration parameters for DocxStamper.
Version:
1.6.6
Author:
Joseph Verron
  • Constructor Details

    • DocxStamperConfiguration

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

    • nullReplacementValue

      public Optional<String> nullReplacementValue()

      nullReplacementValue.

      Returns:
      the ITypeResolver for the given type or the default resolver if no resolver is registered for the given type.
    • isFailOnUnresolvedExpression

      public boolean isFailOnUnresolvedExpression()

      isFailOnUnresolvedExpression.

      Returns:
      a boolean
    • 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.
    • 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
    • nullValuesDefault

      public DocxStamperConfiguration nullValuesDefault(String nullValuesDefault)
      Indicates if expressions that resolve to null should be replaced by a global default value.
      Parameters:
      nullValuesDefault - value to use instead for expression resolving to null
      Returns:
      a DocxStamperConfiguration object
      See Also:
      • replaceNullValues
    • replaceNullValues

      public DocxStamperConfiguration replaceNullValues(boolean replaceNullValues)
      Indicates if expressions that resolve to null should be processed.
      Parameters:
      replaceNullValues - true to replace null value expression with resolved value (which is null), false to leave the expression as is
      Returns:
      a 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

      public <T> DocxStamperConfiguration addTypeResolver(Class<T> resolvedType, ITypeResolver<T> resolver)

      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.
      use new DocxStamper(DocxStamperConfiguration configuration) instead
      Creates a DocxStamper instance configured with this configuration.
      Type Parameters:
      T - a T class
      Returns:
      a DocxStamper object
    • setDefaultTypeResolver

      public DocxStamperConfiguration setDefaultTypeResolver(ITypeResolver<? super Object> defaultTypeResolver)

      Setter for the field defaultTypeResolver.

      Parameters:
      defaultTypeResolver - a ITypeResolver object
      Returns:
      a DocxStamperConfiguration object
    • addPreprocessor

      public void addPreprocessor(PreProcessor preprocessor)
      Adds a preprocessor to the configuration.
      Parameters:
      preprocessor - the preprocessor to add.
    • 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
    • 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
    • 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
    • getEvaluationContextConfigurer

      public EvaluationContextConfigurer getEvaluationContextConfigurer()

      Getter for the field evaluationContextConfigurer.

      Returns:
      a EvaluationContextConfigurer object
    • getSpelParserConfiguration

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

      Getter for the field spelParserConfiguration.

      Returns:
      a SpelParserConfiguration object
    • getExpressionFunctions

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

      Getter for the field expressionFunctions.

      Returns:
      a Map object
    • getTypeResolvers

      public Map<Class<?>,ITypeResolver<?>> getTypeResolvers()

      Getter for the field typeResolvers.

      Returns:
      a Map object
    • getDefaultTypeResolver

      public ITypeResolver<Object> getDefaultTypeResolver()

      Getter for the field defaultTypeResolver.

      Returns:
      a ITypeResolver object
    • getCommentProcessors

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

      Getter for the field commentProcessors.

      Returns:
      a Map object
    • isReplaceNullValues

      public boolean isReplaceNullValues()

      isReplaceNullValues.

      Returns:
      a boolean
    • getNullValuesDefault

      public String getNullValuesDefault()

      Getter for the field nullValuesDefault.

      Returns:
      a String object
    • getPreprocessors

      public List<PreProcessor> getPreprocessors()

      Getter for the field preprocessors.

      Returns:
      a List object