Class HTMLDocument

java.lang.Object
io.sf.carte.doc.dom.DOMDocument
io.sf.carte.doc.dom.HTMLDocument
All Implemented Interfaces:
DOMNode, NonDocumentTypeChildNode, ParentNode, CSSDocument, CSSNode, DocumentCSS, Document, Node, DocumentStyle

public abstract class HTMLDocument extends DOMDocument

HTML Document.

  • Field Details

  • Constructor Details

    • HTMLDocument

      public HTMLDocument(DocumentType documentType)
  • Method Details

    • getDocumentElement

      public HTMLElement getDocumentElement()
      Description copied from class: DOMDocument
      Get the child node which is the document element of this document.
      Specified by:
      getDocumentElement in interface CSSDocument
      Specified by:
      getDocumentElement in interface Document
      Overrides:
      getDocumentElement in class DOMDocument
      Returns:
      the document element.
    • getOwnerDocument

      public HTMLDocument getOwnerDocument()
      Description copied from class: DOMDocument
      Get the DOMDocument object related to this node (for all nodes except DocumentType, it is the document that created it), which is also the object that should be used to create new nodes for the document.
      Specified by:
      getOwnerDocument in interface CSSNode
      Specified by:
      getOwnerDocument in interface DOMNode
      Specified by:
      getOwnerDocument in interface Node
      Overrides:
      getOwnerDocument in class DOMDocument
      Returns:
      the DOMDocument object corresponding to this node. When this node is a DOMDocument or a DocumentType which was not added to any DOMDocument yet, this is null.
    • cloneNode

      public HTMLDocument cloneNode(boolean deep)
      Description copied from class: DOMDocument
      Specified by:
      cloneNode in interface Node
      Overrides:
      cloneNode in class DOMDocument
    • createElement

      public DOMElement createElement(String tagName) throws DOMException
      Description copied from class: DOMDocument
      Creates an element of the type specified, with a null namespace URI.

      The tagName is transformed to lower case.

      No default attributes are created.

      Specified by:
      createElement in interface CSSDocument
      Specified by:
      createElement in interface Document
      Overrides:
      createElement in class DOMDocument
      Parameters:
      tagName - the tag name of the element to create.
      Returns:
      the new DOMElement.
      Throws:
      DOMException - INVALID_CHARACTER_ERR if the name is not an XML valid name.
    • createElementNS

      public DOMElement createElementNS(String namespaceURI, String qualifiedName) throws DOMException
      Description copied from class: DOMDocument
      Creates an element with the given qualified name and namespace URI.

      If namespaceURI is null or the empty string, the qualifiedName is transformed to lower case.

      No default attributes are created.

      Specified by:
      createElementNS in interface CSSDocument
      Specified by:
      createElementNS in interface Document
      Overrides:
      createElementNS in class DOMDocument
      Parameters:
      namespaceURI - the namespace URI of the element to create.
      qualifiedName - the qualified name of the element to create. The namespace prefix, if any, is extracted from this name.
      Returns:
      the new DOMElement.
      Throws:
      DOMException - INVALID_CHARACTER_ERR if the name is not an XML valid name.
      NAMESPACE_ERR: if the qualifiedName is a malformed qualified name, if the qualifiedName has a prefix and the namespaceURI is null, or if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace" , or if the qualifiedName or its prefix is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/", or if the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the qualifiedName nor its prefix is "xmlns".
    • createAttributeNS

      public Attr createAttributeNS(String namespaceURI, String qualifiedName) throws DOMException
      Description copied from class: DOMDocument
      Specified by:
      createAttributeNS in interface Document
      Overrides:
      createAttributeNS in class DOMDocument
      Throws:
      DOMException
    • getBaseURL

      public URL getBaseURL()
      Gets the base URL of this Document.

      If the Document's head element has a base child element, the base URI is computed using the value of the href attribute of the base element.

      Specified by:
      getBaseURL in interface CSSDocument
      Overrides:
      getBaseURL in class DOMDocument
      Returns:
      the base URL, or null if no base URL could be found.
    • getBaseURI

      public String getBaseURI()
      Gets the absolute base URI of this node.
      Specified by:
      getBaseURI in interface Node
      Overrides:
      getBaseURI in class DOMDocument
      Returns:
      the absolute base URI of this node, or null if an absolute URI could not be obtained.
    • setDocumentURI

      public void setDocumentURI(String documentURI)
      Description copied from class: DOMDocument
      Sets the location of this document.

      For security reasons, if you want to retrieve linked style sheets from local URLs (like file:), you need to set the documentURI to a local scheme (file: or jar:) as well.

      No lexical checking is performed when setting this attribute; this could result in a null value returned when using DOMDocument.getBaseURI().

      Specified by:
      setDocumentURI in interface Document
      Overrides:
      setDocumentURI in class DOMDocument
      Parameters:
      documentURI - the document URI.
    • isDefaultNamespace

      public boolean isDefaultNamespace(String namespaceURI)
      Specified by:
      isDefaultNamespace in interface Node
      Overrides:
      isDefaultNamespace in class DOMDocument
    • getChildren

      public ElementList getChildren()
      Gets the live ElementList containing all nodes of type Element that are children of this Element.
      Specified by:
      getChildren in interface ParentNode
      Returns:
      the ElementList containing all nodes of type Element that are children of this Element.
    • querySelectorAll

      public ElementList querySelectorAll(String selectors)
      Gets a static list of the elements that match any of the specified group of selectors.

      Unlike methods like ParentNode.getElementsByTagName(String) or ParentNode.getElementsByClassName(String), this is not a live list but a static one, representing the state of the document when the method was called. If no elements match, the list will be empty.

      Specified by:
      querySelectorAll in interface ParentNode
      Parameters:
      selectors - a comma-separated list of selectors.
      Returns:
      an ElementList with the elements that match any of the specified group of selectors.
    • iterator

      public Iterator<DOMNode> iterator()
      Creates a new iterator over the child nodes.
      Specified by:
      iterator in interface ParentNode
      Returns:
      an iterator over the child nodes.
    • descendingIterator

      public Iterator<DOMNode> descendingIterator()
      Creates a new iterator descending over the child nodes, starting from the last child node.
      Specified by:
      descendingIterator in interface ParentNode
      Returns:
      an iterator descending over the child nodes.
    • iterator

      public Iterator<DOMNode> iterator(BitSet whatToShow)
      Creates a new iterator over the child nodes.

      It only iterates over types set in the whatToShow bit field.

      Example:

            BitSet mask = new BitSet(32);
            mask.set(Node.ELEMENT_NODE);
            Iterator it = node.iterator(mask);
       
      Specified by:
      iterator in interface ParentNode
      Parameters:
      whatToShow - a bit set.
      Returns:
      an iterator over the child nodes.
    • elementIterator

      public Iterator<DOMElement> elementIterator()
      Creates a new iterator over the child elements.
      Specified by:
      elementIterator in interface ParentNode
      Returns:
      an iterator over the child elements.
    • elementIterator

      public Iterator<DOMElement> elementIterator(String tagname)
      Creates a new iterator over the child elements of the given tagname.
      Specified by:
      elementIterator in interface ParentNode
      Parameters:
      tagname - The tag name of the child elements to match on.
      Returns:
      an iterator over the child elements.
    • elementIteratorNS

      public Iterator<DOMElement> elementIteratorNS(String namespaceURI, String localName)
      Creates a new iterator over the child elements of the given namespaceURI and localName.
      Specified by:
      elementIteratorNS in interface ParentNode
      Parameters:
      namespaceURI - the namespace URI of the elements to match on.
      localName - The local name of the elements to match on.
      Returns:
      an iterator over the child elements.
    • iterator

      public Iterator<DOMNode> iterator(int whatToShow, NodeFilter filter)
      Creates a new iterator over the child nodes.

      It only iterates over types set in the whatToShow mask that satisfy the custom NodeFilter.

      Example:

       Iterator it = node.iterator(NodeFilter.SHOW_ELEMENT, null);
       
      Specified by:
      iterator in interface ParentNode
      Parameters:
      whatToShow - the bit field mask to apply to the node types, see NodeFilter. Do not confuse this argument with the short argument of the ParentNode.typeIterator(short) method.
      filter - the filter to use in the iteration. if null, only the whatToShow mask filter is applied.
      Returns:
      an iterator over the child nodes.
    • typeIterator

      public Iterator<DOMNode> typeIterator(short typeToShow)
      Creates a new iterator over the child nodes.

      Do not confuse the typeToShow argument with the int argument of the ParentNode.iterator(int, NodeFilter) method, which is a bit field.

      Specified by:
      typeIterator in interface ParentNode
      Parameters:
      typeToShow - the node type to show (from Node.getNodeType()).
      Returns:
      an iterator over the child nodes.
    • iterator

      public Iterator<DOMNode> iterator(NodeFilter filter)
      Creates a new iterator over the child nodes.

      It only iterates over nodes accepted by the filter.

      Specified by:
      iterator in interface ParentNode
      Parameters:
      filter - a filter, see NodeFilter.
      Returns:
      an iterator over the child nodes.
    • listIterator

      public NodeListIterator listIterator()
      Creates a new list iterator over the child nodes.
      Specified by:
      listIterator in interface ParentNode
      Returns:
      a list iterator over the child nodes.
    • getElementsByTagNameNS

      public ElementList getElementsByTagNameNS(String namespaceURI, String localName)
      Gives an ElementList of all the elements descending from this context node that have the given local name and namespace URI, in document order.

      The list is a live collection, and changes to the document made after calling this method are reflected in the ElementList.

      The most efficient way to browse the returned list is to iterate it.

      Specified by:
      getElementsByTagNameNS in interface ParentNode
      Parameters:
      namespaceURI - the namespace URI of the elements to match on. The special value "*" matches all namespaces.
      localName - The local name of the elements to match on. The special value "*" matches all local names.
      Returns:
      the ElementList object containing all the matched elements.
    • getElementsByTagName

      public ElementList getElementsByTagName(String name)
      Gives an ElementList of all the elements descending from this context node that have the given tag name, in document order.

      The list is a live collection, and changes to the document made after calling this method are reflected in the ElementList.

      The most efficient way to browse the returned list is to iterate it.

      Specified by:
      getElementsByTagName in interface ParentNode
      Parameters:
      name - The tag name of the elements to match on. The special value "*" matches all tag names.
      Returns:
      the ElementList object containing all the matched elements.
    • getFirstElementChild

      public DOMElement getFirstElementChild()
      Gets the Element that is the first child of this ParentNode.
      Returns:
      the Element that is the first child of this ParentNode, or null if there is none.
    • getLastElementChild

      public DOMElement getLastElementChild()
      Gets the DOMElement that is the last child of this ParentNode.
      Returns:
      the DOMElement that is the last child of this ParentNode, or null if there is none.
    • getChildElementCount

      public int getChildElementCount()
      Gets the number of child nodes of type Element that this parent node has.
      Returns:
      the number of child nodes of type Element that this ParentNode has.
    • hasChildNodes

      public boolean hasChildNodes()
      Description copied from interface: DOMNode
      Does this node have any child nodes ?
      Specified by:
      hasChildNodes in interface DOMNode
      Specified by:
      hasChildNodes in interface Node
      Returns:
      true if this node has child nodes, false otherwise.
    • getPreviousElementSibling

      public DOMElement getPreviousElementSibling()
      Description copied from interface: NonDocumentTypeChildNode
      Gets the first preceding sibling that is an element.
      Specified by:
      getPreviousElementSibling in interface NonDocumentTypeChildNode
      Returns:
      the first preceding sibling that is an element, and null otherwise.
    • getNextElementSibling

      public DOMElement getNextElementSibling()
      Description copied from interface: NonDocumentTypeChildNode
      Gets the first following sibling that is an element.
      Specified by:
      getNextElementSibling in interface NonDocumentTypeChildNode
      Returns:
      the first following sibling that is an element, and null otherwise.
    • prependChild

      public DOMNode prependChild(Node newChild) throws DOMException
      Throws:
      DOMException
    • getNodeValue

      public String getNodeValue() throws DOMException
      Specified by:
      getNodeValue in interface Node
      Throws:
      DOMException
    • setNodeValue

      public void setNodeValue(String nodeValue) throws DOMException
      Specified by:
      setNodeValue in interface Node
      Throws:
      DOMException
    • getNodeType

      public short getNodeType()
      Specified by:
      getNodeType in interface Node
    • getLocalName

      public String getLocalName()
      Gives the local part of the qualified name of this node. For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE, this is always null.
      Specified by:
      getLocalName in interface Node
      Returns:
      the local part of the qualified name of this node, or null if this node is not an ELEMENT_NODE nor an ATTRIBUTE_NODE.
    • getAttributes

      public NamedNodeMap getAttributes()
      Specified by:
      getAttributes in interface Node
    • hasAttributes

      public boolean hasAttributes()
      Specified by:
      hasAttributes in interface Node
    • getChildNodes

      public DOMNodeList getChildNodes()
      Description copied from interface: DOMNode
      Get the children of this node.
      Specified by:
      getChildNodes in interface DOMNode
      Specified by:
      getChildNodes in interface Node
      Returns:
      a DOMNodeList with the children of this node. If there are no children, an empty list is returned.
    • getFirstChild

      public DOMNode getFirstChild()
      Description copied from interface: DOMNode
      Get the first child of this node.
      Specified by:
      getFirstChild in interface DOMNode
      Specified by:
      getFirstChild in interface Node
      Returns:
      the first child of this node, null if has no child nodes.
    • getLastChild

      public DOMNode getLastChild()
      Description copied from interface: DOMNode
      Get the last child of this node.
      Specified by:
      getLastChild in interface DOMNode
      Specified by:
      getLastChild in interface Node
      Returns:
      the last child of this node, null if has no child nodes.
    • getPreviousSibling

      public DOMNode getPreviousSibling()
      Description copied from interface: DOMNode
      Get the node immediately preceding this node in its parent's child list.
      Specified by:
      getPreviousSibling in interface DOMNode
      Specified by:
      getPreviousSibling in interface Node
      Returns:
      the node immediately preceding this node in the child list, or null if none.
    • getNextSibling

      public DOMNode getNextSibling()
      Description copied from interface: DOMNode
      Get the node immediately following this node in its parent's child list.
      Specified by:
      getNextSibling in interface DOMNode
      Specified by:
      getNextSibling in interface Node
      Returns:
      the node immediately following this node in the child list, or null if none.
    • appendChild

      public DOMNode appendChild(Node newChild) throws DOMException
      Description copied from interface: DOMNode
      Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.
      Specified by:
      appendChild in interface DOMNode
      Specified by:
      appendChild in interface Node
      Parameters:
      newChild - the node to append. If it is a DocumentFragment object, the entire contents of the document fragment are moved into the child list of this node.
      Returns:
      the appended node.
      Throws:
      DOMException - HIERARCHY_REQUEST_ERR: raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to append is one of this node's ancestors or this node itself, or if this node is of type Document and the DOM application attempts to append a second DocumentType or Element node.
      WRONG_DOCUMENT_ERR: if newChild was created from a different document than the one that created this node.
      NOT_SUPPORTED_ERR: if this implementation does not support children of the type of newChild at this node.
    • removeChild

      public DOMNode removeChild(Node oldChild) throws DOMException
      Description copied from interface: DOMNode
      Removes the node oldChild from the children of this node.
      Specified by:
      removeChild in interface DOMNode
      Specified by:
      removeChild in interface Node
      Parameters:
      oldChild - the node to remove.
      Returns:
      the removed node.
      Throws:
      DOMException - NOT_FOUND_ERR: if oldChild is not a child of this node.
    • setUserData

      public Object setUserData(String key, Object data, UserDataHandler handler)
      Specified by:
      setUserData in interface Node
    • getUserData

      public Object getUserData(String key)
      Specified by:
      getUserData in interface Node
    • normalize

      public void normalize()
      Specified by:
      normalize in interface Node
    • getFeature

      @Deprecated public Object getFeature(String feature, String version)
      Deprecated.
      This method is deprecated and not supported.
      Specified by:
      getFeature in interface Node
      Parameters:
      feature - ignored.
      version - ignored.
      Returns:
      null.
    • isSupported

      @Deprecated public boolean isSupported(String feature, String version)
      Deprecated.
      This method is not supported.
      Specified by:
      isSupported in interface Node
      Parameters:
      feature - ignored.
      version - ignored.
      Returns:
      Always true.
    • compareDocumentPosition

      public short compareDocumentPosition(Node other) throws DOMException
      Specified by:
      compareDocumentPosition in interface Node
      Throws:
      DOMException
    • getTextContent

      public String getTextContent() throws DOMException
      Specified by:
      getTextContent in interface Node
      Throws:
      DOMException
    • setTextContent

      public void setTextContent(String textContent) throws DOMException
      Specified by:
      setTextContent in interface Node
      Throws:
      DOMException
    • getNamespaceURI

      public String getNamespaceURI()
      Specified by:
      getNamespaceURI in interface Node
    • getPrefix

      public String getPrefix()
      Specified by:
      getPrefix in interface Node
    • setPrefix

      public void setPrefix(String prefix) throws DOMException
      Specified by:
      setPrefix in interface Node
      Throws:
      DOMException
    • isEqualNode

      public boolean isEqualNode(Node arg)
      Specified by:
      isEqualNode in interface Node
    • isSameNode

      public boolean isSameNode(Node other)
      Specified by:
      isSameNode in interface Node
    • contains

      public boolean contains(Node node)
      Test if node is an inclusive descendant of this node.
      Parameters:
      node - the node to test.
      Returns:
      true if node is an inclusive descendant of this node, false otherwise (including node being null).