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.

  • Constructor Details

    • ParagraphWrapper

      public ParagraphWrapper(org.docx4j.wml.P paragraph)
  • Method Details

    • recalculateRuns

      public void recalculateRuns()
    • replace

      public void replace(String placeholder, Object 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()