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

hazendaz / httpunit / 656

06 Dec 2025 09:11PM UTC coverage: 80.452% (+0.02%) from 80.435%
656

push

github

hazendaz
[maven-release-plugin] prepare for next development iteration

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10137 relevant lines covered (81.34%)

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
 * MIT License
3
 *
4
 * Copyright 2011-2025 Russell Gold
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
 * of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
 * DEALINGS IN THE SOFTWARE.
19
 */
20
package com.meterware.httpunit.dom;
21

22
import java.util.Iterator;
23

24
import org.w3c.dom.Attr;
25
import org.w3c.dom.CDATASection;
26
import org.w3c.dom.Comment;
27
import org.w3c.dom.DOMConfiguration;
28
import org.w3c.dom.DOMException;
29
import org.w3c.dom.DOMImplementation;
30
import org.w3c.dom.Document;
31
import org.w3c.dom.DocumentFragment;
32
import org.w3c.dom.DocumentType;
33
import org.w3c.dom.Element;
34
import org.w3c.dom.EntityReference;
35
import org.w3c.dom.Node;
36
import org.w3c.dom.NodeList;
37
import org.w3c.dom.ProcessingInstruction;
38
import org.w3c.dom.Text;
39
import org.w3c.dom.html.HTMLElement;
40

41
/**
42
 * The Class DocumentImpl.
43
 */
44
public class DocumentImpl extends NodeImpl implements Document {
1✔
45

46
    /** The Constant serialVersionUID. */
47
    private static final long serialVersionUID = 1L;
48

49
    /** The document element. */
50
    protected Element _documentElement;
51

52
    /**
53
     * Creates the document.
54
     *
55
     * @return the document impl
56
     */
57
    static DocumentImpl createDocument() {
58
        DocumentImpl document = new DocumentImpl();
1✔
59
        document.initialize();
1✔
60
        return document;
1✔
61
    }
62

63
    /**
64
     * Initialize.
65
     */
66
    protected void initialize() {
67
    }
1✔
68

69
    @Override
70
    public String getNodeName() {
71
        return "#document";
1✔
72
    }
73

74
    @Override
75
    public String getNodeValue() throws DOMException {
76
        return null;
1✔
77
    }
78

79
    @Override
80
    public void setNodeValue(String nodeValue) throws DOMException {
81
    }
1✔
82

83
    @Override
84
    public short getNodeType() {
85
        return DOCUMENT_NODE;
1✔
86
    }
87

88
    @Override
89
    public Document getOwnerDocument() {
90
        return this;
1✔
91
    }
92

93
    @Override
94
    public DocumentType getDoctype() {
95
        return null;
×
96
    }
97

98
    @Override
99
    public DOMImplementation getImplementation() {
100
        return null;
×
101
    }
102

103
    @Override
104
    public Element getDocumentElement() {
105
        return _documentElement;
1✔
106
    }
107

108
    /**
109
     * Sets the document element.
110
     *
111
     * @param documentElement
112
     *            the new document element
113
     */
114
    void setDocumentElement(Element documentElement) {
115
        if (_documentElement != null) {
1✔
116
            throw new IllegalStateException("A document may have only one root");
1✔
117
        }
118
        _documentElement = documentElement;
1✔
119
        appendChild(documentElement);
1✔
120
    }
1✔
121

122
    @Override
123
    public Element createElement(String tagName) throws DOMException {
124
        return ElementImpl.createElement(this, tagName);
1✔
125
    }
126

127
    @Override
128
    public DocumentFragment createDocumentFragment() {
129
        throw new UnsupportedOperationException("DocumentFragment creation not supported ");
×
130
    }
131

132
    @Override
133
    public Text createTextNode(String data) {
134
        return TextImpl.createText(this, data);
1✔
135
    }
136

137
    @Override
138
    public Comment createComment(String data) {
139
        return CommentImpl.createComment(this, data);
1✔
140
    }
141

142
    @Override
143
    public CDATASection createCDATASection(String data) throws DOMException {
144
        return CDATASectionImpl.createCDATASection(this, data);
1✔
145
    }
146

147
    @Override
148
    public ProcessingInstruction createProcessingInstruction(String target, String data) throws DOMException {
149
        return ProcessingInstructionImpl.createProcessingImpl(this, target, data);
1✔
150
    }
151

152
    @Override
153
    public Attr createAttribute(String name) throws DOMException {
154
        return AttrImpl.createAttribute(this, name);
1✔
155
    }
156

157
    @Override
158
    public EntityReference createEntityReference(String name) throws DOMException {
159
        throw new UnsupportedOperationException("EntityReference creation not supported ");
×
160
    }
161

162
    @Override
163
    public Node importNode(Node importedNode, boolean deep) throws DOMException {
164
        switch (importedNode.getNodeType()) {
1!
165
            case Node.ATTRIBUTE_NODE:
166
                return AttrImpl.importNode(this, (Attr) importedNode);
1✔
167
            case Node.CDATA_SECTION_NODE:
168
                return CDATASectionImpl.importNode(this, (CDATASection) importedNode);
1✔
169
            case Node.COMMENT_NODE:
170
                return CommentImpl.importNode(this, (Comment) importedNode);
1✔
171
            case Node.ELEMENT_NODE:
172
                return ElementImpl.importNode(this, (Element) importedNode, deep);
1✔
173
            case Node.PROCESSING_INSTRUCTION_NODE:
174
                return ProcessingInstructionImpl.importNode(this, (ProcessingInstruction) importedNode);
1✔
175
            case Node.TEXT_NODE:
176
                return TextImpl.importNode(this, (Text) importedNode);
1✔
177
            default:
178
                throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
×
179
                        "Cannot import node type " + importedNode.getNodeType());
×
180
        }
181
    }
182

183
    @Override
184
    public Element getElementById(String elementId) {
185
        for (Iterator each = preOrderIterator(); each.hasNext();) {
1✔
186
            Node node = (Node) each.next();
1✔
187
            if (!(node instanceof HTMLElement)) {
1✔
188
                continue;
1✔
189
            }
190
            HTMLElement element = (HTMLElement) node;
1✔
191
            if (elementId.equals(element.getId())) {
1✔
192
                return element;
1✔
193
            }
194
        }
1✔
195
        return null;
1✔
196
    }
197

198
    @Override
199
    public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException {
200
        return ElementImpl.createElement(this, namespaceURI, qualifiedName);
1✔
201
    }
202

203
    @Override
204
    public Attr createAttributeNS(String namespaceURI, String qualifiedName) throws DOMException {
205
        return AttrImpl.createAttribute(this, namespaceURI, qualifiedName);
1✔
206
    }
207

208
    @Override
209
    public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
210
        if (namespaceURI != null) {
×
211
            throw new UnsupportedOperationException("Namespaces are not supported");
×
212
        }
213
        return getElementsByTagName(localName);
×
214
    }
215

216
    /**
217
     * import the children.
218
     *
219
     * @param original
220
     *            the original
221
     * @param copy
222
     *            the copy
223
     */
224
    void importChildren(Node original, Node copy) {
225
        NodeList children = original.getChildNodes();
1✔
226
        for (int i = 0; i < children.getLength(); i++) {
1✔
227
            Node childCopy = importNode(children.item(i), /* deep */ true);
1✔
228
            copy.appendChild(childCopy);
1✔
229
        }
230
    }
1✔
231

232
    // ------------------------------------- DOM level 3 methods
233
    // ------------------------------------------------------------
234

235
    @Override
236
    public String getInputEncoding() {
237
        return null;
×
238
    }
239

240
    @Override
241
    public String getXmlEncoding() {
242
        return null;
×
243
    }
244

245
    @Override
246
    public Node renameNode(Node n, String namespaceURI, String qualifiedName) throws DOMException {
247
        return null;
×
248
    }
249

250
    @Override
251
    public boolean getXmlStandalone() {
252
        return false;
×
253
    }
254

255
    @Override
256
    public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
257
    }
×
258

259
    @Override
260
    public String getXmlVersion() {
261
        return null;
×
262
    }
263

264
    @Override
265
    public void setXmlVersion(String xmlVersion) throws DOMException {
266
    }
×
267

268
    @Override
269
    public boolean getStrictErrorChecking() {
270
        return false;
×
271
    }
272

273
    @Override
274
    public void setStrictErrorChecking(boolean strictErrorChecking) {
275
    }
×
276

277
    @Override
278
    public String getDocumentURI() {
279
        return null;
×
280
    }
281

282
    @Override
283
    public void setDocumentURI(String documentURI) {
284
    }
×
285

286
    @Override
287
    public Node adoptNode(Node source) throws DOMException {
288
        return null;
×
289
    }
290

291
    @Override
292
    public DOMConfiguration getDomConfig() {
293
        return null;
×
294
    }
295

296
    @Override
297
    public void normalizeDocument() {
298
    }
×
299

300
}
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