dom4j - 1.6.1

Clover coverage report - dom4j - 1.6.1
Coverage timestamp: ma mei 16 2005 14:23:01 GMT+01:00
FRAMES NO FRAMES

file stats: | LOC: | 264 |  | Methods: | 38
| NCLOC: | 154 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

DOMText.java

0%

5,6%

7,9%

6%

1 |  | /*
2 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
3 |  | *
4 |  | * This software is open source.
5 |  | * See the bottom of this file for the licence.
6 |  | */
7 |  |
8 |  | package org.dom4j.dom;
9 |  |
10 |  | import org.dom4j.Element;
11 |  | import org.dom4j.Text;
12 |  | import org.dom4j.tree.DefaultText;
13 |  |
14 |  | import org.w3c.dom.DOMException;
15 |  | import org.w3c.dom.Document;
16 |  | import org.w3c.dom.NamedNodeMap;
17 |  | import org.w3c.dom.NodeList;
18 |  |
19 |  | /**
20 |  | * <p>
21 |  | * <code>DOMText</code> implements a Text node which supports the W3C DOM API.
22 |  | * </p>
23 |  | *
24 |  | * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
25 |  | * @version $Revision: 1.12 $
26 |  | */
27 |  | public class DOMText extends DefaultText implements org.w3c.dom.Text {
28 | 307 | public DOMText(String text) {
29 | 307 | super(text);
30 |  | }
31 |  |
32 | 0 | public DOMText(Element parent, String text) {
33 | 0 | super(parent, text);
34 |  | }
35 |  |
36 |  | // org.w3c.dom.Node interface
37 |  | // -------------------------------------------------------------------------
38 | 0 | public boolean supports(String feature, String version) {
39 | 0 | return DOMNodeHelper.supports(this, feature, version);
40 |  | }
41 |  |
42 | 0 | public String getNamespaceURI() {
43 | 0 | return DOMNodeHelper.getNamespaceURI(this);
44 |  | }
45 |  |
46 | 0 | public String getPrefix() {
47 | 0 | return DOMNodeHelper.getPrefix(this);
48 |  | }
49 |  |
50 | 0 | public void setPrefix(String prefix) throws DOMException {
51 | 0 | DOMNodeHelper.setPrefix(this, prefix);
52 |  | }
53 |  |
54 | 0 | public String getLocalName() {
55 | 0 | return DOMNodeHelper.getLocalName(this);
56 |  | }
57 |  |
58 | 0 | public String getNodeName() {
59 | 0 | return "#text";
60 |  | }
61 |  |
62 |  | // already part of API
63 |  | //
64 |  | // public short getNodeType();
65 | 73 | public String getNodeValue() throws DOMException {
66 | 73 | return DOMNodeHelper.getNodeValue(this);
67 |  | }
68 |  |
69 | 0 | public void setNodeValue(String nodeValue) throws DOMException {
70 | 0 | DOMNodeHelper.setNodeValue(this, nodeValue);
71 |  | }
72 |  |
73 | 15 | public org.w3c.dom.Node getParentNode() {
74 | 15 | return DOMNodeHelper.getParentNode(this);
75 |  | }
76 |  |
77 | 0 | public NodeList getChildNodes() {
78 | 0 | return DOMNodeHelper.getChildNodes(this);
79 |  | }
80 |  |
81 | 0 | public org.w3c.dom.Node getFirstChild() {
82 | 0 | return DOMNodeHelper.getFirstChild(this);
83 |  | }
84 |  |
85 | 0 | public org.w3c.dom.Node getLastChild() {
86 | 0 | return DOMNodeHelper.getLastChild(this);
87 |  | }
88 |  |
89 | 0 | public org.w3c.dom.Node getPreviousSibling() {
90 | 0 | return DOMNodeHelper.getPreviousSibling(this);
91 |  | }
92 |  |
93 | 0 | public org.w3c.dom.Node getNextSibling() {
94 | 0 | return DOMNodeHelper.getNextSibling(this);
95 |  | }
96 |  |
97 | 0 | public NamedNodeMap getAttributes() {
98 | 0 | return null;
99 |  | }
100 |  |
101 | 0 | public Document getOwnerDocument() {
102 | 0 | return DOMNodeHelper.getOwnerDocument(this);
103 |  | }
104 |  |
105 | 0 | public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild,
106 |  | org.w3c.dom.Node refChild) throws DOMException {
107 | 0 | checkNewChildNode(newChild);
108 |  |
109 | 0 | return DOMNodeHelper.insertBefore(this, newChild, refChild);
110 |  | }
111 |  |
112 | 0 | public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild,
113 |  | org.w3c.dom.Node oldChild) throws DOMException {
114 | 0 | checkNewChildNode(newChild);
115 |  |
116 | 0 | return DOMNodeHelper.replaceChild(this, newChild, oldChild);
117 |  | }
118 |  |
119 | 0 | public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
120 |  | throws DOMException {
121 | 0 | return DOMNodeHelper.removeChild(this, oldChild);
122 |  | }
123 |  |
124 | 0 | public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
125 |  | throws DOMException {
126 | 0 | checkNewChildNode(newChild);
127 |  |
128 | 0 | return DOMNodeHelper.appendChild(this, newChild);
129 |  | }
130 |  |
131 | 0 | private void checkNewChildNode(org.w3c.dom.Node newChild)
132 |  | throws DOMException {
133 | 0 | throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
134 |  | "Text nodes cannot have children");
135 |  | }
136 |  |
137 | 0 | public boolean hasChildNodes() {
138 | 0 | return DOMNodeHelper.hasChildNodes(this);
139 |  | }
140 |  |
141 | 0 | public org.w3c.dom.Node cloneNode(boolean deep) {
142 | 0 | return DOMNodeHelper.cloneNode(this, deep);
143 |  | }
144 |  |
145 | 0 | public void normalize() {
146 | 0 | DOMNodeHelper.normalize(this);
147 |  | }
148 |  |
149 | 0 | public boolean isSupported(String feature, String version) {
150 | 0 | return DOMNodeHelper.isSupported(this, feature, version);
151 |  | }
152 |  |
153 | 0 | public boolean hasAttributes() {
154 | 0 | return DOMNodeHelper.hasAttributes(this);
155 |  | }
156 |  |
157 |  | // org.w3c.dom.CharacterData interface
158 |  | // -------------------------------------------------------------------------
159 | 0 | public String getData() throws DOMException {
160 | 0 | return DOMNodeHelper.getData(this);
161 |  | }
162 |  |
163 | 0 | public void setData(String data) throws DOMException {
164 | 0 | DOMNodeHelper.setData(this, data);
165 |  | }
166 |  |
167 | 0 | public int getLength() {
168 | 0 | return DOMNodeHelper.getLength(this);
169 |  | }
170 |  |
171 | 0 | public String substringData(int offset, int count) throws DOMException {
172 | 0 | return DOMNodeHelper.substringData(this, offset, count);
173 |  | }
174 |  |
175 | 0 | public void appendData(String arg) throws DOMException {
176 | 0 | DOMNodeHelper.appendData(this, arg);
177 |  | }
178 |  |
179 | 0 | public void insertData(int offset, String arg) throws DOMException {
180 | 0 | DOMNodeHelper.insertData(this, offset, arg);
181 |  | }
182 |  |
183 | 0 | public void deleteData(int offset, int count) throws DOMException {
184 | 0 | DOMNodeHelper.deleteData(this, offset, count);
185 |  | }
186 |  |
187 | 0 | public void replaceData(int offset, int count, String arg)
188 |  | throws DOMException {
189 | 0 | DOMNodeHelper.replaceData(this, offset, count, arg);
190 |  | }
191 |  |
192 |  | // org.w3c.dom.Text interface
193 |  | // -------------------------------------------------------------------------
194 | 0 | public org.w3c.dom.Text splitText(int offset) throws DOMException {
195 | 0 | if (isReadOnly()) {
196 | 0 | throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
197 |  | "CharacterData node is read only: " + this);
198 |  | } else {
199 | 0 | String text = getText();
200 | 0 | int length = (text != null) ? text.length() : 0;
201 |  |
202 | 0 | if ((offset < 0) || (offset >= length)) {
203 | 0 | throw new DOMException(DOMException.INDEX_SIZE_ERR,
204 |  | "No text at offset: " + offset);
205 |  | } else {
206 | 0 | String start = text.substring(0, offset);
207 | 0 | String rest = text.substring(offset);
208 | 0 | setText(start);
209 |  |
210 | 0 | Element parent = getParent();
211 | 0 | Text newText = createText(rest);
212 |  |
213 | 0 | if (parent != null) {
214 | 0 | parent.add(newText);
215 |  | }
216 |  |
217 | 0 | return DOMNodeHelper.asDOMText(newText);
218 |  | }
219 |  | }
220 |  | }
221 |  |
222 |  | // Implementation methods
223 |  | // -------------------------------------------------------------------------
224 | 0 | protected Text createText(String text) {
225 | 0 | return new DOMText(text);
226 |  | }
227 |  | }
228 |  |
229 |  | /*
230 |  | * Redistribution and use of this software and associated documentation
231 |  | * ("Software"), with or without modification, are permitted provided that the
232 |  | * following conditions are met:
233 |  | *
234 |  | * 1. Redistributions of source code must retain copyright statements and
235 |  | * notices. Redistributions must also contain a copy of this document.
236 |  | *
237 |  | * 2. Redistributions in binary form must reproduce the above copyright notice,
238 |  | * this list of conditions and the following disclaimer in the documentation
239 |  | * and/or other materials provided with the distribution.
240 |  | *
241 |  | * 3. The name "DOM4J" must not be used to endorse or promote products derived
242 |  | * from this Software without prior written permission of MetaStuff, Ltd. For
243 |  | * written permission, please contact dom4j-info@metastuff.com.
244 |  | *
245 |  | * 4. Products derived from this Software may not be called "DOM4J" nor may
246 |  | * "DOM4J" appear in their names without prior written permission of MetaStuff,
247 |  | * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
248 |  | *
249 |  | * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
250 |  | *
251 |  | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
252 |  | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
253 |  | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
254 |  | * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
255 |  | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
256 |  | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
257 |  | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
258 |  | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
259 |  | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
260 |  | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261 |  | * POSSIBILITY OF SUCH DAMAGE.
262 |  | *
263 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
264 |  | */