1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit;
16
17 import java.io.Serializable;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.htmlunit.cssparser.parser.CSSErrorHandler;
22 import org.htmlunit.cssparser.parser.CSSParseException;
23
24
25
26
27
28
29
30
31 public class DefaultCssErrorHandler implements CSSErrorHandler, Serializable {
32
33 private static final Log LOG = LogFactory.getLog(DefaultCssErrorHandler.class);
34
35
36
37
38 @Override
39 public void error(final CSSParseException exception) {
40 if (LOG.isWarnEnabled()) {
41 LOG.warn("CSS error: " + buildMessage(exception));
42 }
43 }
44
45
46
47
48 @Override
49 public void fatalError(final CSSParseException exception) {
50 if (LOG.isWarnEnabled()) {
51 LOG.warn("CSS fatal error: " + buildMessage(exception));
52 }
53 }
54
55
56
57
58 @Override
59 public void warning(final CSSParseException exception) {
60 if (LOG.isWarnEnabled()) {
61 LOG.warn("CSS warning: " + buildMessage(exception));
62 }
63 }
64
65
66
67
68
69
70 private static String buildMessage(final CSSParseException exception) {
71 final String uri = exception.getURI();
72 final int line = exception.getLineNumber();
73 final int col = exception.getColumnNumber();
74
75 if (null == uri) {
76 return "[" + line + ":" + col + "] " + exception.getMessage();
77 }
78 return "'" + uri + "' [" + line + ":" + col + "] " + exception.getMessage();
79 }
80 }