KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lobobrowser > html > domimpl > CharacterDataImpl


1 /*
2     GNU LESSER GENERAL PUBLIC LICENSE
3     Copyright (C) 2006 The Lobo Project
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19     Contact info: xamjadmin@users.sourceforge.net
20 */

21 /*
22  * Created on Sep 3, 2005
23  */

24 package org.lobobrowser.html.domimpl;
25
26 import org.w3c.dom.*;
27
28 public abstract class CharacterDataImpl extends NodeImpl implements
29         CharacterData {
30     protected volatile String JavaDoc text;
31     
32     public CharacterDataImpl() {
33         super();
34     }
35     
36     public CharacterDataImpl(String JavaDoc text) {
37         this.text = text;
38     }
39     
40     public String JavaDoc getClassName() {
41         return "HTMLCharacterData";
42     }
43
44     public String JavaDoc getTextContent() throws DOMException {
45         return this.text;
46     }
47
48     public void setTextContent(String JavaDoc textContent) throws DOMException {
49         this.text = textContent;
50         if(!this.notificationsSuspended) {
51             this.informInvalid();
52         }
53     }
54
55     /* (non-Javadoc)
56      * @see org.xamjwg.html.domimpl.NodeImpl#cloneNode(boolean)
57      */

58     public Node cloneNode(boolean deep) {
59         CharacterDataImpl newNode = (CharacterDataImpl) super.cloneNode(deep);
60         newNode.setData(this.getData());
61         return newNode;
62     }
63
64
65     public void appendData(String JavaDoc arg) throws DOMException {
66         this.text += arg;
67         if(!this.notificationsSuspended) {
68             this.informInvalid();
69         }
70     }
71
72     public void deleteData(int offset, int count)
73             throws DOMException {
74         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(this.text);
75         StringBuffer JavaDoc result = buffer.delete(offset, offset + count);
76         this.text = result.toString();
77         if(!this.notificationsSuspended) {
78             this.informInvalid();
79         }
80     }
81
82     public String JavaDoc getData() throws DOMException {
83         return this.text;
84     }
85
86     public int getLength() {
87         return this.text.length();
88     }
89
90     public void insertData(int offset, String JavaDoc arg)
91             throws DOMException {
92         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(this.text);
93         StringBuffer JavaDoc result = buffer.insert(offset, arg);
94         this.text = result.toString();
95         if(!this.notificationsSuspended) {
96             this.informInvalid();
97         }
98     }
99
100     public void replaceData(int offset, int count, String JavaDoc arg)
101             throws DOMException {
102         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(this.text);
103         StringBuffer JavaDoc result = buffer.replace(offset, offset + count, arg);
104         this.text = result.toString();
105         if(!this.notificationsSuspended) {
106             this.informInvalid();
107         }
108     }
109
110     public void setData(String JavaDoc data) throws DOMException {
111         this.text = data;
112         if(!this.notificationsSuspended) {
113             this.informInvalid();
114         }
115     }
116
117     public String JavaDoc substringData(int offset, int count)
118             throws DOMException {
119         return this.text.substring(offset, offset + count);
120     }
121
122     public String JavaDoc toString() {
123         String JavaDoc someText = this.text;
124         int length = someText.length();
125         if(someText != null && someText.length() > 32) {
126             someText = someText.substring(0, 29) + "...";
127         }
128         return this.getNodeName() + "[length=" + length + ",text=" + someText + "]";
129     }
130     
131 }
132
Popular Tags