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

hazendaz / httpunit / 636

05 Dec 2025 03:27AM UTC coverage: 80.509%. Remained the same
636

push

github

hazendaz
Cleanup more old since tags

you guessed it, at this point going to jautodoc the rest so the warnings on builds go away ;)

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8249 of 10132 relevant lines covered (81.42%)

0.81 hits per line

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

75.89
/src/main/java/com/meterware/httpunit/dom/ElementImpl.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.ArrayList;
23
import java.util.Hashtable;
24
import java.util.Iterator;
25

26
import org.w3c.dom.Attr;
27
import org.w3c.dom.DOMException;
28
import org.w3c.dom.Element;
29
import org.w3c.dom.NamedNodeMap;
30
import org.w3c.dom.NodeList;
31
import org.w3c.dom.TypeInfo;
32

33
public class ElementImpl extends NamespaceAwareNodeImpl implements Element {
1✔
34

35
    private static final long serialVersionUID = 1L;
36
    private Hashtable _attributes = new Hashtable<>();
1✔
37
    private ArrayList _listeners = new ArrayList<>();
1✔
38

39
    static ElementImpl createElement(DocumentImpl owner, String tagName) {
40
        ElementImpl element = new ElementImpl();
1✔
41
        element.initialize(owner, tagName);
1✔
42
        return element;
1✔
43
    }
44

45
    public static Element createElement(DocumentImpl owner, String namespaceURI, String qualifiedName) {
46
        ElementImpl element = new ElementImpl();
1✔
47
        element.initialize(owner, namespaceURI, qualifiedName);
1✔
48
        return element;
1✔
49
    }
50

51
    public void addDomListener(DomListener listener) {
52
        synchronized (_listeners) {
1✔
53
            _listeners.add(listener);
1✔
54
        }
1✔
55
    }
1✔
56

57
    protected void reportPropertyChanged(String propertyName) {
58
        ArrayList listeners;
59
        synchronized (_listeners) {
1✔
60
            listeners = (ArrayList) _listeners.clone();
1✔
61
        }
1✔
62

63
        for (Iterator each = listeners.iterator(); each.hasNext();) {
1✔
64
            ((DomListener) each.next()).propertyChanged(this, propertyName);
1✔
65
        }
66
    }
1✔
67

68
    // ---------------------------------------- Element methods
69
    // -------------------------------------------------------------
70

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

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

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

85
    @Override
86
    public boolean hasAttributes() {
87
        return !_attributes.isEmpty();
1✔
88
    }
89

90
    @Override
91
    public NamedNodeMap getAttributes() {
92
        return new NamedNodeMapImpl(_attributes);
1✔
93
    }
94

95
    /**
96
     * get the attribute with the given name
97
     *
98
     * @param name
99
     *            - the name of the attribute to get
100
     */
101
    @Override
102
    public String getAttribute(String name) {
103
        Attr attr = getAttributeNode(name);
1✔
104
        return attr == null ? "" : attr.getValue();
1✔
105
    }
106

107
    @Override
108
    public void setAttribute(String name, String value) throws DOMException {
109
        if (value.equals(getAttribute(name))) {
1!
110
            return;
×
111
        }
112

113
        Attr attribute = getOwnerDocument().createAttribute(name);
1✔
114
        attribute.setValue(value);
1✔
115
        setAttributeNode(attribute);
1✔
116
        reportPropertyChanged(name);
1✔
117
    }
1✔
118

119
    /**
120
     * get the event Handler script for the event e.g. onchange, onmousedown, onclick, onmouseup execute the script if
121
     * it's assigned by calling doEvent for the script
122
     *
123
     * @param eventName
124
     *
125
     * @return
126
     */
127
    @Override
128
    public boolean handleEvent(String eventName) {
129
        // check whether onclick is activated
130
        if (eventName.toLowerCase().equals("onclick")) {
×
131
            handleEvent("onmousedown");
×
132
        }
133
        String eventScript = getAttribute(eventName);
×
134
        boolean result = doEventScript(eventScript);
×
135
        if (eventName.toLowerCase().equals("onclick")) {
×
136
            handleEvent("onmouseup");
×
137
        }
138
        return result;
×
139
    }
140

141
    @Override
142
    public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException {
143
        Attr attribute = getOwnerDocument().createAttributeNS(namespaceURI, qualifiedName);
1✔
144
        attribute.setValue(value);
1✔
145
        setAttributeNodeNS(attribute);
1✔
146
    }
1✔
147

148
    @Override
149
    public void removeAttribute(String name) throws DOMException {
150
        _attributes.remove(name);
1✔
151
    }
1✔
152

153
    @Override
154
    public Attr getAttributeNode(String name) {
155
        return (Attr) _attributes.get(name);
1✔
156
    }
157

158
    @Override
159
    public Attr setAttributeNode(Attr newAttr) throws DOMException {
160
        if (newAttr.getOwnerDocument() != getOwnerDocument()) {
1!
161
            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
×
162
                    "attribute must be from the same document as the element");
163
        }
164

165
        ((AttrImpl) newAttr).setOwnerElement(this);
1✔
166
        AttrImpl oldAttr = (AttrImpl) _attributes.put(newAttr.getName(), newAttr);
1✔
167
        if (oldAttr != null) {
1✔
168
            oldAttr.setOwnerElement(null);
1✔
169
        }
170
        return oldAttr;
1✔
171
    }
172

173
    @Override
174
    public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
175
        if (newAttr.getOwnerDocument() != getOwnerDocument()) {
1!
176
            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
×
177
                    "attribute must be from the same document as the element");
178
        }
179

180
        ((AttrImpl) newAttr).setOwnerElement(this);
1✔
181
        AttrImpl oldAttr = (AttrImpl) _attributes.put(newAttr.getName(), newAttr);
1✔
182
        if (oldAttr != null) {
1✔
183
            oldAttr.setOwnerElement(null);
1✔
184
        }
185
        return oldAttr;
1✔
186
    }
187

188
    @Override
189
    public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
190
        if (!_attributes.containsValue(oldAttr)) {
1✔
191
            throw new DOMException(DOMException.NOT_FOUND_ERR, "Specified attribute is not defined for this element");
1✔
192
        }
193

194
        AttrImpl removedAttr = (AttrImpl) _attributes.remove(oldAttr.getName());
1✔
195
        if (removedAttr != null) {
1!
196
            removedAttr.setOwnerElement(null);
1✔
197
        }
198
        return removedAttr;
1✔
199
    }
200

201
    @Override
202
    public boolean hasAttribute(String name) {
203
        return _attributes.containsKey(name);
1✔
204
    }
205

206
    // ----------------------- namespaces are not supported at present --------------------------------
207

208
    @Override
209
    public String getAttributeNS(String namespaceURI, String localName) {
210
        return null;
×
211
    }
212

213
    @Override
214
    public void removeAttributeNS(String namespaceURI, String localName) throws DOMException {
215
    }
×
216

217
    @Override
218
    public Attr getAttributeNodeNS(String namespaceURI, String localName) {
219
        return null;
×
220
    }
221

222
    @Override
223
    public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
224
        return null;
×
225
    }
226

227
    @Override
228
    public boolean hasAttributeNS(String namespaceURI, String localName) {
229
        return false;
×
230
    }
231

232
    public static Element importNode(DocumentImpl document, Element original, boolean deep) {
233
        Element copy = document.createElementNS(original.getNamespaceURI(), original.getTagName());
1✔
234
        NamedNodeMap attributes = original.getAttributes();
1✔
235
        for (int i = 0; i < attributes.getLength(); i++) {
1✔
236
            copy.setAttributeNode((Attr) document.importNode(attributes.item(i), false));
1✔
237
        }
238
        if (deep) {
1✔
239
            document.importChildren(original, copy);
1✔
240
        }
241
        return copy;
1✔
242
    }
243

244
    // ------------------------------------- DOM level 3 methods
245
    // ------------------------------------------------------------
246

247
    @Override
248
    public TypeInfo getSchemaTypeInfo() {
249
        return null; // To change body of implemented methods use File | Settings | File Templates.
×
250
    }
251

252
    @Override
253
    public void setIdAttribute(String name, boolean isId) throws DOMException {
254
        // To change body of implemented methods use File | Settings | File Templates.
255
    }
×
256

257
    @Override
258
    public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) throws DOMException {
259
        // To change body of implemented methods use File | Settings | File Templates.
260
    }
×
261

262
    @Override
263
    public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException {
264
        // To change body of implemented methods use File | Settings | File Templates.
265
    }
×
266
}
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