Class DOMTreeResolver

  • All Implemented Interfaces:
    TreeResolver

    public class DOMTreeResolver
    extends java.lang.Object
    implements TreeResolver
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<org.w3c.dom.Node,​java.util.Map<org.w3c.dom.Node,​java.lang.Integer>> cachedPositions
      We cache element positions for nth-child, odd and even condition matchers.
    • Constructor Summary

      Constructors 
      Constructor Description
      DOMTreeResolver()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getElementName​(java.lang.Object element)
      returns the name of the element so that it may match against the selectors
      java.lang.Object getParentElement​(java.lang.Object element)
      returns the parent element of an element, or null if this was the root element
      int getPositionOfElement​(java.lang.Object element)
      Returns the index of the position of the submitted element among its element node siblings.
      java.lang.Object getPreviousSiblingElement​(java.lang.Object element)
      The previous sibling element, or null if none exists
      boolean isFirstChildElement​(java.lang.Object element)
      returns true if this element is the first child element of its parent
      boolean isLastChildElement​(java.lang.Object element)
      returns true if this element is the last child element of its parent
      boolean matchesElement​(java.lang.Object element, java.lang.String namespaceURI, java.lang.String name)
      Returns true if element has the local name name and namespace URI namespaceURI.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • cachedPositions

        private final java.util.Map<org.w3c.dom.Node,​java.util.Map<org.w3c.dom.Node,​java.lang.Integer>> cachedPositions
        We cache element positions for nth-child, odd and even condition matchers. To avoid scaling with the square of the number of children elements.
    • Constructor Detail

      • DOMTreeResolver

        public DOMTreeResolver()
    • Method Detail

      • getParentElement

        public java.lang.Object getParentElement​(java.lang.Object element)
        Description copied from interface: TreeResolver
        returns the parent element of an element, or null if this was the root element
        Specified by:
        getParentElement in interface TreeResolver
      • getPreviousSiblingElement

        public java.lang.Object getPreviousSiblingElement​(java.lang.Object element)
        Description copied from interface: TreeResolver
        The previous sibling element, or null if none exists
        Specified by:
        getPreviousSiblingElement in interface TreeResolver
      • getElementName

        public java.lang.String getElementName​(java.lang.Object element)
        Description copied from interface: TreeResolver
        returns the name of the element so that it may match against the selectors
        Specified by:
        getElementName in interface TreeResolver
      • isFirstChildElement

        public boolean isFirstChildElement​(java.lang.Object element)
        Description copied from interface: TreeResolver
        returns true if this element is the first child element of its parent
        Specified by:
        isFirstChildElement in interface TreeResolver
      • isLastChildElement

        public boolean isLastChildElement​(java.lang.Object element)
        Description copied from interface: TreeResolver
        returns true if this element is the last child element of its parent
        Specified by:
        isLastChildElement in interface TreeResolver
      • matchesElement

        public boolean matchesElement​(java.lang.Object element,
                                      java.lang.String namespaceURI,
                                      java.lang.String name)
        Description copied from interface: TreeResolver
        Returns true if element has the local name name and namespace URI namespaceURI.
        Specified by:
        matchesElement in interface TreeResolver
        namespaceURI - The namespace to match, may be null to signify any namespace. Use TreeResolver.NO_NAMESPACE to signify that name should only match when there is no namespace defined on element.
        name - The name to match, may not be null
      • getPositionOfElement

        public int getPositionOfElement​(java.lang.Object element)
        Description copied from interface: TreeResolver
        Returns the index of the position of the submitted element among its element node siblings.
        Specified by:
        getPositionOfElement in interface TreeResolver
        Returns:
        -1 in case of error, 0 indexed position otherwise