Text.java revision 320c9890e8241fb0ad05de6fa5e6c3eb3aece159
1adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project/* 2320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Copyright (c) 2004 World Wide Web Consortium, 3320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 4320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * (Massachusetts Institute of Technology, European Research Consortium for 5320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Informatics and Mathematics, Keio University). All Rights Reserved. This 6320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * work is distributed under the W3C(r) Software License [1] in the hope that 7320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * it will be useful, but WITHOUT ANY WARRANTY; without even the implied 8320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 10320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 11adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 12adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 13adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectpackage org.w3c.dom; 14adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 15adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project/** 16adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * The <code>Text</code> interface inherits from <code>CharacterData</code> 17320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 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 no 18320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * markup inside an element's content, the text is contained in a single 19320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * object implementing the <code>Text</code> interface that is the only 20320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * child of the element. If there is markup, it is parsed into the 21320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * information items (elements, comments, etc.) and <code>Text</code> nodes 22320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * that form the list of children of the element. 23adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * <p>When a document is first made available via the DOM, there is only one 24adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * <code>Text</code> node for each block of text. Users may create adjacent 25adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * <code>Text</code> nodes that represent the contents of a given element 26adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * without any intervening markup, but should be aware that there is no way 27adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * to represent the separations between these nodes in XML or HTML, so they 28adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * will not (in general) persist between DOM editing sessions. The 29320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>Node.normalize()</code> method merges any such adjacent 30320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>Text</code> objects into a single node for each block of text. 31320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p> No lexical check is done on the content of a <code>Text</code> node 32320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * and, depending on its position in the document, some characters must be 33320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * escaped during serialization using character references; e.g. the 34320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * characters "<&" if the textual content is part of an element or of 35320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * an attribute, the character sequence "]]>" when part of an element, 36320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the quotation mark character " or the apostrophe character ' when part of 37320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * an attribute. 38320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <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>. 39adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 40adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectpublic interface Text extends CharacterData { 41adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 42adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * Breaks this node into two nodes at the specified <code>offset</code>, 43adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * keeping both in the tree as siblings. After being split, this node 44adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * will contain all the content up to the <code>offset</code> point. A 45adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * new node of the same type, which contains all the content at and 46adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * after the <code>offset</code> point, is returned. If the original 47adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * node had a parent node, the new node is inserted as the next sibling 48adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * of the original node. When the <code>offset</code> is equal to the 49adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * length of this node, the new node has no data. 50adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * @param offset The 16-bit unit offset at which to split, starting from 51adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * <code>0</code>. 52adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * @return The new node, of the same type as this node. 53adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * @exception DOMException 54adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * INDEX_SIZE_ERR: Raised if the specified offset is negative or greater 55adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * than the number of 16-bit units in <code>data</code>. 56adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. 57adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 58adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project public Text splitText(int offset) 59adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project throws DOMException; 60adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 61320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 62320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Returns whether this text node contains <a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204#infoitem.character'> 63320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * element content whitespace</a>, often abusively called "ignorable whitespace". The text node is 64320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * determined to contain whitespace in element content during the load 65320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * of the document or if validation occurs while using 66320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>Document.normalizeDocument()</code>. 67320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @since DOM Level 3 68320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 69320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public boolean isElementContentWhitespace(); 70320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 71320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 72320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Returns all text of <code>Text</code> nodes logically-adjacent text 73320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * nodes to this node, concatenated in document order. 74320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <br>For instance, in the example below <code>wholeText</code> on the 75320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>Text</code> node that contains "bar" returns "barfoo", while on 76320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the <code>Text</code> node that contains "foo" it returns "barfoo". 77320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @since DOM Level 3 78320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 79320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public String getWholeText(); 80320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 81320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 82320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Replaces the text of the current node and all logically-adjacent text 83320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * nodes with the specified text. All logically-adjacent text nodes are 84320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * removed including the current node unless it was the recipient of the 85320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * replacement text. 86320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <br>This method returns the node which received the replacement text. 87320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * The returned node is: 88320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <ul> 89320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <li><code>null</code>, when the replacement text is 90320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the empty string; 91320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * </li> 92320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <li>the current node, except when the current node is 93320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * read-only; 94320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * </li> 95320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <li> a new <code>Text</code> node of the same type ( 96320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>Text</code> or <code>CDATASection</code>) as the current node 97320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * inserted at the location of the replacement. 98320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * </li> 99320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * </ul> 100320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <br>For instance, in the above example calling 101320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>replaceWholeText</code> on the <code>Text</code> node that 102320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * contains "bar" with "yo" in argument results in the following: 103320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <br>Where the nodes to be removed are read-only descendants of an 104320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>EntityReference</code>, the <code>EntityReference</code> must 105320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * be removed instead of the read-only nodes. If any 106320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>EntityReference</code> to be removed has descendants that are 107320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * not <code>EntityReference</code>, <code>Text</code>, or 108320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>CDATASection</code> nodes, the <code>replaceWholeText</code> 109320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * method must fail before performing any modification of the document, 110320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * raising a <code>DOMException</code> with the code 111320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>NO_MODIFICATION_ALLOWED_ERR</code>. 112320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <br>For instance, in the example below calling 113320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>replaceWholeText</code> on the <code>Text</code> node that 114320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * contains "bar" fails, because the <code>EntityReference</code> node 115320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * "ent" contains an <code>Element</code> node which cannot be removed. 116320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param content The content of the replacing <code>Text</code> node. 117320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @return The <code>Text</code> node created with the specified content. 118320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @exception DOMException 119320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * NO_MODIFICATION_ALLOWED_ERR: Raised if one of the <code>Text</code> 120320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * nodes being replaced is readonly. 121320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @since DOM Level 3 122320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 123320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public Text replaceWholeText(String content) 124320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws DOMException; 125320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 126adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project} 127