Class AbstractMerger

java.lang.Object
org.docx4j.model.fields.AbstractMerger
Direct Known Subclasses:
FORMTEXTMerger, MailMerger

public abstract class AbstractMerger extends Object
Since:
11.5.12
Author:
jharrop
  • Field Details

  • Constructor Details

  • Method Details

    • getConsolidatedResultCrude

      public WordprocessingMLPackage getConsolidatedResultCrude(List<Map<DataFieldName,String>> data, boolean processHeadersAndFooters) throws Docx4JException
      A "poor man's" approach, which generates the mail merge results as a single docx, and just hopes for the best. Images and hyperlinks should be ok. But numbering will continue, as will footnotes/endnotes.
      Parameters:
      input -
      data -
      processHeadersAndFooters - process headers and footers in FIRST section only. If you have multiple sections in your input docx, performMerge is a better approach
      Returns:
      Throws:
      Docx4JException
      Since:
      11.5.12
    • performMerge

      public void performMerge(Map<DataFieldName,String> data, boolean processHeadersAndFooters) throws Docx4JException
      Perform merge on a single instance. This is the best approach, if your input has headers/footers in multiple sections. If you are using MergeDocx, you can use that to join the instances into a single docx. WARNING: The input docx will be modified, so input a copy if that is a problem. This is left to the user, since that can potentially be more efficient, than doing it here.
      Parameters:
      input -
      data -
      processHeadersAndFooters -
      Throws:
      Docx4JException
    • performOnInstance

      protected abstract List<Object> performOnInstance(List<Object> contentList, Map<DataFieldName,String> datamap, AbstractMerger.FormTextFieldNames formTextFieldNames) throws Docx4JException
      Throws:
      Docx4JException
    • canonicaliseStarts

      protected static void canonicaliseStarts(ComplexFieldLocator fl, List<FieldRef> fieldRefs) throws Docx4JException
      Parameters:
      fl -
      fieldRefs -
      Throws:
      Docx4JException
    • removeSimpleField

      protected static void removeSimpleField(FieldRef fr)
      Remove the field but preserve the paragraph and content around it
      Parameters:
      fr -
    • getTextInsideContent

      protected static String getTextInsideContent(ContentAccessor paragraph)
      Parse through all content inside the paragraph to concatenate all values inside a text
      Parameters:
      paragraph - The paragraph which contains (or not) data
      Returns:
      All text inside the paragraph
    • recursiveRemove

      protected static void recursiveRemove(ContentAccessor content, Object needToBeRemoved)
      To remove an object from the docx template
      Parameters:
      content - Body (or other part) of the template
      needToBeRemoved - The object that will be removed from the content
    • setOutputField

      public static void setOutputField(MailMerger.OutputField fieldFate)
      What to do with the MERGEFIELD in the output docx. Default is REMOVED. KEEP_MERGEFIELD will allow you to perform another merge on the output document. The AS_FORMTEXT options convert the MERGEFIELD to a FORMTEXT field. This is convenient if you want users to be able to edit the field, where editing is restricted to forms.
      Parameters:
      fieldFate -
    • setFormFieldProperties

      protected static void setFormFieldProperties(FieldRef fr, String ffName, String ffTextInputFormat)