java.lang.Object
pro.verron.officestamper.utils.WmlFactory
Utility class for creating and configuring various WordML (WML) elements.
Provides static methods to generate paragraphs, runs, comments, text, and other WML structures.
This is intended for handling Office Open XML documents programmatically.
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.docx4j.wml.Body
Creates a new Body object containing the provided elements.static org.docx4j.wml.Br
newBr()
Creates a new Br (break) object with text wrapping enabled.static org.docx4j.wml.Tc
newCell()
Creates a new cell object.static org.docx4j.wml.Comments.Comment
newComment
(BigInteger id, String value) Creates a new comment with the provided value.static org.docx4j.wml.CommentRangeEnd
newCommentRangeEnd
(BigInteger id, org.docx4j.wml.P parent) Creates a new CommentRangeEnd object with the specified ID and parent.static org.docx4j.wml.CommentRangeStart
newCommentRangeStart
(BigInteger id, org.docx4j.wml.P parent) Creates a new CommentRangeStart object with the specified ID and parent.static org.docx4j.wml.R.CommentReference
newCommentReference
(BigInteger id, org.docx4j.wml.P parent) Creates a new CommentReference object with the specified ID and parent.static org.docx4j.wml.Comments
newComments
(List<org.docx4j.wml.Comments.Comment> list) Creates a new Comments object and populates it with a list of Comment objects.static org.docx4j.openpackaging.parts.WordprocessingML.CommentsPart
Creates a new CommentsPart object.static org.docx4j.wml.Drawing
newDrawing
(org.docx4j.dml.wordprocessingDrawing.Inline inline) Creates a new Drawing object containing the provided Inline object.static org.docx4j.dml.wordprocessingDrawing.Inline
newInline
(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage imagePart, String filenameHint, String altText, Integer maxWidth) Creates a new Inline object for the given image part, filename hint, and alt text.static org.docx4j.wml.P
newParagraph
(String value) Creates a new paragraph containing the provided string value.static org.docx4j.wml.P
newParagraph
(String... texts) Creates a new paragraph containing the provided text values.static org.docx4j.wml.P
newParagraph
(List<?> values) Creates a new paragraph containing the provided list of values.static org.docx4j.wml.P
newParagraph
(org.docx4j.wml.Drawing drawing) Creates a new paragraph containing a single drawing element.static org.docx4j.wml.P
newParagraph
(org.docx4j.wml.R run) Creates a new paragraph containing the provided run.static org.docx4j.wml.PPr
newPPr()
Creates a new PPr (paragraph properties) object.static org.docx4j.wml.Tr
newRow()
Creates a new row object.static org.docx4j.wml.R
newRun
(Integer maxWidth, org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage abstractImage, String filenameHint, String altText) Creates a new run containing an image with the specified attributes.static org.docx4j.wml.R
Creates a new run containing the provided string value.static org.docx4j.wml.R
Creates a new run containing the provided values deemed worth keeping.static org.docx4j.wml.R
newRun
(org.docx4j.wml.Drawing value) Creates a new run containing a single drawing.static org.docx4j.wml.R
newRun
(org.docx4j.wml.Text value) Creates a new run containing a single text object.static org.docx4j.wml.Tbl
newTbl()
Creates a new table object.static org.docx4j.wml.Text
Creates a new Text object with the specified value, preserving spaces.static org.docx4j.openpackaging.packages.WordprocessingMLPackage
newWord()
Creates a new WordprocessingMLPackage object initialized with a main document part, and an empty comments part.
-
Method Details
-
newParagraph
public static org.docx4j.wml.P newParagraph(org.docx4j.wml.Drawing drawing) Creates a new paragraph containing a single drawing element.- Parameters:
drawing
- The Drawing object to be included in the new paragraph.- Returns:
- A new paragraph containing the provided drawing encapsulated in a run.
-
newParagraph
Creates a new paragraph containing the provided list of values.- Parameters:
values
- A list of objects to be added to the new paragraph. These objects populate the content of the paragraph.- Returns:
- A new paragraph containing the provided values.
-
newRun
public static org.docx4j.wml.R newRun(org.docx4j.wml.Drawing value) Creates a new run containing a single drawing.- Parameters:
value
- The Drawing object to be included in the new run.- Returns:
- A new run encapsulating the provided drawing.
-
newRun
Creates a new run containing the provided values deemed worth keeping.- Parameters:
values
- A list of objects to be added to the new run. Objects are filtered based on a predefined criteria to determine if they are worth keeping.- Returns:
- A new run containing the filtered values.
-
newComment
Creates a new comment with the provided value.- Parameters:
value
- The string value to be included in the comment.- Returns:
- A new Comments.Comment object containing the provided value.
-
newParagraph
Creates a new paragraph containing the provided string value.- Parameters:
value
- The string value to be added to the new paragraph.- Returns:
- A new paragraph containing the provided string value.
-
newParagraph
public static org.docx4j.wml.P newParagraph(org.docx4j.wml.R run) Creates a new paragraph containing the provided run.- Parameters:
run
- The R object (run) to be included in the new paragraph.- Returns:
- A new paragraph containing the provided run.
-
newRun
Creates a new run containing the provided string value.- Parameters:
value
- The string value to be included in the new run.- Returns:
- A new run containing the provided string value.
-
newRun
public static org.docx4j.wml.R newRun(org.docx4j.wml.Text value) Creates a new run containing a single text object.- Parameters:
value
- The Text object to be included in the new run.- Returns:
- A new run encapsulating the provided text object.
-
newText
Creates a new Text object with the specified value, preserving spaces.- Parameters:
value
- The string value to be set in the new Text object.- Returns:
- A new Text object containing the provided value with space preserved.
-
newBody
Creates a new Body object containing the provided elements.- Parameters:
elements
- A list of objects to be added to the new Body.- Returns:
- A new Body containing the provided elements.
-
newParagraph
Creates a new paragraph containing the provided text values.- Parameters:
texts
- The array of string values to be included in the new paragraph.- Returns:
- A new paragraph containing the provided text values.
-
newPPr
public static org.docx4j.wml.PPr newPPr()Creates a new PPr (paragraph properties) object.- Returns:
- A new PPr object.
-
newComments
Creates a new Comments object and populates it with a list of Comment objects.- Parameters:
list
- A list of Comments.Comment objects to be added to the new Comments object.- Returns:
- A new Comments object containing the provided Comment objects.
-
newRun
public static org.docx4j.wml.R newRun(@Nullable Integer maxWidth, org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage abstractImage, String filenameHint, String altText) Creates a new run containing an image with the specified attributes.- Parameters:
maxWidth
- the maximum width of the image, it can be nullabstractImage
- the binary part abstract image to be included in the runfilenameHint
- the filename hint for the imagealtText
- the alternative text for the image- Returns:
- a new run element containing the image
-
newInline
public static org.docx4j.dml.wordprocessingDrawing.Inline newInline(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage imagePart, String filenameHint, String altText, @Nullable Integer maxWidth) Creates a new Inline object for the given image part, filename hint, and alt text.- Parameters:
imagePart
- The binary part abstract image to be used.filenameHint
- A hint for the filename of the image.altText
- Alternative text for the image.- Returns:
- A new Inline object containing the specified image information.
- Throws:
OfficeStamperException
- If there is an error creating the image inline.
-
newDrawing
public static org.docx4j.wml.Drawing newDrawing(org.docx4j.dml.wordprocessingDrawing.Inline inline) Creates a new Drawing object containing the provided Inline object.- Parameters:
inline
- The Inline object to be contained within the new Drawing.- Returns:
- A new Drawing object encapsulating the provided inline object.
-
newCommentRangeStart
public static org.docx4j.wml.CommentRangeStart newCommentRangeStart(BigInteger id, org.docx4j.wml.P parent) Creates a new CommentRangeStart object with the specified ID and parent.- Parameters:
id
- The unique identifier for the CommentRangeStart object.parent
- The parent element (P) to which this CommentRangeStart belongs.- Returns:
- A new CommentRangeStart object with the specified ID and parent.
-
newCommentRangeEnd
public static org.docx4j.wml.CommentRangeEnd newCommentRangeEnd(BigInteger id, org.docx4j.wml.P parent) Creates a new CommentRangeEnd object with the specified ID and parent.- Parameters:
id
- The unique identifier for the CommentRangeEnd object.parent
- The parent element (P) to which this CommentRangeEnd belongs.- Returns:
- A new CommentRangeEnd object with the specified ID and parent.
-
newCommentReference
public static org.docx4j.wml.R.CommentReference newCommentReference(BigInteger id, org.docx4j.wml.P parent) Creates a new CommentReference object with the specified ID and parent.- Parameters:
id
- The unique identifier for the CommentReference.parent
- The parent element (P) to which this CommentReference belongs.- Returns:
- A new CommentReference object with the specified ID and parent.
-
newTbl
public static org.docx4j.wml.Tbl newTbl()Creates a new table object.- Returns:
- A new instance of Tbl.
-
newCell
public static org.docx4j.wml.Tc newCell()Creates a new cell object.- Returns:
- A new instance of Tc.
-
newRow
public static org.docx4j.wml.Tr newRow()Creates a new row object.- Returns:
- A new instance of Tr.
-
newWord
public static org.docx4j.openpackaging.packages.WordprocessingMLPackage newWord()Creates a new WordprocessingMLPackage object initialized with a main document part, and an empty comments part.- Returns:
- A new instance of WordprocessingMLPackage.
-
newCommentsPart
public static org.docx4j.openpackaging.parts.WordprocessingML.CommentsPart newCommentsPart()Creates a new CommentsPart object. This method attempts to create a new instance of CommentsPart. If an InvalidFormatException occurs during the creation process, it wraps the exception in an OfficeStamperException and throws it.- Returns:
- A new instance of CommentsPart.
-
newBr
public static org.docx4j.wml.Br newBr()Creates a new Br (break) object with text wrapping enabled.- Returns:
- A new Br object with text wrapping type and no clear attribute set.
-