• 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

59.57
/src/main/java/com/meterware/httpunit/HTMLElementBase.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;
21

22
import com.meterware.httpunit.scripting.ScriptableDelegate;
23
import com.meterware.httpunit.scripting.ScriptingHandler;
24

25
import java.util.HashSet;
26
import java.util.Set;
27

28
import org.w3c.dom.Node;
29

30
abstract class HTMLElementBase implements HTMLElement {
31

32
    private Node _node;
33
    private ScriptingHandler _scriptable;
34
    private Set _supportedAttributes = new HashSet<>();
1✔
35

36
    @Override
37
    public String getID() {
38
        return getAttribute("id");
1✔
39
    }
40

41
    @Override
42
    public String getClassName() {
43
        return getAttribute("class");
1✔
44
    }
45

46
    @Override
47
    public String getTitle() {
48
        return getAttribute("title");
1✔
49
    }
50

51
    @Override
52
    public String getName() {
53
        return getAttribute("name");
1✔
54
    }
55

56
    /**
57
     * Returns a scriptable object which can act as a proxy for this control.
58
     */
59
    @Override
60
    public ScriptingHandler getScriptingHandler() {
61
        if (_scriptable == null) {
1✔
62
            _scriptable = HttpUnitOptions.getScriptingEngine().createHandler(this);
1✔
63
        }
64
        return _scriptable;
1✔
65
    }
66

67
    /**
68
     * handle the event that has the given script attached by compiling the eventScript as a function and executing it
69
     *
70
     * @param eventScript
71
     *            - the script to use
72
     *
73
     * @deprecated since 1.7 - use doEventScript instead
74
     */
75
    @Deprecated
76
    @Override
77
    public boolean doEvent(String eventScript) {
78
        return doEventScript(eventScript);
×
79
    }
80

81
    /**
82
     * optional do the event if it's defined
83
     */
84
    @Override
85
    public boolean doEventScript(String eventScript) {
86
        return this.getScriptingHandler().doEventScript(eventScript);
×
87
    }
88

89
    @Override
90
    public boolean handleEvent(String eventName) {
91
        return this.getScriptingHandler().handleEvent(eventName);
1✔
92
    }
93

94
    /**
95
     * Returns the text value of this block.
96
     */
97
    @Override
98
    public String getText() {
99
        if (_node == null) {
×
100
            return "";
×
101
        }
102
        if (_node.getNodeType() == Node.TEXT_NODE) {
×
103
            return _node.getNodeValue().trim();
×
104
        }
105
        if (!_node.hasChildNodes()) {
×
106
            return "";
×
107
        }
108
        return NodeUtils.asText(_node.getChildNodes()).trim();
×
109
    }
110

111
    @Override
112
    public String getTagName() {
113
        return _node.getNodeName();
1✔
114
    }
115

116
    /**
117
     * construct me from a node
118
     *
119
     * @param node
120
     *            - the node to get me from
121
     */
122
    protected HTMLElementBase(Node node) {
1✔
123
        _node = node;
1✔
124
        // default attributes every html element can have
125
        supportAttribute("id");
1✔
126
        supportAttribute("class");
1✔
127
        supportAttribute("title");
1✔
128
        supportAttribute("name");
1✔
129
    }
1✔
130

131
    /**
132
     * get the Attribute with the given name - by delegating to NodeUtils
133
     *
134
     * @param name
135
     *            - the name of the attribute to get
136
     *
137
     * @return the attribute
138
     */
139
    @Override
140
    public String getAttribute(final String name) {
141
        return NodeUtils.getNodeAttribute(getNode(), name);
1✔
142
    }
143

144
    /**
145
     * set the Attribute with the given name - by delegating to NodeUtils
146
     *
147
     * @param name
148
     *            - the name of the attribute to set
149
     * @param value
150
     *            - the value to set
151
     */
152
    @Override
153
    public void setAttribute(final String name, final Object value) {
154
        NodeUtils.setNodeAttribute(getNode(), name, value == null ? null : value.toString());
1!
155
    }
1✔
156

157
    /**
158
     * remove the Attribute with the given name - by delegating to NodeUtils
159
     *
160
     * @param name
161
     *            - the name of the attribute to remove
162
     */
163
    @Override
164
    public void removeAttribute(final String name) {
165
        NodeUtils.removeNodeAttribute(getNode(), name);
×
166
    }
×
167

168
    @Override
169
    public boolean isSupportedAttribute(String name) {
170
        return _supportedAttributes.contains(name);
1✔
171
    }
172

173
    protected String getAttribute(final String name, String defaultValue) {
174
        return NodeUtils.getNodeAttribute(getNode(), name, defaultValue);
×
175
    }
176

177
    @Override
178
    public Node getNode() {
179
        return _node;
1✔
180
    }
181

182
    protected void supportAttribute(String name) {
183
        _supportedAttributes.add(name);
1✔
184
    }
1✔
185

186
    /**
187
     * Creates and returns a scriptable object for this control. Subclasses should override this if they use a different
188
     * implementation of Scriptable.
189
     */
190
    @Override
191
    public ScriptableDelegate newScriptable() {
192
        return new HTMLElementScriptable(this);
1✔
193
    }
194

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