• 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

3.23
/src/main/java/com/meterware/httpunit/parsing/JTidyHTMLParser.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.parsing;
9

10
import com.meterware.httpunit.dom.HTMLDocumentImpl;
11

12
import java.io.ByteArrayInputStream;
13
import java.io.IOException;
14
import java.net.URL;
15
import java.nio.charset.StandardCharsets;
16

17
import org.w3c.dom.Document;
18
import org.w3c.dom.Node;
19
import org.w3c.dom.NodeList;
20
import org.w3c.dom.html.HTMLDocument;
21
import org.w3c.tidy.Tidy;
22
import org.xml.sax.SAXException;
23

24
/**
25
 * The Class JTidyHTMLParser.
26
 */
27
class JTidyHTMLParser implements HTMLParser {
1✔
28

29
    @Override
30
    public void parse(URL pageURL, String pageText, DocumentAdapter adapter) throws IOException, SAXException {
31
        Document jtidyDocument = getParser(pageURL)
×
32
                .parseDOM(new ByteArrayInputStream(pageText.getBytes(StandardCharsets.UTF_8)), null);
×
33
        HTMLDocument htmlDocument = new HTMLDocumentImpl();
×
34
        NodeList nl = jtidyDocument.getChildNodes();
×
35
        for (int i = 0; i < nl.getLength(); i++) {
×
36
            Node importedNode = nl.item(i);
×
37
            if (importedNode.getNodeType() != Node.DOCUMENT_TYPE_NODE) {
×
38
                htmlDocument.appendChild(htmlDocument.importNode(importedNode, true));
×
39
            }
40
        }
41
        adapter.setDocument(htmlDocument);
×
42
    }
×
43

44
    @Override
45
    public String getCleanedText(String string) {
46
        return string == null ? "" : string.replace(NBSP, ' ');
×
47
    }
48

49
    @Override
50
    public boolean supportsPreserveTagCase() {
51
        return false;
×
52
    }
53

54
    @Override
55
    public boolean supportsForceTagCase() {
56
        return false;
×
57
    }
58

59
    @Override
60
    public boolean supportsReturnHTMLDocument() {
61
        return true;
×
62
    }
63

64
    @Override
65
    public boolean supportsParserWarnings() {
66
        return true;
×
67
    }
68

69
    /** The Constant NBSP. */
70
    private static final char NBSP = (char) 160; // non-breaking space, defined by JTidy
71

72
    /**
73
     * get the parser of the given url.
74
     *
75
     * @param url
76
     *            the url
77
     *
78
     * @return the parser
79
     */
80
    private static Tidy getParser(URL url) {
81
        Tidy tidy = new Tidy();
×
82
        // BR 2880636 httpunit 1.7 does not work with latest Tidy release r918
83
        // tidy.setCharEncoding( org.w3c.tidy.Configuration.UTF8 );
84
        tidy.setInputEncoding("UTF8");
×
85
        tidy.setQuiet(true);
×
86
        tidy.setShowWarnings(HTMLParserFactory.isParserWarningsEnabled());
×
87
        if (!HTMLParserFactory.getHTMLParserListeners().isEmpty()) {
×
88
            tidy.setErrout(new JTidyPrintWriter(url));
×
89
        }
90
        return tidy;
×
91
    }
92

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