Class PlaceholderReplacer

java.lang.Object
pro.verron.officestamper.core.PlaceholderReplacer
All Implemented Interfaces:
ParagraphPlaceholderReplacer

public class PlaceholderReplacer extends Object implements ParagraphPlaceholderReplacer
Replaces expressions in a document with the values provided by the ExpressionResolver.
Since:
1.0.0
Version:
${version}
Author:
Joseph Verron, Tom Hombergs
  • Constructor Details

    • PlaceholderReplacer

      public PlaceholderReplacer(ObjectResolverRegistry registry, ExpressionResolver resolver, boolean failOnUnresolvedExpression, boolean replaceUnresolvedExpressions, String unresolvedExpressionsDefaultValue, boolean leaveEmptyOnExpressionError, Placeholder linebreakPlaceholder)

      Constructor for PlaceholderReplacer.

      Parameters:
      registry - the registry containing all available type resolvers.
      resolver - the expression resolver used to resolve expressions in the document.
      failOnUnresolvedExpression - if set to true, an exception is thrown when an expression cannot be resolved.
      replaceUnresolvedExpressions - if set to true, expressions that cannot be resolved are replaced by the value provided in the unresolvedExpressionsDefaultValue parameter.
      unresolvedExpressionsDefaultValue - the value to use when replacing unresolved expressions.
      leaveEmptyOnExpressionError - if set to true, expressions that cannot be resolved will be by replaced by an empty string.
      linebreakPlaceholder - if set to a non-null value, all occurrences of this placeholder will be replaced with a line break.
  • Method Details

    • resolveExpressions

      public void resolveExpressions(org.docx4j.openpackaging.packages.WordprocessingMLPackage document, Object expressionContext)
      Finds expressions in a document and resolves them against the specified context object. The resolved values will then replace the expressions in the document.
      Parameters:
      document - the document in which to replace all expressions.
      expressionContext - the context root
    • resolveExpressionsForParagraph

      public void resolveExpressionsForParagraph(Paragraph paragraph, Object context, org.docx4j.openpackaging.packages.WordprocessingMLPackage document)
      Finds expressions in the given paragraph and replaces them with the values provided by the expression resolver.
      Specified by:
      resolveExpressionsForParagraph in interface ParagraphPlaceholderReplacer
      Parameters:
      paragraph - the paragraph in which to replace expressions.
      context - the context root
      document - the document in which to replace all expressions.