• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 755

14 Feb 2026 07:14PM UTC coverage: 80.526%. Remained the same
755

push

github

hazendaz
[ci] Fix badge

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10124 relevant lines covered (81.44%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.11
/src/main/java/com/meterware/httpunit/dom/DocumentImpl.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2000-2026 Russell Gold
6
 * Copyright 2021-2000 hazendaz
7
 */
8
package com.meterware.httpunit.dom;
9

10
import java.util.Iterator;
11

12
import org.w3c.dom.Attr;
13
import org.w3c.dom.CDATASection;
14
import org.w3c.dom.Comment;
15
import org.w3c.dom.DOMConfiguration;
16
import org.w3c.dom.DOMException;
17
import org.w3c.dom.DOMImplementation;
18
import org.w3c.dom.Document;
19
import org.w3c.dom.DocumentFragment;
20
import org.w3c.dom.DocumentType;
21
import org.w3c.dom.Element;
22
import org.w3c.dom.EntityReference;
23
import org.w3c.dom.Node;
24
import org.w3c.dom.NodeList;
25
import org.w3c.dom.ProcessingInstruction;
26
import org.w3c.dom.Text;
27
import org.w3c.dom.html.HTMLElement;
28

29
/**
30
 * The Class DocumentImpl.
31
 */
32
public class DocumentImpl extends NodeImpl implements Document {
1✔
33

34
    /** The Constant serialVersionUID. */
35
    private static final long serialVersionUID = 1L;
36

37
    /** The document element. */
38
    protected Element _documentElement;
39

40
    /**
41
     * Creates the document.
42
     *
43
     * @return the document impl
44
     */
45
    static DocumentImpl createDocument() {
46
        DocumentImpl document = new DocumentImpl();
1✔
47
        document.initialize();
1✔
48
        return document;
1✔
49
    }
50

51
    /**
52
     * Initialize.
53
     */
54
    protected void initialize() {
55
    }
1✔
56

57
    @Override
58
    public String getNodeName() {
59
        return "#document";
1✔
60
    }
61

62
    @Override
63
    public String getNodeValue() throws DOMException {
64
        return null;
1✔
65
    }
66

67
    @Override
68
    public void setNodeValue(String nodeValue) throws DOMException {
69
    }
1✔
70

71
    @Override
72
    public short getNodeType() {
73
        return DOCUMENT_NODE;
1✔
74
    }
75

76
    @Override
77
    public Document getOwnerDocument() {
78
        return this;
1✔
79
    }
80

81
    @Override
82
    public DocumentType getDoctype() {
83
        return null;
×
84
    }
85

86
    @Override
87
    public DOMImplementation getImplementation() {
88
        return null;
×
89
    }
90

91
    @Override
92
    public Element getDocumentElement() {
93
        return _documentElement;
1✔
94
    }
95

96
    /**
97
     * Sets the document element.
98
     *
99
     * @param documentElement
100
     *            the new document element
101
     */
102
    void setDocumentElement(Element documentElement) {
103
        if (_documentElement != null) {
1✔
104
            throw new IllegalStateException("A document may have only one root");
1✔
105
        }
106
        _documentElement = documentElement;
1✔
107
        appendChild(documentElement);
1✔
108
    }
1✔
109

110
    @Override
111
    public Element createElement(String tagName) throws DOMException {
112
        return ElementImpl.createElement(this, tagName);
1✔
113
    }
114

115
    @Override
116
    public DocumentFragment createDocumentFragment() {
117
        throw new UnsupportedOperationException("DocumentFragment creation not supported ");
×
118
    }
119

120
    @Override
121
    public Text createTextNode(String data) {
122
        return TextImpl.createText(this, data);
1✔
123
    }
124

125
    @Override
126
    public Comment createComment(String data) {
127
        return CommentImpl.createComment(this, data);
1✔
128
    }
129

130
    @Override
131
    public CDATASection createCDATASection(String data) throws DOMException {
132
        return CDATASectionImpl.createCDATASection(this, data);
1✔
133
    }
134

135
    @Override
136
    public ProcessingInstruction createProcessingInstruction(String target, String data) throws DOMException {
137
        return ProcessingInstructionImpl.createProcessingImpl(this, target, data);
1✔
138
    }
139

140
    @Override
141
    public Attr createAttribute(String name) throws DOMException {
142
        return AttrImpl.createAttribute(this, name);
1✔
143
    }
144

145
    @Override
146
    public EntityReference createEntityReference(String name) throws DOMException {
147
        throw new UnsupportedOperationException("EntityReference creation not supported ");
×
148
    }
149

150
    @Override
151
    public Node importNode(Node importedNode, boolean deep) throws DOMException {
152
        switch (importedNode.getNodeType()) {
1!
153
            case Node.ATTRIBUTE_NODE:
154
                return AttrImpl.importNode(this, (Attr) importedNode);
1✔
155
            case Node.CDATA_SECTION_NODE:
156
                return CDATASectionImpl.importNode(this, (CDATASection) importedNode);
1✔
157
            case Node.COMMENT_NODE:
158
                return CommentImpl.importNode(this, (Comment) importedNode);
1✔
159
            case Node.ELEMENT_NODE:
160
                return ElementImpl.importNode(this, (Element) importedNode, deep);
1✔
161
            case Node.PROCESSING_INSTRUCTION_NODE:
162
                return ProcessingInstructionImpl.importNode(this, (ProcessingInstruction) importedNode);
1✔
163
            case Node.TEXT_NODE:
164
                return TextImpl.importNode(this, (Text) importedNode);
1✔
165
            default:
166
                throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
×
167
                        "Cannot import node type " + importedNode.getNodeType());
×
168
        }
169
    }
170

171
    @Override
172
    public Element getElementById(String elementId) {
173
        for (Iterator each = preOrderIterator(); each.hasNext();) {
1✔
174
            Node node = (Node) each.next();
1✔
175
            if (!(node instanceof HTMLElement)) {
1✔
176
                continue;
1✔
177
            }
178
            HTMLElement element = (HTMLElement) node;
1✔
179
            if (elementId.equals(element.getId())) {
1✔
180
                return element;
1✔
181
            }
182
        }
1✔
183
        return null;
1✔
184
    }
185

186
    @Override
187
    public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException {
188
        return ElementImpl.createElement(this, namespaceURI, qualifiedName);
1✔
189
    }
190

191
    @Override
192
    public Attr createAttributeNS(String namespaceURI, String qualifiedName) throws DOMException {
193
        return AttrImpl.createAttribute(this, namespaceURI, qualifiedName);
1✔
194
    }
195

196
    @Override
197
    public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
198
        if (namespaceURI != null) {
×
199
            throw new UnsupportedOperationException("Namespaces are not supported");
×
200
        }
201
        return getElementsByTagName(localName);
×
202
    }
203

204
    /**
205
     * import the children.
206
     *
207
     * @param original
208
     *            the original
209
     * @param copy
210
     *            the copy
211
     */
212
    void importChildren(Node original, Node copy) {
213
        NodeList children = original.getChildNodes();
1✔
214
        for (int i = 0; i < children.getLength(); i++) {
1✔
215
            Node childCopy = importNode(children.item(i), /* deep */ true);
1✔
216
            copy.appendChild(childCopy);
1✔
217
        }
218
    }
1✔
219

220
    // ------------------------------------- DOM level 3 methods
221
    // ------------------------------------------------------------
222

223
    @Override
224
    public String getInputEncoding() {
225
        return null;
×
226
    }
227

228
    @Override
229
    public String getXmlEncoding() {
230
        return null;
×
231
    }
232

233
    @Override
234
    public Node renameNode(Node n, String namespaceURI, String qualifiedName) throws DOMException {
235
        return null;
×
236
    }
237

238
    @Override
239
    public boolean getXmlStandalone() {
240
        return false;
×
241
    }
242

243
    @Override
244
    public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
245
    }
×
246

247
    @Override
248
    public String getXmlVersion() {
249
        return null;
×
250
    }
251

252
    @Override
253
    public void setXmlVersion(String xmlVersion) throws DOMException {
254
    }
×
255

256
    @Override
257
    public boolean getStrictErrorChecking() {
258
        return false;
×
259
    }
260

261
    @Override
262
    public void setStrictErrorChecking(boolean strictErrorChecking) {
263
    }
×
264

265
    @Override
266
    public String getDocumentURI() {
267
        return null;
×
268
    }
269

270
    @Override
271
    public void setDocumentURI(String documentURI) {
272
    }
×
273

274
    @Override
275
    public Node adoptNode(Node source) throws DOMException {
276
        return null;
×
277
    }
278

279
    @Override
280
    public DOMConfiguration getDomConfig() {
281
        return null;
×
282
    }
283

284
    @Override
285
    public void normalizeDocument() {
286
    }
×
287

288
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc