Path: blob/master/src/java.xml/share/classes/org/w3c/dom/Text.java
40948 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) 2004 World Wide Web Consortium,31*32* (Massachusetts Institute of Technology, European Research Consortium for33* Informatics and Mathematics, Keio University). All Rights Reserved. This34* work is distributed under the W3C(r) Software License [1] in the hope that35* it will be useful, but WITHOUT ANY WARRANTY; without even the implied36* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.37*38* [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-2002123139*/4041package org.w3c.dom;4243/**44* The <code>Text</code> interface inherits from <code>CharacterData</code>45* and represents the textual content (termed <a href='http://www.w3.org/TR/2004/REC-xml-20040204#syntax'>character data</a> in XML) of an <code>Element</code> or <code>Attr</code>. If there is no46* markup inside an element's content, the text is contained in a single47* object implementing the <code>Text</code> interface that is the only48* child of the element. If there is markup, it is parsed into the49* information items (elements, comments, etc.) and <code>Text</code> nodes50* that form the list of children of the element.51* <p>When a document is first made available via the DOM, there is only one52* <code>Text</code> node for each block of text. Users may create adjacent53* <code>Text</code> nodes that represent the contents of a given element54* without any intervening markup, but should be aware that there is no way55* to represent the separations between these nodes in XML or HTML, so they56* will not (in general) persist between DOM editing sessions. The57* <code>Node.normalize()</code> method merges any such adjacent58* <code>Text</code> objects into a single node for each block of text.59* <p> No lexical check is done on the content of a <code>Text</code> node60* and, depending on its position in the document, some characters must be61* escaped during serialization using character references; e.g. the62* characters "<&" if the textual content is part of an element or of63* an attribute, the character sequence "]]>" when part of an element,64* the quotation mark character " or the apostrophe character ' when part of65* an attribute.66* <p>See also the <a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>Document Object Model (DOM) Level 3 Core Specification</a>.67*/68public interface Text extends CharacterData {69/**70* Breaks this node into two nodes at the specified <code>offset</code>,71* keeping both in the tree as siblings. After being split, this node72* will contain all the content up to the <code>offset</code> point. A73* new node of the same type, which contains all the content at and74* after the <code>offset</code> point, is returned. If the original75* node had a parent node, the new node is inserted as the next sibling76* of the original node. When the <code>offset</code> is equal to the77* length of this node, the new node has no data.78* @param offset The 16-bit unit offset at which to split, starting from79* <code>0</code>.80* @return The new node, of the same type as this node.81* @exception DOMException82* INDEX_SIZE_ERR: Raised if the specified offset is negative or greater83* than the number of 16-bit units in <code>data</code>.84* <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.85*/86public Text splitText(int offset)87throws DOMException;8889/**90* Returns whether this text node contains <a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204#infoitem.character'>91* element content whitespace</a>, often abusively called "ignorable whitespace". The text node is92* determined to contain whitespace in element content during the load93* of the document or if validation occurs while using94* <code>Document.normalizeDocument()</code>.95* @since 1.5, DOM Level 396*/97public boolean isElementContentWhitespace();9899/**100* Returns all text of <code>Text</code> nodes logically-adjacent text101* nodes to this node, concatenated in document order.102* <br>For instance, in the example below <code>wholeText</code> on the103* <code>Text</code> node that contains "bar" returns "barfoo", while on104* the <code>Text</code> node that contains "foo" it returns "barfoo".105*106* <pre>107* +-----+108* | <p> |109* +-----+110* /\111* / \112* /-----\ +-------+113* | bar | | &ent; |114* \-----/ +-------+115* |116* |117* /-----\118* | foo |119* \-----/120* </pre>121* <em>Figure: barTextNode.wholeText value is "barfoo"</em>122*123* @since 1.5, DOM Level 3124*/125public String getWholeText();126127/**128* Replaces the text of the current node and all logically-adjacent text129* nodes with the specified text. All logically-adjacent text nodes are130* removed including the current node unless it was the recipient of the131* replacement text.132* <p>This method returns the node which received the replacement text.133* The returned node is:</p>134* <ul>135* <li><code>null</code>, when the replacement text is136* the empty string;137* </li>138* <li>the current node, except when the current node is139* read-only;140* </li>141* <li> a new <code>Text</code> node of the same type (142* <code>Text</code> or <code>CDATASection</code>) as the current node143* inserted at the location of the replacement.144* </li>145* </ul>146* <p>For instance, in the above example calling147* <code>replaceWholeText</code> on the <code>Text</code> node that148* contains "bar" with "yo" in argument results in the following:</p>149*150* <pre>151* +-----+152* | <p> |153* +-----+154* |155* |156* /-----\157* | yo |158* \-----/159* </pre>160* <em>Figure: barTextNode.replaceWholeText("yo") modifies the161* textual content of barTextNode with "yo"</em>162*163* <p>Where the nodes to be removed are read-only descendants of an164* <code>EntityReference</code>, the <code>EntityReference</code> must165* be removed instead of the read-only nodes. If any166* <code>EntityReference</code> to be removed has descendants that are167* not <code>EntityReference</code>, <code>Text</code>, or168* <code>CDATASection</code> nodes, the <code>replaceWholeText</code>169* method must fail before performing any modification of the document,170* raising a <code>DOMException</code> with the code171* <code>NO_MODIFICATION_ALLOWED_ERR</code>.</p>172* <p>For instance, in the example below calling173* <code>replaceWholeText</code> on the <code>Text</code> node that174* contains "bar" fails, because the <code>EntityReference</code> node175* "ent" contains an <code>Element</code> node which cannot be removed.</p>176* @param content The content of the replacing <code>Text</code> node.177* @return The <code>Text</code> node created with the specified content.178* @exception DOMException179* NO_MODIFICATION_ALLOWED_ERR: Raised if one of the <code>Text</code>180* nodes being replaced is readonly.181* @since 1.5, DOM Level 3182*/183public Text replaceWholeText(String content)184throws DOMException;185186}187188189