• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 343

07 Jun 2025 08:37PM UTC coverage: 80.528% (-0.06%) from 80.591%
343

push

github

hazendaz
[ci] Remove old jakarta support note from readme as now mainline

3216 of 4105 branches covered (78.34%)

Branch coverage included in aggregate %.

8252 of 10136 relevant lines covered (81.41%)

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
 * @author <a href="mailto:russgold@httpunit.org">Russell Gold</a>
33
 *
34
 * @since 1.6
35
 */
36
public abstract class BlockElement extends ParsedHTML implements HTMLSegment, HTMLElement {
37

38
    private ScriptingHandler _scriptable;
39
    private Node _node;
40

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

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

66
    // -------------------------------- HTMLElement methods
67
    // ---------------------------------------
68

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

202
    // ----------------------------------------------- Object methods
203
    // -------------------------------------------------------
204

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

210
    private boolean equals(BlockElement block) {
211
        return _node.equals(block._node);
1✔
212
    }
213

214
    @Override
215
    public int hashCode() {
216
        return _node.hashCode();
1✔
217
    }
218

219
    // ------------------------------------- protected members
220
    // --------------------------------------------------------------
221

222
    protected BlockElement(WebResponse response, FrameSelector frame, URL baseURL, String baseTarget, Node rootNode,
223
            String characterSet) {
224
        super(response, frame, baseURL, baseTarget, rootNode, characterSet);
1✔
225
        _node = rootNode;
1✔
226
    }
1✔
227

228
    protected int getAttributeValue(Node node, String attributeName, int defaultValue) {
229
        return NodeUtils.getAttributeValue(node, attributeName, defaultValue);
×
230
    }
231
}
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