Class DocumentUtil

java.lang.Object
org.wickedsource.docxstamper.util.DocumentUtil

public class DocumentUtil extends Object
Utility class to retrieve elements from a document.
Version:
${version}
Author:
Joseph Verron
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<Object>
    allElements(org.docx4j.openpackaging.packages.WordprocessingMLPackage subDocument)
    Retrieve the last element from an object.
    static List<org.docx4j.wml.P>
    Retrieve all the paragraphs from a document
    static List<org.docx4j.wml.Tc>
    Retrieve all the cells from an object.
    static List<org.docx4j.wml.Tbl>
    getTableFromObject(Object parentObject)
    Retrieve all the tables from an object.
    static List<org.docx4j.wml.Tr>
    Retrieve all the rows from an object.
    static Object
    lastElement(org.docx4j.openpackaging.packages.WordprocessingMLPackage subDocument)
    Retrieve the first element from an object.
    static <T> Stream<T>
    streamElements(Object object, Class<T> elementClass)
    Retrieve all the elements of a given class from an object.
    static Stream<org.docx4j.wml.P>
    streamParagraphs(org.docx4j.openpackaging.packages.WordprocessingMLPackage document)
    Retrieve all the runs from a document.
    static Map<org.docx4j.wml.R,org.docx4j.wml.R>
    walkObjectsAndImportImages(org.docx4j.openpackaging.packages.WordprocessingMLPackage source, org.docx4j.openpackaging.packages.WordprocessingMLPackage target)
    Recursively walk through source to find embedded images and import them in the target document.
    static Map<org.docx4j.wml.R,org.docx4j.wml.R>
    walkObjectsAndImportImages(org.docx4j.wml.ContentAccessor container, org.docx4j.openpackaging.packages.WordprocessingMLPackage source, org.docx4j.openpackaging.packages.WordprocessingMLPackage target)
    Recursively walk through source accessor to find embedded images and import the target document.

    Methods inherited from class java.lang.Object

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

    • getParagraphsFromObject

      public static List<org.docx4j.wml.P> getParagraphsFromObject(Object parentObject)
      Retrieve all the paragraphs from a document
      Parameters:
      parentObject - the document to get the paragraphs from
      Returns:
      a list of paragraphs
    • streamElements

      public static <T> Stream<T> streamElements(Object object, Class<T> elementClass)
      Retrieve all the elements of a given class from an object.
      Type Parameters:
      T - the type of the elements to get
      Parameters:
      object - the object to get the elements from
      elementClass - the class of the elements to get
      Returns:
      a stream of the elements
    • getTableFromObject

      public static List<org.docx4j.wml.Tbl> getTableFromObject(Object parentObject)
      Retrieve all the tables from an object.
      Parameters:
      parentObject - the object to get the tables from
      Returns:
      a list of tables
    • getTableRowsFromObject

      public static List<org.docx4j.wml.Tr> getTableRowsFromObject(Object parentObject)
      Retrieve all the rows from an object.
      Parameters:
      parentObject - the object to get the rows from
      Returns:
      a list of rows
    • getTableCellsFromObject

      public static List<org.docx4j.wml.Tc> getTableCellsFromObject(Object parentObject)
      Retrieve all the cells from an object.
      Parameters:
      parentObject - the object to get the cells from
      Returns:
      a list of cells
    • lastElement

      public static Object lastElement(org.docx4j.openpackaging.packages.WordprocessingMLPackage subDocument)
      Retrieve the first element from an object.
      Parameters:
      subDocument - the object to get the first element from
      Returns:
      the first element
    • allElements

      public static List<Object> allElements(org.docx4j.openpackaging.packages.WordprocessingMLPackage subDocument)
      Retrieve the last element from an object.
      Parameters:
      subDocument - the object to get the last element from
      Returns:
      the last element
    • walkObjectsAndImportImages

      public static Map<org.docx4j.wml.R,org.docx4j.wml.R> walkObjectsAndImportImages(org.docx4j.openpackaging.packages.WordprocessingMLPackage source, org.docx4j.openpackaging.packages.WordprocessingMLPackage target)
      Recursively walk through source to find embedded images and import them in the target document.
      Parameters:
      source - source document containing image files.
      target - target document to add image files to.
      Returns:
      a Map object
    • walkObjectsAndImportImages

      public static Map<org.docx4j.wml.R,org.docx4j.wml.R> walkObjectsAndImportImages(org.docx4j.wml.ContentAccessor container, org.docx4j.openpackaging.packages.WordprocessingMLPackage source, org.docx4j.openpackaging.packages.WordprocessingMLPackage target)
      Recursively walk through source accessor to find embedded images and import the target document.
      Parameters:
      container - source container to walk.
      source - source document containing image files.
      target - target document to add image files to.
      Returns:
      a Map object
    • streamParagraphs

      public static Stream<org.docx4j.wml.P> streamParagraphs(org.docx4j.openpackaging.packages.WordprocessingMLPackage document)
      Retrieve all the runs from a document.
      Parameters:
      document - the document to get the runs from
      Returns:
      the runs