01: /*
02: * Copyright 2005-2006 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.core.datadictionary;
18:
19: import org.apache.commons.logging.Log;
20: import org.apache.commons.logging.LogFactory;
21: import org.kuali.core.datadictionary.exception.ParseException;
22: import org.xml.sax.ErrorHandler;
23: import org.xml.sax.SAXParseException;
24:
25: /**
26: * Defines exception-handling for the XML parses used by the DataDictionaryBuilder's Digester
27: *
28: *
29: */
30: public class XmlErrorHandler implements ErrorHandler {
31: // logger
32: private static Log LOG = LogFactory.getLog(XmlErrorHandler.class);
33:
34: private final String fileName;
35:
36: public XmlErrorHandler(String fileName) {
37: this .fileName = fileName;
38: }
39:
40: public void warning(SAXParseException e) {
41: String parseMessage = assembleMessage("warning", e);
42: LOG.error(parseMessage);
43: throw new ParseException(parseMessage, e);
44: }
45:
46: public void error(SAXParseException e) {
47: String parseMessage = assembleMessage("error", e);
48: LOG.error(parseMessage);
49: throw new ParseException(parseMessage, e);
50: }
51:
52: public void fatalError(SAXParseException e) {
53: String parseMessage = assembleMessage("fatal error", e);
54: LOG.error(parseMessage);
55: throw new ParseException(parseMessage, e);
56: }
57:
58: private String assembleMessage(String messageType,
59: SAXParseException e) {
60: StringBuffer message = new StringBuffer(messageType);
61: message.append(" parsing dataDictionary input file '");
62: message.append(fileName);
63: message.append("' , line ");
64: message.append(e.getLineNumber());
65: message.append(", column ");
66: message.append(e.getColumnNumber());
67: message.append(":");
68: message.append(e.getMessage());
69:
70: return message.toString();
71: }
72: }
|