• 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

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
    private ScriptingHandler _scriptable;
35
    private Node _node;
36

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

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

62
    // -------------------------------- HTMLElement methods
63
    // ---------------------------------------
64

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

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

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

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

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

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

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

135
    @Override
136
    public boolean handleEvent(String eventName) {
137
        return this.getScriptingHandler().handleEvent(eventName);
×
138
    }
139

140
    @Override
141
    public ScriptableDelegate getParentDelegate() {
142
        return getResponse().getDocumentScriptable();
1✔
143
    }
144

145
    @Override
146
    public ScriptableDelegate newScriptable() {
147
        return new HTMLElementScriptable(this);
1✔
148
    }
149

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

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

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

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

193
    @Override
194
    public Node getNode() {
195
        return _node;
×
196
    }
197

198
    // ----------------------------------------------- Object methods
199
    // -------------------------------------------------------
200

201
    @Override
202
    public boolean equals(Object obj) {
203
        return getClass().equals(obj.getClass()) && equals((BlockElement) obj);
1!
204
    }
205

206
    private boolean equals(BlockElement block) {
207
        return _node.equals(block._node);
1✔
208
    }
209

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

215
    // ------------------------------------- protected members
216
    // --------------------------------------------------------------
217

218
    protected BlockElement(WebResponse response, FrameSelector frame, URL baseURL, String baseTarget, Node rootNode,
219
            String characterSet) {
220
        super(response, frame, baseURL, baseTarget, rootNode, characterSet);
1✔
221
        _node = rootNode;
1✔
222
    }
1✔
223

224
    protected int getAttributeValue(Node node, String attributeName, int defaultValue) {
225
        return NodeUtils.getAttributeValue(node, attributeName, defaultValue);
×
226
    }
227
}
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