Package org.docx4j

Class TraversalUtil

java.lang.Object
org.docx4j.TraversalUtil

public class TraversalUtil
extends java.lang.Object
Traverse a list of JAXB objects (eg document.xml's document/body children), and do something to them. This is similar to what one could do via XSLT, but avoids marshalling/unmarshalling. The downside is that not everything will necessarily get traversed here since visitChildren is not (yet) comprehensive. This utility might be redundant if we used http://code.google.com/p/jaxb-visitor/ or https://github.com/ops4j/org.ops4j.xvisitor at XJC time. Haven't tried them though. See also org.docx4j.utils.SingleTraversalUtilVisitorCallback and CompoundTraversalUtilVisitorCallback
Author:
jharrop, alberto
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static interface  TraversalUtil.Callback  
    static class  TraversalUtil.CallbackImpl  
  • Constructor Summary

    Constructors 
    Constructor Description
    TraversalUtil​(java.lang.Object parent, TraversalUtil.Callback cb)
    Traverse the object using your callback.
  • Method Summary

    Modifier and Type Method Description
    static java.util.List<java.lang.Object> getChildrenImpl​(java.lang.Object o)
    Get the children of some docx content object (as opposed to pptx, xlsx content).
    static void replaceChildren​(java.lang.Object o, java.util.List<java.lang.Object> newChildren)  
    static void visit​(java.lang.Object parent, java.util.List<TraversalUtilVisitor> visitorList)
    Use this if there is more than one object type (eg Tables and Paragraphs) you are interested in doing something with during the traversal.
    static void visit​(java.lang.Object parent, TraversalUtil.Callback callback)  
    static void visit​(java.lang.Object parent, TraversalUtilVisitor visitor)
    Use this if there is only a single object type (eg just P's) you are interested in doing something with.
    static void visit​(WordprocessingMLPackage wmlPackage, boolean bodyOnly, java.util.List<TraversalUtilVisitor> visitorList)
    Use this if there is more than one object type (eg Tables and Paragraphs) you are interested in doing something with during the traversal.
    static void visit​(WordprocessingMLPackage wmlPackage, boolean bodyOnly, TraversalUtil.Callback callback)  
    static void visit​(WordprocessingMLPackage wmlPackage, boolean bodyOnly, TraversalUtilVisitor visitor)
    Use this if there is only a single object type (eg just P's) you are interested in doing something with.

    Methods inherited from class java.lang.Object

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

    • TraversalUtil

      public TraversalUtil​(java.lang.Object parent, TraversalUtil.Callback cb)
      Traverse the object using your callback. Invoking this constructor starts the traverse, by invoking the callback's walkJAXBElements method.
      Parameters:
      parent -
      cb -
  • Method Details

    • getChildrenImpl

      public static java.util.List<java.lang.Object> getChildrenImpl​(java.lang.Object o)
      Get the children of some docx content object (as opposed to pptx, xlsx content).
      Parameters:
      o -
      Returns:
    • replaceChildren

      public static void replaceChildren​(java.lang.Object o, java.util.List<java.lang.Object> newChildren)
    • visit

      public static void visit​(WordprocessingMLPackage wmlPackage, boolean bodyOnly, TraversalUtilVisitor visitor)
      Use this if there is only a single object type (eg just P's) you are interested in doing something with. This method allows you to traverse just the main document part, or also headers/footers, footnotes/endnotes, and comments as well.
      Parameters:
      wmlPackage -
      bodyOnly -
      visitor -
    • visit

      public static void visit​(java.lang.Object parent, TraversalUtilVisitor visitor)
      Use this if there is only a single object type (eg just P's) you are interested in doing something with. This method is for traversing an arbitrary WML object (eg a table), as opposed to eg the main document part, or a header.
      Parameters:
      parent -
      visitor -
    • visit

      public static void visit​(WordprocessingMLPackage wmlPackage, boolean bodyOnly, java.util.List<TraversalUtilVisitor> visitorList)
      Use this if there is more than one object type (eg Tables and Paragraphs) you are interested in doing something with during the traversal. This method allows you to traverse just the main document part, or also headers/footers, footnotes/endnotes, and comments as well.
      Parameters:
      wmlPackage -
      bodyOnly -
      visitorList -
    • visit

      public static void visit​(java.lang.Object parent, java.util.List<TraversalUtilVisitor> visitorList)
      Use this if there is more than one object type (eg Tables and Paragraphs) you are interested in doing something with during the traversal. This method is for traversing an arbitrary WML object (eg a table), as opposed to eg the main document part, or a header.
      Parameters:
      parent -
      visitorList -
    • visit

      public static void visit​(java.lang.Object parent, TraversalUtil.Callback callback)
    • visit

      public static void visit​(WordprocessingMLPackage wmlPackage, boolean bodyOnly, TraversalUtil.Callback callback)