Class XPathAwareCloner

java.lang.Object
org.docx4j.utils.XPathAwareCloner

public class XPathAwareCloner
extends java.lang.Object
Some users wish to be able to use an XPath on the result of cloning a JAXB object. This variant on XmlUtils.deepCopy allows that. Note that if you use this object's deepCopy method more than once, the results returned by getJAXBNodesViaXPath will only be on your last deepCopy.
  • Constructor Summary

    Constructors 
    Constructor Description
    XPathAwareCloner()  
  • Method Summary

    Modifier and Type Method Description
    java.lang.Object deepCopy​(java.lang.Object o)
    Clone this JAXB object, using default JAXBContext.
    java.lang.Object deepCopy​(java.lang.Object o, javax.xml.bind.JAXBContext jc)
    Clone this JAXB object
    javax.xml.bind.Binder<org.w3c.dom.Node> getBinder()
    Enables synchronization between XML infoset nodes and JAXB objects representing same XML document.
    java.util.List<java.lang.Object> getJAXBNodesViaXPath​(java.lang.String xpathExpr, boolean refreshXmlFirst)
    Fetch JAXB Nodes matching an XPath (for example "//w:p").
    static void main​(java.lang.String[] args)  

    Methods inherited from class java.lang.Object

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

  • Method Details

    • deepCopy

      public java.lang.Object deepCopy​(java.lang.Object o)
      Clone this JAXB object, using default JAXBContext.
    • deepCopy

      public java.lang.Object deepCopy​(java.lang.Object o, javax.xml.bind.JAXBContext jc)
      Clone this JAXB object
      Parameters:
      value -
      jc -
      Returns:
    • getBinder

      public javax.xml.bind.Binder<org.w3c.dom.Node> getBinder()
      Enables synchronization between XML infoset nodes and JAXB objects representing same XML document. An instance of this class maintains the association between XML nodes of an infoset preserving view and a JAXB representation of an XML document. Navigation between the two views is provided by the methods getXMLNode(Object) and getJAXBNode(Object) . In theory, modifications can be made to either the infoset preserving view or the JAXB representation of the document while the other view remains unmodified. The binder ought to be able to synchronize the changes made in the modified view back into the other view using the appropriate Binder update methods, #updateXML(Object, Object) or #updateJAXB(Object). But JAXB doesn't currently work as advertised .. access to this object is offered for advanced users on an experimental basis only.
    • getJAXBNodesViaXPath

      public java.util.List<java.lang.Object> getJAXBNodesViaXPath​(java.lang.String xpathExpr, boolean refreshXmlFirst) throws javax.xml.bind.JAXBException, XPathBinderAssociationIsPartialException
      Fetch JAXB Nodes matching an XPath (for example "//w:p"). If you have modified your JAXB objects (eg added or changed a w:p paragraph), you need to update the association. The problem is that this can only be done ONCE, owing to a bug in JAXB: see https://jaxb.dev.java.net/issues/show_bug.cgi?id=459 So this is left for you to choose to do via the refreshXmlFirst parameter.
      Parameters:
      xpathExpr -
      refreshXmlFirst -
      Returns:
      Throws:
      javax.xml.bind.JAXBException
      XPathBinderAssociationIsPartialException
    • main

      public static void main​(java.lang.String[] args) throws javax.xml.bind.JAXBException, XPathBinderAssociationIsPartialException
      Parameters:
      args -
      Throws:
      javax.xml.bind.JAXBException
      XPathBinderAssociationIsPartialException