Class PowerpointParagraph

java.lang.Object
pro.verron.officestamper.experimental.PowerpointParagraph
All Implemented Interfaces:
Paragraph

public class PowerpointParagraph extends Object implements Paragraph

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.

Since:
1.0.8
Version:
${version}
Author:
Joseph Verron, Tom Hombergs
  • Constructor Summary

    Constructors
    Constructor
    Description
    PowerpointParagraph(PptxPart part, org.docx4j.dml.CTTextParagraph paragraph)
    Constructs a new ParagraphWrapper for the given paragraph.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    apply(Consumer<org.docx4j.wml.ContentAccessor> pConsumer)
    Applies the specified consumer function to the paragraph content.
    Returns the aggregated text over all runs.
    Collection<org.docx4j.wml.Comments.Comment>
    Retrieves a collection of comments associated with the paragraph.
    <T> Optional<T>
    parent(Class<T> aClass)
    Retrieves the parent of the current paragraph that matches the specified class type.
    Retrieves the parent table of the current paragraph, if it exists.
    Retrieves the parent table row of the current paragraph, if it exists.
    void
    Removes the paragraph from the document.
    void
    replace(Object from, Object to, Insert insert)
    Replaces a section of elements within the document, defined by the start and end objects, with the elements provided by the given insert.
    void
    replace(String expression, Insert insert)
    Replaces a placeholder within the paragraph with the content from the given insert, preserving formatting.
    void
    replace(List<org.docx4j.wml.P> toRemove, List<org.docx4j.wml.P> toAdd)
    Replaces specified contiguous elements within the paragraph with new elements.

    Methods inherited from class Object

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

    • PowerpointParagraph

      public PowerpointParagraph(PptxPart part, org.docx4j.dml.CTTextParagraph paragraph)
      Constructs a new ParagraphWrapper for the given paragraph.
      Parameters:
      part - the source of the paragraph.
      paragraph - the paragraph to wrap.
  • Method Details

    • replace

      public void replace(List<org.docx4j.wml.P> toRemove, List<org.docx4j.wml.P> toAdd)
      Description copied from interface: Paragraph
      Replaces specified contiguous elements within the paragraph with new elements.
      Specified by:
      replace in interface Paragraph
      Parameters:
      toRemove - The list of elements to be removed from the paragraph.
      toAdd - The list of elements to be added to the paragraph.
    • remove

      public void remove()
      Description copied from interface: Paragraph
      Removes the paragraph from the document. This method is intended to be used when a paragraph needs to be deleted.
      Specified by:
      remove in interface Paragraph
    • replace

      public void replace(String expression, Insert insert)
      Replaces a placeholder within the paragraph with the content from the given insert, preserving formatting.
      Specified by:
      replace in interface Paragraph
      Parameters:
      expression - the expression to replace.
      insert - the content to replace the placeholder with; must be a valid and compatible text run
    • replace

      public void replace(Object from, Object to, Insert insert)
      Description copied from interface: Paragraph
      Replaces a section of elements within the document, defined by the start and end objects, with the elements provided by the given insert.
      Specified by:
      replace in interface Paragraph
      Parameters:
      from - the starting object marking the beginning of the section to replace.
      to - the ending object marking the end of the section to replace.
      insert - the insert containing the elements that will replace the specified section.
    • asString

      public String asString()
      Returns the aggregated text over all runs.
      Specified by:
      asString in interface Paragraph
      Returns:
      the text of all runs.
    • apply

      public void apply(Consumer<org.docx4j.wml.ContentAccessor> pConsumer)
      Description copied from interface: Paragraph
      Applies the specified consumer function to the paragraph content.
      Specified by:
      apply in interface Paragraph
      Parameters:
      pConsumer - The consumer function to apply to the paragraph content.
    • parent

      public <T> Optional<T> parent(Class<T> aClass)
      Description copied from interface: Paragraph
      Retrieves the parent of the current paragraph that matches the specified class type.
      Specified by:
      parent in interface Paragraph
      Type Parameters:
      T - The type of the parent element to be returned.
      Parameters:
      aClass - The class type to match for the parent element.
      Returns:
      An Optional containing the matched parent element if found, otherwise an empty Optional.
    • getComment

      public Collection<org.docx4j.wml.Comments.Comment> getComment()
      Description copied from interface: Paragraph
      Retrieves a collection of comments associated with the paragraph.
      Specified by:
      getComment in interface Paragraph
      Returns:
      a collection of Comments.Comment objects related to the paragraph
    • parentTableRow

      public Optional<Table.Row> parentTableRow()
      Description copied from interface: Paragraph
      Retrieves the parent table row of the current paragraph, if it exists.
      Specified by:
      parentTableRow in interface Paragraph
      Returns:
      an Optional containing the parent Table.Row if the paragraph is within a table row, otherwise an empty Optional
    • parentTable

      public Optional<Table> parentTable()
      Description copied from interface: Paragraph
      Retrieves the parent table of the current paragraph, if it exists.
      Specified by:
      parentTable in interface Paragraph
      Returns:
      an Optional containing the parent Table if the paragraph is within a table, otherwise an empty Optional
    • toString

      public String toString()
      Overrides:
      toString in class Object