• 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

60.0
/src/main/java/com/meterware/httpunit/BlockElement.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;
9

10
import com.meterware.httpunit.scripting.ScriptableDelegate;
11
import com.meterware.httpunit.scripting.ScriptingHandler;
12

13
import java.net.URL;
14

15
import org.w3c.dom.Node;
16

17
/**
18
 * Represents a block-level element such as a paragraph or table cell, which can contain other elements.
19
 */
20
public abstract class BlockElement extends ParsedHTML implements HTMLSegment, HTMLElement {
21

22
    /** The scriptable. */
23
    private ScriptingHandler _scriptable;
24

25
    /** The node. */
26
    private Node _node;
27

28
    /**
29
     * Returns the text value of this block.
30
     */
31
    @Override
32
    public String getText() {
33
        if (_node == null) {
1!
34
            return "";
×
35
        }
36
        if (_node.getNodeType() == Node.TEXT_NODE) {
1✔
37
            return _node.getNodeValue().trim();
1✔
38
        }
39
        if (!_node.hasChildNodes()) {
1!
40
            return "";
×
41
        }
42
        return NodeUtils.asText(_node.getChildNodes()).trim();
1✔
43
    }
44

45
    /**
46
     * Returns the tag for this block.
47
     */
48
    @Override
49
    public String getTagName() {
50
        return _node == null ? "p" : _node.getNodeName();
1!
51
    }
52

53
    // -------------------------------- HTMLElement methods
54
    // ---------------------------------------
55

56
    /**
57
     * Returns the ID associated with this element. IDs are unique throughout the HTML document.
58
     */
59
    @Override
60
    public String getID() {
61
        return getAttribute("id");
1✔
62
    }
63

64
    /**
65
     * Returns the class attribute associated with this element.
66
     */
67
    @Override
68
    public String getClassName() {
69
        return getAttribute("class");
1✔
70
    }
71

72
    /**
73
     * Returns the name associated with this element.
74
     */
75
    @Override
76
    public String getName() {
77
        return getAttribute("name");
1✔
78
    }
79

80
    /**
81
     * Returns the title associated with this element.
82
     */
83
    @Override
84
    public String getTitle() {
85
        return getAttribute("title");
1✔
86
    }
87

88
    /**
89
     * Returns the delegate which supports scripting this element.
90
     */
91
    @Override
92
    public ScriptingHandler getScriptingHandler() {
93
        if (_scriptable == null) {
1!
94
            _scriptable = HttpUnitOptions.getScriptingEngine().createHandler(this);
1✔
95
        }
96
        return _scriptable;
1✔
97
    }
98

99
    /**
100
     * handle the event that has the given script attached by compiling the eventScript as a function and executing it
101
     *
102
     * @param eventScript
103
     *            - the script to use
104
     *
105
     * @deprecated since 1.7 - use doEventScript instead
106
     */
107
    @Deprecated
108
    @Override
109
    public boolean doEvent(String eventScript) {
110
        return doEventScript(eventScript);
×
111
    }
112

113
    /**
114
     * optional do the event if it's defined
115
     *
116
     * @param eventScript
117
     *            - the script to work on
118
     *
119
     * @return true if the event script was handled
120
     */
121
    @Override
122
    public boolean doEventScript(String eventScript) {
123
        return this.getScriptingHandler().doEventScript(eventScript);
×
124
    }
125

126
    @Override
127
    public boolean handleEvent(String eventName) {
128
        return this.getScriptingHandler().handleEvent(eventName);
×
129
    }
130

131
    @Override
132
    public ScriptableDelegate getParentDelegate() {
133
        return getResponse().getDocumentScriptable();
1✔
134
    }
135

136
    @Override
137
    public ScriptableDelegate newScriptable() {
138
        return new HTMLElementScriptable(this);
1✔
139
    }
140

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

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

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

176
    /**
177
     * Returns true if this element may have an attribute with the specified name.
178
     */
179
    @Override
180
    public boolean isSupportedAttribute(String name) {
181
        return false;
×
182
    }
183

184
    @Override
185
    public Node getNode() {
186
        return _node;
×
187
    }
188

189
    // ----------------------------------------------- Object methods
190
    // -------------------------------------------------------
191

192
    @Override
193
    public boolean equals(Object obj) {
194
        return getClass().equals(obj.getClass()) && equals((BlockElement) obj);
1!
195
    }
196

197
    /**
198
     * Equals.
199
     *
200
     * @param block
201
     *            the block
202
     *
203
     * @return true, if successful
204
     */
205
    private boolean equals(BlockElement block) {
206
        return _node.equals(block._node);
1✔
207
    }
208

209
    @Override
210
    public int hashCode() {
211
        return _node.hashCode();
1✔
212
    }
213

214
    // ------------------------------------- protected members
215
    // --------------------------------------------------------------
216

217
    /**
218
     * Instantiates a new block element.
219
     *
220
     * @param response
221
     *            the response
222
     * @param frame
223
     *            the frame
224
     * @param baseURL
225
     *            the base URL
226
     * @param baseTarget
227
     *            the base target
228
     * @param rootNode
229
     *            the root node
230
     * @param characterSet
231
     *            the character set
232
     */
233
    protected BlockElement(WebResponse response, FrameSelector frame, URL baseURL, String baseTarget, Node rootNode,
234
            String characterSet) {
235
        super(response, frame, baseURL, baseTarget, rootNode, characterSet);
1✔
236
        _node = rootNode;
1✔
237
    }
1✔
238

239
    /**
240
     * Gets the attribute value.
241
     *
242
     * @param node
243
     *            the node
244
     * @param attributeName
245
     *            the attribute name
246
     * @param defaultValue
247
     *            the default value
248
     *
249
     * @return the attribute value
250
     */
251
    protected int getAttributeValue(Node node, String attributeName, int defaultValue) {
252
        return NodeUtils.getAttributeValue(node, attributeName, defaultValue);
×
253
    }
254
}
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