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 public XmlErrorHandler() {
33 }
34
35 public void warning(SAXParseException e) {
36 String parseMessage = assembleMessage("warning", e);
37 LOG.error(parseMessage);
38 throw new ParseException(parseMessage, e);
39 }
40
41 public void error(SAXParseException e) {
42 String parseMessage = assembleMessage("error", e);
43 LOG.error(parseMessage);
44 throw new ParseException(parseMessage, e);
45 }
46
47 public void fatalError(SAXParseException e) {
48 String parseMessage = assembleMessage("fatal error", e);
49 LOG.error(parseMessage);
50 throw new ParseException(parseMessage, e);
51 }
52
53 private String assembleMessage(String messageType, SAXParseException e) {
54 StringBuffer message = new StringBuffer(messageType);
55 message.append(" Parsing error was encountered on line ");
56 message.append(e.getLineNumber());
57 message.append(", column ");
58 message.append(e.getColumnNumber());
59 message.append(": ");
60 message.append(e.getMessage());
61
62 return message.toString();
63 }
64 }