KickJava   Java API By Example, From Geeks To Geeks.

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

81 public class TextImpl
82     extends CharacterDataImpl
83     implements CharacterData JavaDoc, Text JavaDoc {
84
85     //
86
// Constants
87
//
88

89     /** Serialization version. */
90     static final long serialVersionUID = -5294980852957403469L;
91     
92     //
93
// Constructors
94
//
95

96     /** Factory constructor. */
97     public TextImpl(CoreDocumentImpl ownerDoc, String JavaDoc data) {
98         super(ownerDoc, data);
99     }
100     
101     //
102
// Node methods
103
//
104

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

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

121     public void setIgnorableWhitespace(boolean ignore) {
122
123         if (needsSyncData()) {
124             synchronizeData();
125         }
126         isIgnorableWhitespace(ignore);
127
128     } // setIgnorableWhitespace(boolean)
129

130
131     /**
132      * NON-DOM: Returns whether this Text is ignorable whitespace.
133      */

134     public boolean isIgnorableWhitespace() {
135
136         if (needsSyncData()) {
137             synchronizeData();
138         }
139         return internalIsIgnorableWhitespace();
140
141     } // isIgnorableWhitespace():boolean
142

143     //
144
// Text methods
145
//
146

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

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

195
196     /* (non-Javadoc)
197      * @see org.w3c.dom.Text#isElementContentWhitespace()
198      */

199     public boolean isElementContentWhitespace() {
200         // TODO Auto-generated method stub
201
return false;
202     }
203     /* (non-Javadoc)
204      * @see org.w3c.dom.Text#getWholeText()
205      */

206     public String JavaDoc getWholeText() {
207         // TODO Auto-generated method stub
208
return null;
209     }
210     /* (non-Javadoc)
211      * @see org.w3c.dom.Text#replaceWholeText(java.lang.String)
212      */

213     public Text JavaDoc replaceWholeText(String JavaDoc content) throws DOMException JavaDoc {
214         // TODO Auto-generated method stub
215
return null;
216     }
217
218 } // class TextImpl
219
Popular Tags