Class ParagraphWrapper

java.lang.Object
org.wickedsource.docxstamper.util.ParagraphWrapper

public class ParagraphWrapper extends Object

A "Run" defines a region of text within a docx document with a common set of properties. Word processors are relatively free in splitting a paragraph of text into multiple runs, so there is no strict rule to say over how many runs a word or a string of words is spread.

This class aggregates multiple runs so they can be treated as a single text, no matter how many runs the text spans. Call addRun() to add all runs that should be aggregated. Then, call methods to modify the aggregated text. Finally, call getText() or getRuns() to get the modified text or the list of modified runs.

Version:
${version}
Author:
Joseph Verron
  • Constructor Summary

    Constructors
    Constructor
    Description
    ParagraphWrapper(org.docx4j.wml.P paragraph)
    Constructs a new ParagraphWrapper for the given paragraph.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.docx4j.wml.P
    Getter for the field paragraph.
    List<org.docx4j.wml.R>
    Returns the list of runs that are aggregated.
    Returns the aggregated text over all runs.
    void
    Recalculates the runs of the paragraph.
    void
    replace(String placeholder, org.docx4j.wml.R replacement)
    Replaces the given placeholder String with the replacement object within the paragraph.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ParagraphWrapper

      public ParagraphWrapper(org.docx4j.wml.P paragraph)
      Constructs a new ParagraphWrapper for the given paragraph.
      Parameters:
      paragraph - the paragraph to wrap.
  • Method Details

    • recalculateRuns

      public void recalculateRuns()
      Recalculates the runs of the paragraph. This method is called automatically by the constructor, but can also be called manually to recalculate the runs after a modification to the paragraph was done.
    • replace

      public void replace(String placeholder, org.docx4j.wml.R replacement)
      Replaces the given placeholder String with the replacement object within the paragraph. The replacement object must be a valid DOCX4J Object.
      Parameters:
      placeholder - the placeholder to be replaced.
      replacement - the object to replace the placeholder String.
    • getText

      public String getText()
      Returns the aggregated text over all runs.
      Returns:
      the text of all runs.
    • getRuns

      public List<org.docx4j.wml.R> getRuns()
      Returns the list of runs that are aggregated. Depending on what modifications were done to the aggregated text this list may not return the same runs that were initially added to the aggregator.
      Returns:
      the list of aggregated runs.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getParagraph

      public org.docx4j.wml.P getParagraph()

      Getter for the field paragraph.

      Returns:
      a P object