• 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

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

27
import org.w3c.dom.Node;
28

29
/**
30
 * Represents a block-level element such as a paragraph or table cell, which can contain other elements.
31
 */
32
public abstract class BlockElement extends ParsedHTML implements HTMLSegment, HTMLElement {
33

34
    /** The scriptable. */
35
    private ScriptingHandler _scriptable;
36

37
    /** The node. */
38
    private Node _node;
39

40
    /**
41
     * Returns the text value of this block.
42
     */
43
    @Override
44
    public String getText() {
45
        if (_node == null) {
1!
46
            return "";
×
47
        }
48
        if (_node.getNodeType() == Node.TEXT_NODE) {
1✔
49
            return _node.getNodeValue().trim();
1✔
50
        }
51
        if (!_node.hasChildNodes()) {
1!
52
            return "";
×
53
        }
54
        return NodeUtils.asText(_node.getChildNodes()).trim();
1✔
55
    }
56

57
    /**
58
     * Returns the tag for this block.
59
     */
60
    @Override
61
    public String getTagName() {
62
        return _node == null ? "p" : _node.getNodeName();
1!
63
    }
64

65
    // -------------------------------- HTMLElement methods
66
    // ---------------------------------------
67

68
    /**
69
     * Returns the ID associated with this element. IDs are unique throughout the HTML document.
70
     */
71
    @Override
72
    public String getID() {
73
        return getAttribute("id");
1✔
74
    }
75

76
    /**
77
     * Returns the class attribute associated with this element.
78
     */
79
    @Override
80
    public String getClassName() {
81
        return getAttribute("class");
1✔
82
    }
83

84
    /**
85
     * Returns the name associated with this element.
86
     */
87
    @Override
88
    public String getName() {
89
        return getAttribute("name");
1✔
90
    }
91

92
    /**
93
     * Returns the title associated with this element.
94
     */
95
    @Override
96
    public String getTitle() {
97
        return getAttribute("title");
1✔
98
    }
99

100
    /**
101
     * Returns the delegate which supports scripting this element.
102
     */
103
    @Override
104
    public ScriptingHandler getScriptingHandler() {
105
        if (_scriptable == null) {
1!
106
            _scriptable = HttpUnitOptions.getScriptingEngine().createHandler(this);
1✔
107
        }
108
        return _scriptable;
1✔
109
    }
110

111
    /**
112
     * handle the event that has the given script attached by compiling the eventScript as a function and executing it
113
     *
114
     * @param eventScript
115
     *            - the script to use
116
     *
117
     * @deprecated since 1.7 - use doEventScript instead
118
     */
119
    @Deprecated
120
    @Override
121
    public boolean doEvent(String eventScript) {
122
        return doEventScript(eventScript);
×
123
    }
124

125
    /**
126
     * optional do the event if it's defined
127
     *
128
     * @param eventScript
129
     *            - the script to work on
130
     *
131
     * @return true if the event script was handled
132
     */
133
    @Override
134
    public boolean doEventScript(String eventScript) {
135
        return this.getScriptingHandler().doEventScript(eventScript);
×
136
    }
137

138
    @Override
139
    public boolean handleEvent(String eventName) {
140
        return this.getScriptingHandler().handleEvent(eventName);
×
141
    }
142

143
    @Override
144
    public ScriptableDelegate getParentDelegate() {
145
        return getResponse().getDocumentScriptable();
1✔
146
    }
147

148
    @Override
149
    public ScriptableDelegate newScriptable() {
150
        return new HTMLElementScriptable(this);
1✔
151
    }
152

153
    /**
154
     * get the attribute with the given name
155
     *
156
     * @param name
157
     *            - the name of the attribute to get
158
     */
159
    @Override
160
    public String getAttribute(final String name) {
161
        return NodeUtils.getNodeAttribute(_node, name);
1✔
162
    }
163

164
    /**
165
     * set the attribute with the given name to the given value
166
     *
167
     * @param name
168
     *            - the name of the attribute to set
169
     * @param value
170
     *            - the value to use
171
     */
172
    @Override
173
    public void setAttribute(final String name, final Object value) {
174
        NodeUtils.setNodeAttribute(_node, name, value == null ? null : value.toString());
×
175
    }
×
176

177
    /**
178
     * remove the attribute with the given name
179
     *
180
     * @param name
181
     *            - the name of the attribute
182
     */
183
    @Override
184
    public void removeAttribute(final String name) {
185
        NodeUtils.removeNodeAttribute(_node, name);
×
186
    }
×
187

188
    /**
189
     * Returns true if this element may have an attribute with the specified name.
190
     */
191
    @Override
192
    public boolean isSupportedAttribute(String name) {
193
        return false;
×
194
    }
195

196
    @Override
197
    public Node getNode() {
198
        return _node;
×
199
    }
200

201
    // ----------------------------------------------- Object methods
202
    // -------------------------------------------------------
203

204
    @Override
205
    public boolean equals(Object obj) {
206
        return getClass().equals(obj.getClass()) && equals((BlockElement) obj);
1!
207
    }
208

209
    /**
210
     * Equals.
211
     *
212
     * @param block
213
     *            the block
214
     *
215
     * @return true, if successful
216
     */
217
    private boolean equals(BlockElement block) {
218
        return _node.equals(block._node);
1✔
219
    }
220

221
    @Override
222
    public int hashCode() {
223
        return _node.hashCode();
1✔
224
    }
225

226
    // ------------------------------------- protected members
227
    // --------------------------------------------------------------
228

229
    /**
230
     * Instantiates a new block element.
231
     *
232
     * @param response
233
     *            the response
234
     * @param frame
235
     *            the frame
236
     * @param baseURL
237
     *            the base URL
238
     * @param baseTarget
239
     *            the base target
240
     * @param rootNode
241
     *            the root node
242
     * @param characterSet
243
     *            the character set
244
     */
245
    protected BlockElement(WebResponse response, FrameSelector frame, URL baseURL, String baseTarget, Node rootNode,
246
            String characterSet) {
247
        super(response, frame, baseURL, baseTarget, rootNode, characterSet);
1✔
248
        _node = rootNode;
1✔
249
    }
1✔
250

251
    /**
252
     * Gets the attribute value.
253
     *
254
     * @param node
255
     *            the node
256
     * @param attributeName
257
     *            the attribute name
258
     * @param defaultValue
259
     *            the default value
260
     *
261
     * @return the attribute value
262
     */
263
    protected int getAttributeValue(Node node, String attributeName, int defaultValue) {
264
        return NodeUtils.getAttributeValue(node, attributeName, defaultValue);
×
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