KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > dom > TextImpl


1 /**
2  * org/ozone-db/xml/dom/TextImpl.java
3  *
4  * The contents of this file are subject to the OpenXML Public
5  * License Version 1.0; you may not use this file except in compliance
6  * with the License. You may obtain a copy of the License at
7  * http://www.openxml.org/license.html
8  *
9  * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
10  * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
11  * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
12  * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
13  * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
14  * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
15  *
16  * The Initial Developer of this code under the License is Assaf Arkin.
17  * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
18  * All Rights Reserved.
19  *
20  * The Initial Developer of this code under the License is Assaf Arkin.
21  * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
22  * All Rights Reserved.
23  */

24
25 /**
26  * Changes for Persistent DOM running with ozone are
27  * Copyright 1999 by SMB GmbH. All rights reserved.
28  */

29
30 package org.ozoneDB.xml.dom;
31
32 import org.w3c.dom.*;
33
34
35 /**
36  * Implements the textual content (termed character data) of a {@link
37  * org.w3c.dom.Element} or {@link org.w3c.dom.Attr}. If there is no markup
38  * inside an element's content, the text is contained in a single object
39  * implementing the {@link org.w3c.dom.Text} interface; if there is markup,
40  * it is parsed into a list of elements and {@link org.w3c.dom.Text} nodes
41  * that form the list of children of the element.
42  * <P>
43  * Notes:
44  * <OLl>
45  * <LI>Node type is {@link org.w3c.dom.Node#TEXT_NODE}
46  * <LI>Node does not support childern
47  * <LI>Node name is always "#text"
48  * <LI>One of two nodes that may be added to an attribute
49  * </OL>
50  *
51  *
52  * @version $Revision: 1.2 $ $Date: 2003/11/20 23:18:42 $
53  * @author <a HREF="mailto:arkin@trendline.co.il">Assaf Arkin</a>
54  * @see org.w3c.dom.Text
55  * @see CharacterDataImpl
56  */

57 public class TextImpl extends CharacterDataImpl implements TextProxy {
58
59     final static long serialVersionUID = 1;
60
61
62     public short getNodeType() {
63         return TEXT_NODE;
64     }
65
66
67     public synchronized final Text splitText( int offset ) throws DOMException {
68         TextProxy next = null;
69
70         if (isReadOnly()) {
71             throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR );
72         }
73         if (offset < 0 || offset > getLength()) {
74             throw new DOMExceptionImpl( DOMException.INDEX_SIZE_ERR, "Offest is negative or greater than text size." );
75         }
76         // Create new Text node, splice the first section and place it in the new
77
// text node, then add it before this node. Splice the second section and
78
// place it in the existing node. Note that this Text node might not have
79
// a parent.
80
try {
81             next = (TextProxy)database().createObject( TextImpl.class.getName() );
82             next.init( _ownerDocument, substringData( 0, offset ) );
83         } catch (Exception JavaDoc except) {
84             throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() );
85         }
86         if (getParentNode() != null) {
87             getParentNode().insertBefore( next, this );
88         }
89         setData( substringData( offset, getLength() - offset ) );
90         return next;
91     }
92
93
94     public String JavaDoc toString() {
95         String JavaDoc value;
96
97         value = getData();
98         if (value.length() > 64) {
99             value = value.substring( 0, 64 ) + "..";
100         }
101         value = value.replace( '\n', '|' );
102         return "Text node: [" + value + "]";
103     }
104
105
106     public Object JavaDoc clone() {
107         TextProxy clone = null;
108         try {
109             clone = (TextProxy)database().createObject( TextImpl.class.getName() );
110             clone.init( _ownerDocument, getNodeValue() );
111             cloneInto( clone, true );
112         } catch (Exception JavaDoc except) {
113             throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() );
114         }
115         return clone;
116     }
117
118
119     public Node cloneNode( boolean deep ) {
120         TextProxy clone = null;
121         try {
122             clone = (TextProxy)database().createObject( TextImpl.class.getName() );
123             clone.init( _ownerDocument, getNodeValue() );
124             cloneInto( clone, deep );
125         } catch (Exception JavaDoc except) {
126             throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() );
127         }
128         return clone;
129     }
130
131
132     /**
133      * Constructor requires only owner document and initial text.
134      *
135      * @param owner The owner of this document
136      * @param text The initial text
137      */

138     TextImpl( DocumentImpl owner, String JavaDoc text ) {
139         super( owner, "#text", text );
140     }
141
142
143     /**
144      * Constructor for {@link CDATASectionImpl}.
145      */

146     TextImpl( DocumentImpl owner, String JavaDoc name, String JavaDoc text ) {
147         super( owner, name, text );
148     }
149
150
151     public TextImpl() {
152         super();
153     }
154
155
156     public void init( DocumentProxy owner, String JavaDoc text ) {
157         super.init( owner, "#text", text );
158     }
159 }
160
Popular Tags