01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.kuali.kfs.exceptions;
18:
19: import org.apache.commons.logging.Log;
20: import org.apache.commons.logging.LogFactory;
21: import org.xml.sax.ErrorHandler;
22: import org.xml.sax.SAXParseException;
23:
24: /**
25: * Defines exception-handling for the XML parses
26: */
27: public class XmlErrorHandler implements ErrorHandler {
28: private static Log LOG = LogFactory.getLog(XmlErrorHandler.class);
29:
30: public XmlErrorHandler() {
31: }
32:
33: public void warning(SAXParseException e) {
34: String parseMessage = assembleMessage("warning", e);
35: LOG.error(parseMessage);
36: throw new XMLParseException(parseMessage, e);
37: }
38:
39: public void error(SAXParseException e) {
40: String parseMessage = assembleMessage("error", e);
41: LOG.error(parseMessage);
42: throw new XMLParseException(parseMessage, e);
43: }
44:
45: public void fatalError(SAXParseException e) {
46: String parseMessage = assembleMessage("fatal error", e);
47: LOG.error(parseMessage);
48: throw new XMLParseException(parseMessage, e);
49: }
50:
51: private String assembleMessage(String messageType,
52: SAXParseException e) {
53: StringBuffer message = new StringBuffer(messageType);
54: message.append(" Parsing error was encountered on line ");
55: message.append(e.getLineNumber());
56: message.append(", column ");
57: message.append(e.getColumnNumber());
58: message.append(": ");
59: message.append(e.getMessage());
60:
61: return message.toString();
62: }
63: }
|