Class WmlFactory

java.lang.Object
pro.verron.officestamper.utils.WmlFactory

public class WmlFactory extends Object
WmlFactory is a utility class providing methods to create and manipulate WordML objects. It includes methods for creating paragraphs, runs, text elements, comments, bodies and drawings. This factory encapsulates the complexity of WordML elements and simplifies the process of working with them.
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.docx4j.wml.Body
    newBody(List<Object> elements)
    Creates a new Body object containing the provided elements.
    static org.docx4j.wml.Comments.Comment
    Creates a new comment with the provided value.
    static org.docx4j.wml.CommentRangeEnd
    newCommentRangeEnd(BigInteger id, org.docx4j.wml.P parent)
     
    static org.docx4j.wml.CommentRangeStart
    newCommentRangeStart(BigInteger id, org.docx4j.wml.P parent)
     
    static org.docx4j.wml.R.CommentReference
    newCommentReference(BigInteger id, org.docx4j.wml.P 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
    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 values.
    static org.docx4j.wml.P
    newParagraph(org.docx4j.wml.Drawing drawing)
    Creates a new paragraph containing a single drawing.
    static org.docx4j.wml.P
    newParagraph(org.docx4j.wml.R run)
    Creates a new paragraph containing the provided run.
    static org.docx4j.wml.PPr
    Creates a new PPr (paragraph properties) 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
    newRun(String value)
    Creates a new run containing the provided string value.
    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.Text
    newText(String value)
    Creates a new Text object with the specified value, preserving spaces.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • newParagraph

      public static org.docx4j.wml.P newParagraph(org.docx4j.wml.Drawing drawing)
      Creates a new paragraph containing a single drawing.
      Parameters:
      drawing - The Drawing object to be included in the new paragraph.
      Returns:
      A new paragraph encapsulating the provided drawing.
    • newParagraph

      public static org.docx4j.wml.P newParagraph(List<?> values)
      Creates a new paragraph containing the provided values.
      Parameters:
      values - A list of objects to be added to the new 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.
    • newComment

      public static org.docx4j.wml.Comments.Comment newComment(BigInteger id, String value)
      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

      public static org.docx4j.wml.P newParagraph(String value)
      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

      public static org.docx4j.wml.R newRun(String value)
      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

      public static org.docx4j.wml.Text newText(String value)
      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

      public static org.docx4j.wml.Body newBody(List<Object> elements)
      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

      public static org.docx4j.wml.P newParagraph(String... texts)
      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

      public 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.
      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.
    • 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.
    • 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 null
      abstractImage - the binary part abstract image to be included in the run
      filenameHint - the filename hint for the image
      altText - 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)
    • newCommentRangeEnd

      public static org.docx4j.wml.CommentRangeEnd newCommentRangeEnd(BigInteger id, org.docx4j.wml.P parent)
    • newCommentReference

      public static org.docx4j.wml.R.CommentReference newCommentReference(BigInteger id, org.docx4j.wml.P parent)