Class DocumentUtil

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

public class DocumentUtil extends Object
Utility class to retrieve elements from a document.
Since:
1.4.7
Version:
${version}
Author:
Joseph Verron, DallanMC
  • 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 boolean
    depthElementSearch(Object searchTarget, Object content)
    Recursively searches for an element in a content tree.
    static org.docx4j.wml.ContentAccessor
    Finds the smallest common parent between two objects.
    static List<org.docx4j.wml.P>
    Deprecated, for removal: This API element is subject to removal in a future version.
    method not used internally so will be removed
    static List<org.docx4j.wml.Tc>
    Deprecated, for removal: This API element is subject to removal in a future version.
    method not used internally so will be removed
    static List<org.docx4j.wml.Tbl>
    getTableFromObject(Object parentObject)
    Deprecated, for removal: This API element is subject to removal in a future version.
    method not used internally so will be removed
    static List<org.docx4j.wml.Tr>
    Deprecated, for removal: This API element is subject to removal in a future version.
    method not used internally so will be removed
    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 a 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

      @Deprecated(since="1.6.8", forRemoval=true) public static List<org.docx4j.wml.P> getParagraphsFromObject(Object parentObject)
      Deprecated, for removal: This API element is subject to removal in a future version.
      method not used internally so will be removed
      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

      @Deprecated(since="1.6.8", forRemoval=true) public static List<org.docx4j.wml.Tbl> getTableFromObject(Object parentObject)
      Deprecated, for removal: This API element is subject to removal in a future version.
      method not used internally so will be removed
      Retrieve all the tables from an object.
      Parameters:
      parentObject - the object to get the tables from
      Returns:
      a list of tables
    • getTableRowsFromObject

      @Deprecated(since="1.6.8", forRemoval=true) public static List<org.docx4j.wml.Tr> getTableRowsFromObject(Object parentObject)
      Deprecated, for removal: This API element is subject to removal in a future version.
      method not used internally so will be removed
      Retrieve all the rows from an object.
      Parameters:
      parentObject - the object to get the rows from
      Returns:
      a list of rows
    • getTableCellsFromObject

      @Deprecated(since="1.6.8", forRemoval=true) public static List<org.docx4j.wml.Tc> getTableCellsFromObject(Object parentObject)
      Deprecated, for removal: This API element is subject to removal in a future version.
      method not used internally so will be removed
      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 a 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
    • findSmallestCommonParent

      public static org.docx4j.wml.ContentAccessor findSmallestCommonParent(Object o1, Object o2)
      Finds the smallest common parent between two objects.
      Parameters:
      o1 - the first object
      o2 - the second object
      Returns:
      the smallest common parent of the two objects
      Throws:
      OfficeStamperException - if there is an error finding the common parent
    • depthElementSearch

      public static boolean depthElementSearch(Object searchTarget, Object content)
      Recursively searches for an element in a content tree.
      Parameters:
      searchTarget - the element to search for
      content - the content tree to search in
      Returns:
      true if the element is found, false otherwise