Class ParagraphWrapper
java.lang.Object
org.wickedsource.docxstamper.util.ParagraphWrapper
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:
- 1.6.6
- Author:
- Joseph Verron
-
Constructor Summary
ConstructorsConstructorDescriptionParagraphWrapper(org.docx4j.wml.P paragraph) Constructs a new ParagraphWrapper for the given paragraph. -
Method Summary
Modifier and TypeMethodDescriptionorg.docx4j.wml.PGetter for the fieldparagraph.List<org.docx4j.wml.R> getRuns()Returns the list of runs that are aggregated.getText()Returns the aggregated text over all runs.voidRecalculates the runs of the paragraph.voidReplaces the given placeholder String with the replacement object within the paragraph.toString()
-
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
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
Returns the aggregated text over all runs.- Returns:
- the text of all runs.
-
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
-
getParagraph
public org.docx4j.wml.P getParagraph()Getter for the field
paragraph.- Returns:
- a
Pobject
-