Class ObjectPath

java.lang.Object
com.itextpdf.kernel.utils.objectpathitems.ObjectPath
Direct Known Subclasses:
TrailerPath

public class ObjectPath extends Object
Class that helps to find two corresponding objects in the compared documents and also keeps track of the already met during comparing process parent indirect objects.

You could say that CompareObjectPath instance consists of two parts: direct path and indirect path. Direct path defines path to the currently comparing objects in relation to base objects. It could be empty, which would mean that currently comparing objects are base objects themselves. Base objects are the two indirect objects from the comparing documents which are in the same position in the pdf trees. Another part, indirect path, defines which indirect objects were met during comparison process to get to the current base objects. Indirect path is needed to avoid infinite loops during comparison.

  • Field Details

  • Constructor Details

    • ObjectPath

      public ObjectPath()
      Creates empty ObjectPath.
    • ObjectPath

      public ObjectPath (ObjectPath objectPath)
      Creates an ObjectPath object from another ObjectPath object, passed as argument.
      Parameters:
      objectPath - an ObjectPath object to create from.
    • ObjectPath

      public ObjectPath (PdfIndirectReference baseCmpObject, PdfIndirectReference baseOutObject)
      Creates CompareObjectPath with corresponding base objects in two documents.
      Parameters:
      baseCmpObject - base object in cmp document.
      baseOutObject - base object in out document.
    • ObjectPath

      public ObjectPath (PdfIndirectReference baseCmpObject, PdfIndirectReference baseOutObject, Stack<LocalPathItem> path, Stack<IndirectPathItem> indirects)
      Creates CompareObjectPath with corresponding base objects in two documents.
      Parameters:
      baseCmpObject - base object in cmp document
      baseOutObject - base object in out document
      path - local path that denotes sequence of the path items from base object to the comparing direct object
      indirects - indirect path which denotes sequence of the indirect references that were passed in comparing process to get to the current base objects
  • Method Details

    • resetDirectPath

      public ObjectPath resetDirectPath (PdfIndirectReference baseCmpObject, PdfIndirectReference baseOutObject)
      Creates a new ObjectPath instance with two new given base objects, which are supposed to be nested in the base objects of the current instance of the ObjectPath. This method is used to avoid infinite loop in case of circular references in pdf documents objects structure.

      Basically, this method creates copy of the current CompareObjectPath instance, but resets information of the direct paths, and also adds current CompareObjectPath instance base objects to the indirect references chain that denotes a path to the new base objects.

      Parameters:
      baseCmpObject - new base object in cmp document.
      baseOutObject - new base object in out document.
      Returns:
      new ObjectPath instance, which stores chain of the indirect references which were already met to get to the new base objects.
    • isComparing

      public boolean isComparing (PdfIndirectReference cmpObject, PdfIndirectReference outObject)
      This method is used to define if given objects were already met in the path to the current base objects. If this method returns true it basically means that we found a loop in the objects structure and that we already compared these objects.
      Parameters:
      cmpObject - cmp object to check if it was already met in base objects path.
      outObject - out object to check if it was already met in base objects path.
      Returns:
      true if given objects are contained in the path and therefore were already compared.
    • pushArrayItemToPath

      public void pushArrayItemToPath (int index)
      Adds array item to the direct path. See ArrayPathItem.
      Parameters:
      index - index in the array of the direct object to be compared.
    • pushDictItemToPath

      public void pushDictItemToPath (PdfName key)
      Adds dictionary item to the direct path. See DictPathItem.
      Parameters:
      key - key in the dictionary to which corresponds direct object to be compared.
    • pushOffsetToPath

      public void pushOffsetToPath (int offset)
      Adds offset item to the direct path. See OffsetPathItem.
      Parameters:
      offset - offset to the specific byte in the stream that is compared.
    • pop

      public void pop()
      Removes the last path item from the direct path.
    • getLocalPath

      public Stack<LocalPathItem> getLocalPath()
      Gets local (or direct) path that denotes sequence of the path items from base object to the comparing direct object.
      Returns:
      direct path to the comparing object.
    • getIndirectPath

      public Stack<IndirectPathItem> getIndirectPath()
      Gets indirect path which denotes sequence of the indirect references that were passed in comparing process to get to the current base objects.
      Returns:
      indirect path to the current base objects.
    • getBaseCmpObject

      public PdfIndirectReference getBaseCmpObject()
      Method returns current base PdfIndirectReference object in the cmp document.
      Returns:
      current base PdfIndirectReference object in the cmp document.
    • getBaseOutObject

      public PdfIndirectReference getBaseOutObject()
      Method returns current base PdfIndirectReference object in the out document.
      Returns:
      current base object in the out document.
    • toXmlNode

      public Node toXmlNode (Document document)
      Creates an xml node that describes a direct path stored in this ObjectPath instance.
      Parameters:
      document - xml document, to which this xml node will be added.
      Returns:
      an xml node describing direct path.
    • toString

      public String toString()
      Method returns a string representation of the direct path stored in this ObjectPath instance.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the direct path.
    • hashCode

      public int hashCode()
      Method returns a hash code of this ObjectPath instance.
      Overrides:
      hashCode in class Object
      Returns:
      a int hash code of this ObjectPath instance.
    • equals

      public boolean equals (Object obj)
      Method returns true if this ObjectPath instance equals to the passed object.
      Overrides:
      equals in class Object
      Returns:
      true - if this ObjectPath instance equals to the passed object.