1
/* $Revision: 7636 $ $Author: egonw $ $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
3
* Copyright (C) 1997-2007 Egon Willighagen <egonw@users.sf.net>
5
* Contact: cdk-devel@lists.sourceforge.net
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public License
9
* as published by the Free Software Foundation; either version 2.1
10
* of the License, or (at your option) any later version.
11
* All we ask is that proper credit is given for our work, which includes
12
* - but is not limited to - adding the above copyright notice to the beginning
13
* of your source code files, and to any copyright notice that you may distribute
14
* with programs based on this work.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Lesser General Public License for more details.
21
* You should have received a copy of the GNU Lesser General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26
package org.openscience.cdk.io.cml;
28
import org.openscience.cdk.tools.LoggingTool;
29
import org.xml.sax.ErrorHandler;
30
import org.xml.sax.SAXException;
31
import org.xml.sax.SAXParseException;
34
* CDK's SAX2 ErrorHandler for giving feedback on XML errors in the CML document.
35
* Output is redirected to org.openscience.cdk.tools.LoggingTool.
39
* @author Egon Willighagen <egonw@sci.kun.nl>
41
public class CMLErrorHandler implements ErrorHandler {
43
private LoggingTool logger;
45
public boolean reportErrors = true;
46
public boolean abortOnErrors = false;
49
* Constructor a SAX2 ErrorHandler that uses the cdk.tools.LoggingTool
50
* class to output errors and warnings to.
52
public CMLErrorHandler() {
53
logger = new LoggingTool(this);
54
logger.info("instantiated");
58
* Internal procedure that outputs an SAXParseException with a significance level
59
* to the cdk.tools.LoggingTool logger.
61
* @param level significance level
62
* @param exception Exception to output
64
private void print (String level, SAXParseException exception) {
65
if (level.equals("warning")) {
66
logger.warn("** " + level + ": " + exception.getMessage ());
67
logger.warn(" URI = " + exception.getSystemId ());
68
logger.warn(" line = " + exception.getLineNumber ());
70
logger.error("** " + level + ": " + exception.getMessage ());
71
logger.error(" URI = " + exception.getSystemId ());
72
logger.error(" line = " + exception.getLineNumber ());
76
// for recoverable errors, like validity problems
79
* Outputs a SAXParseException error to the logger.
81
* @param exception Exception to output
83
public void error (SAXParseException exception) throws SAXException {
84
if (reportErrors) print("error", exception);
85
if (abortOnErrors) throw exception;
89
* Outputs as fatal SAXParseException error to the logger.
91
* @param exception Exception to output
93
public void fatalError (SAXParseException exception) throws SAXException {
94
if (reportErrors) print("fatal", exception);
95
if (abortOnErrors) throw exception;
99
* Outputs a SAXParseException warning to the logger.
101
* @param exception Exception to output
103
public void warning (SAXParseException exception) throws SAXException {
104
if (reportErrors) print("warning", exception);