13 November, 2000

Appendix B: Java Language Binding

This appendix contains the complete Java Language [Java] binding for the Level 2 Document Object Model Traversal and Range. The definitions are divided into Traversal, and Range.

The Java files are also available as http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/java-binding.zip

B.1: Document Object Model Traversal

org/w3c/dom/traversal/NodeIterator.java:

package org.w3c.dom.traversal;

import org.w3c.dom.Node;
import org.w3c.dom.DOMException;

public interface NodeIterator {
    public Node getRoot();

    public int getWhatToShow();

    public NodeFilter getFilter();

    public boolean getExpandEntityReferences();

    public Node nextNode()
                         throws DOMException;

    public Node previousNode()
                             throws DOMException;

    public void detach();

}

org/w3c/dom/traversal/NodeFilter.java:

package org.w3c.dom.traversal;

import org.w3c.dom.Node;

public interface NodeFilter {
    // Constants returned by acceptNode
    public static final short FILTER_ACCEPT             = 1;
    public static final short FILTER_REJECT             = 2;
    public static final short FILTER_SKIP               = 3;

    // Constants for whatToShow
    public static final int SHOW_ALL                  = 0xFFFFFFFF;
    public static final int SHOW_ELEMENT              = 0x00000001;
    public static final int SHOW_ATTRIBUTE            = 0x00000002;
    public static final int SHOW_TEXT                 = 0x00000004;
    public static final int SHOW_CDATA_SECTION        = 0x00000008;
    public static final int SHOW_ENTITY_REFERENCE     = 0x00000010;
    public static final int SHOW_ENTITY               = 0x00000020;
    public static final int SHOW_PROCESSING_INSTRUCTION = 0x00000040;
    public static final int SHOW_COMMENT              = 0x00000080;
    public static final int SHOW_DOCUMENT             = 0x00000100;
    public static final int SHOW_DOCUMENT_TYPE        = 0x00000200;
    public static final int SHOW_DOCUMENT_FRAGMENT    = 0x00000400;
    public static final int SHOW_NOTATION             = 0x00000800;

    public short acceptNode(Node n);

}

org/w3c/dom/traversal/TreeWalker.java:

package org.w3c.dom.traversal;

import org.w3c.dom.Node;
import org.w3c.dom.DOMException;

public interface TreeWalker {
    public Node getRoot();

    public int getWhatToShow();

    public NodeFilter getFilter();

    public boolean getExpandEntityReferences();

    public Node getCurrentNode();
    public void setCurrentNode(Node currentNode)
                            throws DOMException;

    public Node parentNode();

    public Node firstChild();

    public Node lastChild();

    public Node previousSibling();

    public Node nextSibling();

    public Node previousNode();

    public Node nextNode();

}

org/w3c/dom/traversal/DocumentTraversal.java:

package org.w3c.dom.traversal;

import org.w3c.dom.Node;
import org.w3c.dom.DOMException;

public interface DocumentTraversal {
    public NodeIterator createNodeIterator(Node root, 
                                           int whatToShow, 
                                           NodeFilter filter, 
                                           boolean entityReferenceExpansion)
                                           throws DOMException;

    public TreeWalker createTreeWalker(Node root, 
                                       int whatToShow, 
                                       NodeFilter filter, 
                                       boolean entityReferenceExpansion)
                                       throws DOMException;

}

B.2: Document Object Model Range

org/w3c/dom/ranges/RangeException.java:

package org.w3c.dom.ranges;

public class RangeException extends RuntimeException {
    public RangeException(short code, String message) {
       super(message);
       this.code = code;
    }
    public short   code;
    // RangeExceptionCode
    public static final short BAD_BOUNDARYPOINTS_ERR    = 1;
    public static final short INVALID_NODE_TYPE_ERR     = 2;

}

org/w3c/dom/ranges/Range.java:

package org.w3c.dom.ranges;

import org.w3c.dom.Node;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.DOMException;

public interface Range {
    public Node getStartContainer()
                                       throws DOMException;

    public int getStartOffset()
                                       throws DOMException;

    public Node getEndContainer()
                                       throws DOMException;

    public int getEndOffset()
                                       throws DOMException;

    public boolean getCollapsed()
                                       throws DOMException;

    public Node getCommonAncestorContainer()
                                       throws DOMException;

    public void setStart(Node refNode, 
                         int offset)
                         throws RangeException, DOMException;

    public void setEnd(Node refNode, 
                       int offset)
                       throws RangeException, DOMException;

    public void setStartBefore(Node refNode)
                               throws RangeException, DOMException;

    public void setStartAfter(Node refNode)
                              throws RangeException, DOMException;

    public void setEndBefore(Node refNode)
                             throws RangeException, DOMException;

    public void setEndAfter(Node refNode)
                            throws RangeException, DOMException;

    public void collapse(boolean toStart)
                         throws DOMException;

    public void selectNode(Node refNode)
                           throws RangeException, DOMException;

    public void selectNodeContents(Node refNode)
                                   throws RangeException, DOMException;

    // CompareHow
    public static final short START_TO_START            = 0;
    public static final short START_TO_END              = 1;
    public static final short END_TO_END                = 2;
    public static final short END_TO_START              = 3;

    public short compareBoundaryPoints(short how, 
                                       Range sourceRange)
                                       throws DOMException;

    public void deleteContents()
                               throws DOMException;

    public DocumentFragment extractContents()
                                            throws DOMException;

    public DocumentFragment cloneContents()
                                          throws DOMException;

    public void insertNode(Node newNode)
                           throws DOMException, RangeException;

    public void surroundContents(Node newParent)
                                 throws DOMException, RangeException;

    public Range cloneRange()
                            throws DOMException;

    public String toString()
                           throws DOMException;

    public void detach()
                       throws DOMException;

}

org/w3c/dom/ranges/DocumentRange.java:

package org.w3c.dom.ranges;

public interface DocumentRange {
    public Range createRange();

}