001 /*
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
003 *
004 * This code is free software; you can redistribute it and/or modify it
005 * under the terms of the GNU General Public License version 2 only, as
006 * published by the Free Software Foundation. Sun designates this
007 * particular file as subject to the "Classpath" exception as provided
008 * by Sun in the LICENSE file that accompanied this code.
009 *
010 * This code is distributed in the hope that it will be useful, but WITHOUT
011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
013 * version 2 for more details (a copy is included in the LICENSE file that
014 * accompanied this code).
015 *
016 * You should have received a copy of the GNU General Public License version
017 * 2 along with this work; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
019 *
020 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
021 * CA 95054 USA or visit www.sun.com if you need additional information or
022 * have any questions.
023 */
024
025 /*
026 * This file is available under and governed by the GNU General Public
027 * License version 2 only, as published by the Free Software Foundation.
028 * However, the following notice accompanied the original version of this
029 * file and, per its terms, should not be removed:
030 *
031 * Copyright (c) 2004 World Wide Web Consortium,
032 *
033 * (Massachusetts Institute of Technology, European Research Consortium for
034 * Informatics and Mathematics, Keio University). All Rights Reserved. This
035 * work is distributed under the W3C(r) Software License [1] in the hope that
036 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
037 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
038 *
039 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
040 */
041
042 package org.w3c.dom;
043
044 /**
045 * The <code>Text</code> interface inherits from <code>CharacterData</code>
046 * 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
047 * markup inside an element's content, the text is contained in a single
048 * object implementing the <code>Text</code> interface that is the only
049 * child of the element. If there is markup, it is parsed into the
050 * information items (elements, comments, etc.) and <code>Text</code> nodes
051 * that form the list of children of the element.
052 * <p>When a document is first made available via the DOM, there is only one
053 * <code>Text</code> node for each block of text. Users may create adjacent
054 * <code>Text</code> nodes that represent the contents of a given element
055 * without any intervening markup, but should be aware that there is no way
056 * to represent the separations between these nodes in XML or HTML, so they
057 * will not (in general) persist between DOM editing sessions. The
058 * <code>Node.normalize()</code> method merges any such adjacent
059 * <code>Text</code> objects into a single node for each block of text.
060 * <p> No lexical check is done on the content of a <code>Text</code> node
061 * and, depending on its position in the document, some characters must be
062 * escaped during serialization using character references; e.g. the
063 * characters "<&" if the textual content is part of an element or of
064 * an attribute, the character sequence "]]>" when part of an element,
065 * the quotation mark character " or the apostrophe character ' when part of
066 * an attribute.
067 * <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>.
068 */
069 public interface Text extends CharacterData {
070 /**
071 * Breaks this node into two nodes at the specified <code>offset</code>,
072 * keeping both in the tree as siblings. After being split, this node
073 * will contain all the content up to the <code>offset</code> point. A
074 * new node of the same type, which contains all the content at and
075 * after the <code>offset</code> point, is returned. If the original
076 * node had a parent node, the new node is inserted as the next sibling
077 * of the original node. When the <code>offset</code> is equal to the
078 * length of this node, the new node has no data.
079 * @param offset The 16-bit unit offset at which to split, starting from
080 * <code>0</code>.
081 * @return The new node, of the same type as this node.
082 * @exception DOMException
083 * INDEX_SIZE_ERR: Raised if the specified offset is negative or greater
084 * than the number of 16-bit units in <code>data</code>.
085 * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
086 */
087 public Text splitText(int offset) throws DOMException;
088
089 /**
090 * Returns whether this text node contains <a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204#infoitem.character'>
091 * element content whitespace</a>, often abusively called "ignorable whitespace". The text node is
092 * determined to contain whitespace in element content during the load
093 * of the document or if validation occurs while using
094 * <code>Document.normalizeDocument()</code>.
095 * @since DOM Level 3
096 */
097 public boolean isElementContentWhitespace();
098
099 /**
100 * Returns all text of <code>Text</code> nodes logically-adjacent text
101 * nodes to this node, concatenated in document order.
102 * <br>For instance, in the example below <code>wholeText</code> on the
103 * <code>Text</code> node that contains "bar" returns "barfoo", while on
104 * 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 DOM Level 3
124 */
125 public String getWholeText();
126
127 /**
128 * Replaces the text of the current node and all logically-adjacent text
129 * nodes with the specified text. All logically-adjacent text nodes are
130 * removed including the current node unless it was the recipient of the
131 * 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 is
136 * the empty string;
137 * </li>
138 * <li>the current node, except when the current node is
139 * 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 node
143 * inserted at the location of the replacement.
144 * </li>
145 * </ul>
146 * <p>For instance, in the above example calling
147 * <code>replaceWholeText</code> on the <code>Text</code> node that
148 * 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 the
161 * textual content of barTextNode with "yo"</em>
162 *
163 * <p>Where the nodes to be removed are read-only descendants of an
164 * <code>EntityReference</code>, the <code>EntityReference</code> must
165 * be removed instead of the read-only nodes. If any
166 * <code>EntityReference</code> to be removed has descendants that are
167 * not <code>EntityReference</code>, <code>Text</code>, or
168 * <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 code
171 * <code>NO_MODIFICATION_ALLOWED_ERR</code>.</p>
172 * <p>For instance, in the example below calling
173 * <code>replaceWholeText</code> on the <code>Text</code> node that
174 * contains "bar" fails, because the <code>EntityReference</code> node
175 * "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 DOMException
179 * NO_MODIFICATION_ALLOWED_ERR: Raised if one of the <code>Text</code>
180 * nodes being replaced is readonly.
181 * @since DOM Level 3
182 */
183 public Text replaceWholeText(String content) throws DOMException;
184
185 }
|