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/** 16f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * The <code>Text</code> interface inherits from <code>CharacterData</code> 17f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 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 18f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * markup inside an element's content, the text is contained in a single 19f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * object implementing the <code>Text</code> interface that is the only 20f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * child of the element. If there is markup, it is parsed into the 21f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * information items (elements, comments, etc.) and <code>Text</code> nodes 22320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * that form the list of children of the element. 23f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <p>When a document is first made available via the DOM, there is only one 24f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <code>Text</code> node for each block of text. Users may create adjacent 25f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <code>Text</code> nodes that represent the contents of a given element 26f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * without any intervening markup, but should be aware that there is no way 27f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * to represent the separations between these nodes in XML or HTML, so they 28f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * will not (in general) persist between DOM editing sessions. The 29f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <code>Node.normalize()</code> method merges any such adjacent 30320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>Text</code> objects into a single node for each block of text. 31f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <p> No lexical check is done on the content of a <code>Text</code> node 32f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * and, depending on its position in the document, some characters must be 33f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * escaped during serialization using character references; e.g. the 34f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * characters "<&" if the textual content is part of an element or of 35f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * an attribute, the character sequence "]]>" when part of an element, 36f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * the quotation mark character " or the apostrophe character ' when part of 37f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 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 /** 42f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * Breaks this node into two nodes at the specified <code>offset</code>, 43f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * keeping both in the tree as siblings. After being split, this node 44f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * will contain all the content up to the <code>offset</code> point. A 45f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * new node of the same type, which contains all the content at and 46f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * after the <code>offset</code> point, is returned. If the original 47f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * node had a parent node, the new node is inserted as the next sibling 48f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 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. 50f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * @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 54f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 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'> 63f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * element content whitespace</a>, often abusively called "ignorable whitespace". The text node is 64f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * determined to contain whitespace in element content during the load 65f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 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 /** 72f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * Returns all text of <code>Text</code> nodes logically-adjacent text 73320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * nodes to this node, concatenated in document order. 74f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <br>For instance, in the example below <code>wholeText</code> on the 75f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <code>Text</code> node that contains "bar" returns "barfoo", while on 76f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 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 /** 82f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * Replaces the text of the current node and all logically-adjacent text 83f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * nodes with the specified text. All logically-adjacent text nodes are 84f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * removed including the current node unless it was the recipient of the 85320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * replacement text. 86f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <br>This method returns the node which received the replacement text. 87f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * The returned node is: 88320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <ul> 89f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <li><code>null</code>, when the replacement text is 90320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the empty string; 91320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * </li> 92f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <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 ( 96f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <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> 100f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <br>For instance, in the above example calling 101f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <code>replaceWholeText</code> on the <code>Text</code> node that 102f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * contains "bar" with "yo" in argument results in the following: 103f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <br>Where the nodes to be removed are read-only descendants of an 104f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <code>EntityReference</code>, the <code>EntityReference</code> must 105f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * be removed instead of the read-only nodes. If any 106f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <code>EntityReference</code> to be removed has descendants that are 107f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * not <code>EntityReference</code>, <code>Text</code>, or 108f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <code>CDATASection</code> nodes, the <code>replaceWholeText</code> 109f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * method must fail before performing any modification of the document, 110f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * raising a <code>DOMException</code> with the code 111320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>NO_MODIFICATION_ALLOWED_ERR</code>. 112f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <br>For instance, in the example below calling 113f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * <code>replaceWholeText</code> on the <code>Text</code> node that 114f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 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 119f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 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