• 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

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
/**
31
 * The Class HTMLElementBase.
32
 */
33
abstract class HTMLElementBase implements HTMLElement {
34

35
    /** The node. */
36
    private Node _node;
37

38
    /** The scriptable. */
39
    private ScriptingHandler _scriptable;
40

41
    /** The supported attributes. */
42
    private Set _supportedAttributes = new HashSet<>();
1✔
43

44
    @Override
45
    public String getID() {
46
        return getAttribute("id");
1✔
47
    }
48

49
    @Override
50
    public String getClassName() {
51
        return getAttribute("class");
1✔
52
    }
53

54
    @Override
55
    public String getTitle() {
56
        return getAttribute("title");
1✔
57
    }
58

59
    @Override
60
    public String getName() {
61
        return getAttribute("name");
1✔
62
    }
63

64
    /**
65
     * Returns a scriptable object which can act as a proxy for this control.
66
     */
67
    @Override
68
    public ScriptingHandler getScriptingHandler() {
69
        if (_scriptable == null) {
1✔
70
            _scriptable = HttpUnitOptions.getScriptingEngine().createHandler(this);
1✔
71
        }
72
        return _scriptable;
1✔
73
    }
74

75
    /**
76
     * handle the event that has the given script attached by compiling the eventScript as a function and executing it
77
     *
78
     * @param eventScript
79
     *            - the script to use
80
     *
81
     * @deprecated since 1.7 - use doEventScript instead
82
     */
83
    @Deprecated
84
    @Override
85
    public boolean doEvent(String eventScript) {
86
        return doEventScript(eventScript);
×
87
    }
88

89
    /**
90
     * optional do the event if it's defined
91
     */
92
    @Override
93
    public boolean doEventScript(String eventScript) {
94
        return this.getScriptingHandler().doEventScript(eventScript);
×
95
    }
96

97
    @Override
98
    public boolean handleEvent(String eventName) {
99
        return this.getScriptingHandler().handleEvent(eventName);
1✔
100
    }
101

102
    /**
103
     * Returns the text value of this block.
104
     */
105
    @Override
106
    public String getText() {
107
        if (_node == null) {
×
108
            return "";
×
109
        }
110
        if (_node.getNodeType() == Node.TEXT_NODE) {
×
111
            return _node.getNodeValue().trim();
×
112
        }
113
        if (!_node.hasChildNodes()) {
×
114
            return "";
×
115
        }
116
        return NodeUtils.asText(_node.getChildNodes()).trim();
×
117
    }
118

119
    @Override
120
    public String getTagName() {
121
        return _node.getNodeName();
1✔
122
    }
123

124
    /**
125
     * construct me from a node.
126
     *
127
     * @param node
128
     *            - the node to get me from
129
     */
130
    protected HTMLElementBase(Node node) {
1✔
131
        _node = node;
1✔
132
        // default attributes every html element can have
133
        supportAttribute("id");
1✔
134
        supportAttribute("class");
1✔
135
        supportAttribute("title");
1✔
136
        supportAttribute("name");
1✔
137
    }
1✔
138

139
    /**
140
     * get the Attribute with the given name - by delegating to NodeUtils
141
     *
142
     * @param name
143
     *            - the name of the attribute to get
144
     *
145
     * @return the attribute
146
     */
147
    @Override
148
    public String getAttribute(final String name) {
149
        return NodeUtils.getNodeAttribute(getNode(), name);
1✔
150
    }
151

152
    /**
153
     * set the Attribute with the given name - by delegating to NodeUtils
154
     *
155
     * @param name
156
     *            - the name of the attribute to set
157
     * @param value
158
     *            - the value to set
159
     */
160
    @Override
161
    public void setAttribute(final String name, final Object value) {
162
        NodeUtils.setNodeAttribute(getNode(), name, value == null ? null : value.toString());
1!
163
    }
1✔
164

165
    /**
166
     * remove the Attribute with the given name - by delegating to NodeUtils
167
     *
168
     * @param name
169
     *            - the name of the attribute to remove
170
     */
171
    @Override
172
    public void removeAttribute(final String name) {
173
        NodeUtils.removeNodeAttribute(getNode(), name);
×
174
    }
×
175

176
    @Override
177
    public boolean isSupportedAttribute(String name) {
178
        return _supportedAttributes.contains(name);
1✔
179
    }
180

181
    /**
182
     * Gets the attribute.
183
     *
184
     * @param name
185
     *            the name
186
     * @param defaultValue
187
     *            the default value
188
     *
189
     * @return the attribute
190
     */
191
    protected String getAttribute(final String name, String defaultValue) {
192
        return NodeUtils.getNodeAttribute(getNode(), name, defaultValue);
×
193
    }
194

195
    @Override
196
    public Node getNode() {
197
        return _node;
1✔
198
    }
199

200
    /**
201
     * Support attribute.
202
     *
203
     * @param name
204
     *            the name
205
     */
206
    protected void supportAttribute(String name) {
207
        _supportedAttributes.add(name);
1✔
208
    }
1✔
209

210
    /**
211
     * Creates and returns a scriptable object for this control. Subclasses should override this if they use a different
212
     * implementation of Scriptable.
213
     */
214
    @Override
215
    public ScriptableDelegate newScriptable() {
216
        return new HTMLElementScriptable(this);
1✔
217
    }
218

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