1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.ole.exception;
18
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 import org.xml.sax.ErrorHandler;
23 import org.xml.sax.SAXParseException;
24
25
26
27
28 public class XmlErrorHandler implements ErrorHandler {
29
30 private static Logger LOG = LoggerFactory.getLogger(XmlErrorHandler.class);
31
32
33
34
35 public XmlErrorHandler() {
36 }
37
38
39
40
41
42 public void warning(SAXParseException e) {
43 String parseMessage = assembleMessage("warning", e);
44 LOG.error(parseMessage);
45 throw new ParseException(parseMessage, e);
46 }
47
48
49
50
51
52 public void error(SAXParseException e) {
53 String parseMessage = assembleMessage("error", e);
54 LOG.error(parseMessage);
55 throw new ParseException(parseMessage, e);
56 }
57
58
59
60
61
62 public void fatalError(SAXParseException e) {
63 String parseMessage = assembleMessage("fatal error", e);
64 LOG.error(parseMessage);
65 throw new ParseException(parseMessage, e);
66 }
67
68
69
70
71
72
73
74 private String assembleMessage(String messageType, SAXParseException e) {
75 StringBuffer message = new StringBuffer(messageType);
76 message.append(" Parsing error was encountered on line ");
77 message.append(e.getLineNumber());
78 message.append(", column ");
79 message.append(e.getColumnNumber());
80 message.append(": ");
81 message.append(e.getMessage());
82
83 return message.toString();
84 }
85 }