• 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

22.61
/src/main/java/com/meterware/httpunit/parsing/JTidyPrintWriter.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.parsing;
21

22
import java.io.PrintWriter;
23
import java.net.URL;
24
import java.text.DecimalFormat;
25
import java.text.NumberFormat;
26
import java.text.ParseException;
27
import java.util.List;
28
import java.util.StringTokenizer;
29

30
/**
31
 * Basic "parser" for the JTidy error output. Will get the line and column number as well as the message. It assumes
32
 * that an error or warning is to be logged once println() has been called or if a string starts with "line"
33
 **/
34
class JTidyPrintWriter extends PrintWriter {
35
    /**
36
     * DecimalFormat.getNumberInstance() should provide us with a proper formatter for the default locale. The integers
37
     * returned from JTidy contain the appropriate decimal separator for the current locale.
38
     */
39
    private static final NumberFormat INTEGER_FORMAT = DecimalFormat.getNumberInstance();
1✔
40

41
    /**
42
     * Instantiates a new j tidy print writer.
43
     *
44
     * @param pageURL
45
     *            the page URL
46
     */
47
    JTidyPrintWriter(URL pageURL) {
48
        super(System.out);
1✔
49
        _url = pageURL;
1✔
50
    }
1✔
51

52
    @Override
53
    public void print(boolean b) {
54
        print(String.valueOf(b));
×
55
    }
×
56

57
    @Override
58
    public void print(char c) {
59
        print(String.valueOf(c));
×
60
    }
×
61

62
    @Override
63
    public void print(char[] s) {
64
        print(String.valueOf(s));
×
65
    }
×
66

67
    @Override
68
    public void print(double d) {
69
        print(String.valueOf(d));
×
70
    }
×
71

72
    @Override
73
    public void print(float f) {
74
        print(String.valueOf(f));
×
75
    }
×
76

77
    @Override
78
    public void print(int i) {
79
        print(String.valueOf(i));
×
80
    }
×
81

82
    @Override
83
    public void print(long l) {
84
        print(String.valueOf(l));
×
85
    }
×
86

87
    @Override
88
    public void print(Object obj) {
89
        print(obj.toString());
×
90
    }
×
91

92
    /**
93
     * Detects a new log if starting with "line", a warning if message starts with "Warning" and an error if it starts
94
     * with "Error"
95
     **/
96
    @Override
97
    public void print(String s) {
98
        if (s.startsWith("line")) {
1!
99
            if (!_logged && _line > 0 && _msg != null && _msg.length() > 0) {
1!
100
                log(); // log previous!!!
×
101
            }
102
            _logged = false; // new error....
1✔
103
            StringTokenizer tok = new StringTokenizer(s);
1✔
104
            // skip first "line"
105
            tok.nextToken();
1✔
106
            // get line
107
            _line = parseInteger(tok.nextToken());
1✔
108
            // skip second "column"
109
            tok.nextToken();
1✔
110
            // get column
111
            _column = parseInteger(tok.nextToken());
1✔
112
        } else if (s.startsWith("Warning")) {
1!
113
            _error = false;
×
114
            _msg = s;
×
115
        } else if (s.startsWith("Error")) {
×
116
            _error = true;
×
117
            _msg = s;
×
118
        } else {
119
            // non structured msg
120
            _msg += s;
×
121
        }
122
    }
1✔
123

124
    /**
125
     * Parses the integer.
126
     *
127
     * @param integer
128
     *            the integer
129
     *
130
     * @return the int
131
     */
132
    private int parseInteger(String integer) {
133
        try {
134
            return INTEGER_FORMAT.parse(integer).intValue();
1✔
135
        } catch (ParseException e) {
×
136
            throw new NumberFormatException("Unable to parse integer [int: " + integer + ", error: " + e.getMessage());
×
137
        }
138
    }
139

140
    @Override
141
    public void println() {
142
        if (!_logged) {
×
143
            log();
×
144
        }
145
    }
×
146

147
    @Override
148
    public void println(boolean x) {
149
        print(String.valueOf(x));
×
150
        println();
×
151
    }
×
152

153
    @Override
154
    public void println(char c) {
155
        print(String.valueOf(c));
×
156
        println();
×
157
    }
×
158

159
    @Override
160
    public void println(char[] c) {
161
        print(String.valueOf(c));
×
162
        println();
×
163
    }
×
164

165
    @Override
166
    public void println(double d) {
167
        print(String.valueOf(d));
×
168
        println();
×
169
    }
×
170

171
    @Override
172
    public void println(float f) {
173
        print(String.valueOf(f));
×
174
        println();
×
175
    }
×
176

177
    @Override
178
    public void println(int i) {
179
        print(String.valueOf(i));
×
180
        println();
×
181
    }
×
182

183
    @Override
184
    public void println(long l) {
185
        print(String.valueOf(l));
×
186
        println();
×
187
    }
×
188

189
    @Override
190
    public void println(Object o) {
191
        print(o.toString());
×
192
        println();
×
193
    }
×
194

195
    @Override
196
    public void println(String s) {
197
        print(s);
×
198
        println();
×
199
    }
×
200

201
    // ----------------------------------------------- private members
202
    // ------------------------------------------------------
203

204
    /** The line. */
205
    private int _line = -1;
1✔
206

207
    /** The column. */
208
    private int _column = -1;
1✔
209

210
    /** The msg. */
211
    private String _msg = "";
1✔
212

213
    /** The error. */
214
    private boolean _error = false;
1✔
215

216
    /** The logged. */
217
    private boolean _logged = false;
1✔
218

219
    /** The url. */
220
    private URL _url;
221

222
    /**
223
     * reports the warning or error and then resets the current error/warning.
224
     **/
225
    private void log() {
226
        // System.out.println("Logging.........................");
227
        if (_error) {
×
228
            reportError(_msg, _line, _column);
×
229
        } else {
230
            reportWarning(_msg, _line, _column);
×
231
        }
232
        _logged = true;
×
233
        _line = -1;
×
234
        _column = -1;
×
235
        _msg = "";
×
236
    }
×
237

238
    /**
239
     * Report error.
240
     *
241
     * @param msg
242
     *            the msg
243
     * @param line
244
     *            the line
245
     * @param column
246
     *            the column
247
     */
248
    private void reportError(String msg, int line, int column) {
249
        List<HTMLParserListener> listeners = HTMLParserFactory.getHTMLParserListeners();
×
250
        for (HTMLParserListener listener : listeners) {
×
251
            listener.error(_url, msg, line, column);
×
252
        }
×
253
    }
×
254

255
    /**
256
     * Report warning.
257
     *
258
     * @param msg
259
     *            the msg
260
     * @param line
261
     *            the line
262
     * @param column
263
     *            the column
264
     */
265
    private void reportWarning(String msg, int line, int column) {
266
        List<HTMLParserListener> listeners = HTMLParserFactory.getHTMLParserListeners();
×
267
        for (HTMLParserListener listener : listeners) {
×
268
            listener.warning(_url, msg, line, column);
×
269
        }
×
270
    }
×
271
}
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