KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xml > QCharacterData


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.xml;
30
31 import org.w3c.dom.CharacterData JavaDoc;
32 import org.w3c.dom.DOMException JavaDoc;
33
34 import java.io.IOException JavaDoc;
35
36 abstract class QCharacterData extends QAbstractNode implements CharacterData JavaDoc {
37   protected String JavaDoc _data;
38   protected boolean _whitespaceOnly;
39
40   /**
41    * Creates new character data with initial data.
42    */

43   QCharacterData()
44   {
45   }
46
47   /**
48    * Creates new character data with initial data.
49    */

50   QCharacterData(String JavaDoc data)
51   {
52     _data = data;
53   }
54
55   /**
56    * Returns the node value. For QCharacterData, this is the text value.
57    */

58   public String JavaDoc getNodeValue()
59   {
60     return _data;
61   }
62
63   /**
64    * Sets the node value. For QCharacterData, this is the text value.
65    */

66   public void setNodeValue(String JavaDoc data)
67   {
68     _data = data;
69   }
70
71   /**
72    * Returns the node value. For QCharacterData, this is the text value.
73    */

74   public String JavaDoc getData()
75   {
76     return _data;
77   }
78
79   /**
80    * Sets the node value. For QCharacterData, this is the text value.
81    */

82   public void setData(String JavaDoc data)
83   {
84     _data = data;
85   }
86
87   /**
88    * Returns the length of the text data.
89    */

90   public int getLength()
91   {
92     return _data.length();
93   }
94
95   public String JavaDoc substringData(int start, int count)
96     throws DOMException JavaDoc
97   {
98     if (start + count >= _data.length())
99       return _data.substring(start);
100     else
101       return _data.substring(start, start + count);
102   }
103
104   public String JavaDoc substringData(int start)
105     throws DOMException JavaDoc
106   {
107     return _data.substring(start);
108   }
109
110   public void appendData(String JavaDoc arg)
111     throws DOMException JavaDoc
112   {
113     _data = _data + arg;
114   }
115
116   public void insertData(int offset, String JavaDoc arg)
117     throws DOMException JavaDoc
118   {
119     _data = _data.substring(0, offset) + arg + _data.substring(offset);
120   }
121
122   public void deleteData(int offset, int count)
123     throws DOMException JavaDoc
124   {
125     if (_data.length() <= offset + count)
126       _data = _data.substring(0, offset);
127     else
128       _data = _data.substring(0, offset) + _data.substring(offset + count);
129   }
130
131   public void deleteData(int offset)
132     throws DOMException JavaDoc
133   {
134     _data = _data.substring(0, offset);
135   }
136
137   public void replaceData(int offset, int count, String JavaDoc arg)
138     throws DOMException JavaDoc
139   {
140     if (_data.length() <= offset + count)
141       _data = _data.substring(0, offset) + arg;
142     else
143       _data = _data.substring(0, offset) + arg + _data.substring(offset + count);
144   }
145
146   public boolean hasContent()
147   {
148     for (int i = 0; i < _data.length(); i++)
149       if (! Character.isWhitespace(_data.charAt(i)))
150     return true;
151
152     return false;
153   }
154
155   public boolean isElementContentWhitespace()
156   {
157     for (int i = 0; i < _data.length(); i++)
158       if (! Character.isWhitespace(_data.charAt(i)))
159     return false;
160
161     return true;
162   }
163
164   public void print(XmlPrinter os) throws IOException JavaDoc
165   {
166     os.text(getData());
167   }
168 }
169
Popular Tags