Package org.docx4j
Class TraversalUtil
java.lang.Object
org.docx4j.TraversalUtil
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 ClassesModifier and TypeClassDescriptionstatic interfacestatic class -
Constructor Summary
ConstructorsConstructorDescriptionTraversalUtil(Object parent, TraversalUtil.Callback cb) Traverse the object using your callback. -
Method Summary
Modifier and TypeMethodDescriptionGet the children of some docx content object (as opposed to pptx, xlsx content).static voidreplaceChildren(Object o, List<Object> newChildren) static voidvisit(Object parent, 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 voidvisit(Object parent, TraversalUtil.Callback callback) static voidvisit(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 voidvisit(WordprocessingMLPackage wmlPackage, boolean bodyOnly, 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 voidvisit(WordprocessingMLPackage wmlPackage, boolean bodyOnly, TraversalUtil.Callback callback) static voidvisit(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.
-
Constructor Details
-
TraversalUtil
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
Get the children of some docx content object (as opposed to pptx, xlsx content).- Parameters:
o-- Returns:
-
replaceChildren
-
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
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, 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
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
-
visit
public static void visit(WordprocessingMLPackage wmlPackage, boolean bodyOnly, TraversalUtil.Callback callback)
-