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

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

Source file | Conditionals | Statements | Methods | TOTAL

DOMCDATA.java

0%

0%

0%

0%

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