Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/w3c/dom/ranges/Range.java
86410 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* This file is available under and governed by the GNU General Public26* License version 2 only, as published by the Free Software Foundation.27* However, the following notice accompanied the original version of this28* file and, per its terms, should not be removed:29*30* Copyright (c) 2000 World Wide Web Consortium,31* (Massachusetts Institute of Technology, Institut National de32* Recherche en Informatique et en Automatique, Keio University). All33* Rights Reserved. This program is distributed under the W3C's Software34* Intellectual Property License. This program is distributed in the35* hope that it will be useful, but WITHOUT ANY WARRANTY; without even36* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR37* PURPOSE.38* See W3C License http://www.w3.org/Consortium/Legal/ for more details.39*/4041package org.w3c.dom.ranges;4243import org.w3c.dom.Node;44import org.w3c.dom.DOMException;45import org.w3c.dom.DocumentFragment;4647/**48* <p>See also the <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113'>Document Object Model (DOM) Level 2 Traversal and Range Specification</a>.49* @since DOM Level 250*/51public interface Range {52/**53* Node within which the Range begins54* @exception DOMException55* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been56* invoked on this object.57*/58public Node getStartContainer()59throws DOMException;6061/**62* Offset within the starting node of the Range.63* @exception DOMException64* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been65* invoked on this object.66*/67public int getStartOffset()68throws DOMException;6970/**71* Node within which the Range ends72* @exception DOMException73* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been74* invoked on this object.75*/76public Node getEndContainer()77throws DOMException;7879/**80* Offset within the ending node of the Range.81* @exception DOMException82* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been83* invoked on this object.84*/85public int getEndOffset()86throws DOMException;8788/**89* TRUE if the Range is collapsed90* @exception DOMException91* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been92* invoked on this object.93*/94public boolean getCollapsed()95throws DOMException;9697/**98* The deepest common ancestor container of the Range's two99* boundary-points.100* @exception DOMException101* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been102* invoked on this object.103*/104public Node getCommonAncestorContainer()105throws DOMException;106107/**108* Sets the attributes describing the start of the Range.109* @param refNode The <code>refNode</code> value. This parameter must be110* different from <code>null</code>.111* @param offset The <code>startOffset</code> value.112* @exception RangeException113* INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code> or an ancestor114* of <code>refNode</code> is an Entity, Notation, or DocumentType115* node.116* @exception DOMException117* INDEX_SIZE_ERR: Raised if <code>offset</code> is negative or greater118* than the number of child units in <code>refNode</code>. Child units119* are 16-bit units if <code>refNode</code> is a type of CharacterData120* node (e.g., a Text or Comment node) or a ProcessingInstruction121* node. Child units are Nodes in all other cases.122* <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already123* been invoked on this object.124* <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created125* from a different document than the one that created this range.126*/127public void setStart(Node refNode,128int offset)129throws RangeException, DOMException;130131/**132* Sets the attributes describing the end of a Range.133* @param refNode The <code>refNode</code> value. This parameter must be134* different from <code>null</code>.135* @param offset The <code>endOffset</code> value.136* @exception RangeException137* INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code> or an ancestor138* of <code>refNode</code> is an Entity, Notation, or DocumentType139* node.140* @exception DOMException141* INDEX_SIZE_ERR: Raised if <code>offset</code> is negative or greater142* than the number of child units in <code>refNode</code>. Child units143* are 16-bit units if <code>refNode</code> is a type of CharacterData144* node (e.g., a Text or Comment node) or a ProcessingInstruction145* node. Child units are Nodes in all other cases.146* <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already147* been invoked on this object.148* <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created149* from a different document than the one that created this range.150*/151public void setEnd(Node refNode,152int offset)153throws RangeException, DOMException;154155/**156* Sets the start position to be before a node157* @param refNode Range starts before <code>refNode</code>158* @exception RangeException159* INVALID_NODE_TYPE_ERR: Raised if the root container of160* <code>refNode</code> is not an Attr, Document, or DocumentFragment161* node or if <code>refNode</code> is a Document, DocumentFragment,162* Attr, Entity, or Notation node.163* @exception DOMException164* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been165* invoked on this object.166* <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created167* from a different document than the one that created this range.168*/169public void setStartBefore(Node refNode)170throws RangeException, DOMException;171172/**173* Sets the start position to be after a node174* @param refNode Range starts after <code>refNode</code>175* @exception RangeException176* INVALID_NODE_TYPE_ERR: Raised if the root container of177* <code>refNode</code> is not an Attr, Document, or DocumentFragment178* node or if <code>refNode</code> is a Document, DocumentFragment,179* Attr, Entity, or Notation node.180* @exception DOMException181* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been182* invoked on this object.183* <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created184* from a different document than the one that created this range.185*/186public void setStartAfter(Node refNode)187throws RangeException, DOMException;188189/**190* Sets the end position to be before a node.191* @param refNode Range ends before <code>refNode</code>192* @exception RangeException193* INVALID_NODE_TYPE_ERR: Raised if the root container of194* <code>refNode</code> is not an Attr, Document, or DocumentFragment195* node or if <code>refNode</code> is a Document, DocumentFragment,196* Attr, Entity, or Notation node.197* @exception DOMException198* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been199* invoked on this object.200* <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created201* from a different document than the one that created this range.202*/203public void setEndBefore(Node refNode)204throws RangeException, DOMException;205206/**207* Sets the end of a Range to be after a node208* @param refNode Range ends after <code>refNode</code>.209* @exception RangeException210* INVALID_NODE_TYPE_ERR: Raised if the root container of211* <code>refNode</code> is not an Attr, Document or DocumentFragment212* node or if <code>refNode</code> is a Document, DocumentFragment,213* Attr, Entity, or Notation node.214* @exception DOMException215* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been216* invoked on this object.217* <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created218* from a different document than the one that created this range.219*/220public void setEndAfter(Node refNode)221throws RangeException, DOMException;222223/**224* Collapse a Range onto one of its boundary-points225* @param toStart If TRUE, collapses the Range onto its start; if FALSE,226* collapses it onto its end.227* @exception DOMException228* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been229* invoked on this object.230*/231public void collapse(boolean toStart)232throws DOMException;233234/**235* Select a node and its contents236* @param refNode The node to select.237* @exception RangeException238* INVALID_NODE_TYPE_ERR: Raised if an ancestor of <code>refNode</code>239* is an Entity, Notation or DocumentType node or if240* <code>refNode</code> is a Document, DocumentFragment, Attr, Entity,241* or Notation node.242* @exception DOMException243* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been244* invoked on this object.245* <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created246* from a different document than the one that created this range.247*/248public void selectNode(Node refNode)249throws RangeException, DOMException;250251/**252* Select the contents within a node253* @param refNode Node to select from254* @exception RangeException255* INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code> or an ancestor256* of <code>refNode</code> is an Entity, Notation or DocumentType node.257* @exception DOMException258* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been259* invoked on this object.260* <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created261* from a different document than the one that created this range.262*/263public void selectNodeContents(Node refNode)264throws RangeException, DOMException;265266// CompareHow267/**268* Compare start boundary-point of <code>sourceRange</code> to start269* boundary-point of Range on which <code>compareBoundaryPoints</code>270* is invoked.271*/272public static final short START_TO_START = 0;273/**274* Compare start boundary-point of <code>sourceRange</code> to end275* boundary-point of Range on which <code>compareBoundaryPoints</code>276* is invoked.277*/278public static final short START_TO_END = 1;279/**280* Compare end boundary-point of <code>sourceRange</code> to end281* boundary-point of Range on which <code>compareBoundaryPoints</code>282* is invoked.283*/284public static final short END_TO_END = 2;285/**286* Compare end boundary-point of <code>sourceRange</code> to start287* boundary-point of Range on which <code>compareBoundaryPoints</code>288* is invoked.289*/290public static final short END_TO_START = 3;291292/**293* Compare the boundary-points of two Ranges in a document.294* @param how A code representing the type of comparison, as defined295* above.296* @param sourceRange The <code>Range</code> on which this current297* <code>Range</code> is compared to.298* @return -1, 0 or 1 depending on whether the corresponding299* boundary-point of the Range is respectively before, equal to, or300* after the corresponding boundary-point of <code>sourceRange</code>.301* @exception DOMException302* WRONG_DOCUMENT_ERR: Raised if the two Ranges are not in the same303* Document or DocumentFragment.304* <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already305* been invoked on this object.306*/307public short compareBoundaryPoints(short how,308Range sourceRange)309throws DOMException;310311/**312* Removes the contents of a Range from the containing document or313* document fragment without returning a reference to the removed314* content.315* @exception DOMException316* NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of the content of317* the Range is read-only or any of the nodes that contain any of the318* content of the Range are read-only.319* <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already320* been invoked on this object.321*/322public void deleteContents()323throws DOMException;324325/**326* Moves the contents of a Range from the containing document or document327* fragment to a new DocumentFragment.328* @return A DocumentFragment containing the extracted contents.329* @exception DOMException330* NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of the content of331* the Range is read-only or any of the nodes which contain any of the332* content of the Range are read-only.333* <br>HIERARCHY_REQUEST_ERR: Raised if a DocumentType node would be334* extracted into the new DocumentFragment.335* <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already336* been invoked on this object.337*/338public DocumentFragment extractContents()339throws DOMException;340341/**342* Duplicates the contents of a Range343* @return A DocumentFragment that contains content equivalent to this344* Range.345* @exception DOMException346* HIERARCHY_REQUEST_ERR: Raised if a DocumentType node would be347* extracted into the new DocumentFragment.348* <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already349* been invoked on this object.350*/351public DocumentFragment cloneContents()352throws DOMException;353354/**355* Inserts a node into the Document or DocumentFragment at the start of356* the Range. If the container is a Text node, this will be split at the357* start of the Range (as if the Text node's splitText method was358* performed at the insertion point) and the insertion will occur359* between the two resulting Text nodes. Adjacent Text nodes will not be360* automatically merged. If the node to be inserted is a361* DocumentFragment node, the children will be inserted rather than the362* DocumentFragment node itself.363* @param newNode The node to insert at the start of the Range364* @exception DOMException365* NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of the366* start of the Range is read-only.367* <br>WRONG_DOCUMENT_ERR: Raised if <code>newNode</code> and the368* container of the start of the Range were not created from the same369* document.370* <br>HIERARCHY_REQUEST_ERR: Raised if the container of the start of371* the Range is of a type that does not allow children of the type of372* <code>newNode</code> or if <code>newNode</code> is an ancestor of373* the container.374* <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already375* been invoked on this object.376* @exception RangeException377* INVALID_NODE_TYPE_ERR: Raised if <code>newNode</code> is an Attr,378* Entity, Notation, or Document node.379*/380public void insertNode(Node newNode)381throws DOMException, RangeException;382383/**384* Reparents the contents of the Range to the given node and inserts the385* node at the position of the start of the Range.386* @param newParent The node to surround the contents with.387* @exception DOMException388* NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of389* either boundary-point of the Range is read-only.390* <br>WRONG_DOCUMENT_ERR: Raised if <code> newParent</code> and the391* container of the start of the Range were not created from the same392* document.393* <br>HIERARCHY_REQUEST_ERR: Raised if the container of the start of394* the Range is of a type that does not allow children of the type of395* <code>newParent</code> or if <code>newParent</code> is an ancestor396* of the container or if <code>node</code> would end up with a child397* node of a type not allowed by the type of <code>node</code>.398* <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already399* been invoked on this object.400* @exception RangeException401* BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a402* non-text node.403* <br>INVALID_NODE_TYPE_ERR: Raised if <code> node</code> is an Attr,404* Entity, DocumentType, Notation, Document, or DocumentFragment node.405*/406public void surroundContents(Node newParent)407throws DOMException, RangeException;408409/**410* Produces a new Range whose boundary-points are equal to the411* boundary-points of the Range.412* @return The duplicated Range.413* @exception DOMException414* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been415* invoked on this object.416*/417public Range cloneRange()418throws DOMException;419420/**421* Returns the contents of a Range as a string. This string contains only422* the data characters, not any markup.423* @return The contents of the Range.424* @exception DOMException425* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been426* invoked on this object.427*/428public String toString()429throws DOMException;430431/**432* Called to indicate that the Range is no longer in use and that the433* implementation may relinquish any resources associated with this434* Range. Subsequent calls to any methods or attribute getters on this435* Range will result in a <code>DOMException</code> being thrown with an436* error code of <code>INVALID_STATE_ERR</code>.437* @exception DOMException438* INVALID_STATE_ERR: Raised if <code>detach()</code> has already been439* invoked on this object.440*/441public void detach()442throws DOMException;443444}445446447