KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xpath > datamodel > xerces > dom > TextImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.xquark.xpath.datamodel.xerces.dom;
59
60 import org.w3c.dom.*;
61
62 /**
63  * Text nodes hold the non-markup, non-Entity content of
64  * an Element or Attribute.
65  * <P>
66  * When a document is first made available to the DOM, there is only
67  * one Text object for each block of adjacent plain-text. Users (ie,
68  * applications) may create multiple adjacent Texts during editing --
69  * see {@link Element#normalize} for discussion.
70  * <P>
71  * Note that CDATASection is a subclass of Text. This is conceptually
72  * valid, since they're really just two different ways of quoting
73  * characters when they're written out as part of an XML stream.
74  *
75  * @version
76  * @since PR-DOM-Level-1-19980818.
77  */

78 public class TextImpl
79     extends CharacterDataImpl
80     implements CharacterData, Text {
81
82     //
83
// Constants
84
//
85

86     /** Serialization version. */
87     static final long serialVersionUID = -5294980852957403469L;
88     
89     //
90
// Constructors
91
//
92

93     /** Factory constructor. */
94     public TextImpl(DocumentImpl ownerDoc, String JavaDoc data) {
95         super(ownerDoc, data);
96     }
97     
98     //
99
// Node methods
100
//
101

102     /**
103      * A short integer indicating what type of node this is. The named
104      * constants for this value are defined in the org.w3c.dom.Node interface.
105      */

106     public short getNodeType() {
107         return Node.TEXT_NODE;
108     }
109
110     /** Returns the node name. */
111     public String JavaDoc getNodeName() {
112         return "#text";
113     }
114
115     /**
116      * NON-DOM: Set whether this Text is ignorable whitespace.
117      */

118     public void setIgnorableWhitespace(boolean ignore) {
119
120         if (needsSyncData()) {
121             synchronizeData();
122         }
123         isIgnorableWhitespace(ignore);
124
125     } // setIgnorableWhitespace(boolean)
126

127
128     /**
129      * NON-DOM: Returns whether this Text is ignorable whitespace.
130      */

131     public boolean isIgnorableWhitespace() {
132
133         if (needsSyncData()) {
134             synchronizeData();
135         }
136         return internalIsIgnorableWhitespace();
137
138     } // isIgnorableWhitespace():boolean
139

140     //
141
// Text methods
142
//
143

144     /**
145      * Break a text node into two sibling nodes. (Note that if the
146      * current node has no parent, they won't wind up as "siblings" --
147      * they'll both be orphans.)
148      *
149      * @param offset The offset at which to split. If offset is at the
150      * end of the available data, the second node will be empty.
151      *
152      * @returns A reference to the new node (containing data after the
153      * offset point). The original node will contain data up to that
154      * point.
155      *
156      * @throws DOMException(INDEX_SIZE_ERR) if offset is <0 or >length.
157      *
158      * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if node is read-only.
159      */

160     public Text splitText(int offset)
161         throws DOMException {
162
163         if (isReadOnly()) {
164             throw new DOMException(
165                 DOMException.NO_MODIFICATION_ALLOWED_ERR,
166                 "DOM001 Modification not allowed");
167         }
168
169         if (needsSyncData()) {
170             synchronizeData();
171         }
172         if (offset < 0 || offset > data.length() ) {
173             throw new DOMException(DOMException.INDEX_SIZE_ERR,
174                                        "DOM004 Index out of bounds");
175         }
176             
177         // split text into two separate nodes
178
Text newText =
179             getOwnerDocument().createTextNode(data.substring(offset));
180         setNodeValue(data.substring(0, offset));
181
182         // insert new text node
183
Node parentNode = getParentNode();
184         if (parentNode != null) {
185             parentNode.insertBefore(newText, nextSibling);
186         }
187
188         return newText;
189
190     } // splitText(int):Text
191

192 } // class TextImpl
193
Popular Tags