/* $Id: SaxErrorHandler.java,v 1.9 2005/10/17 17:14:02 m31 Exp $
 *
 * This file is part of the project "Hilbert II" - http://www.qedeq.org
 *
 * Copyright 2000-2005,  Michael Meyling <mime@qedeq.org>.
 *
 * "Hilbert II" is free software; you can redistribute
 * it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 */

package org.qedeq.kernel.xml.parser;

import java.io.File;

import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;


/**
 * Error handler for XML parsing.
 *
 * @version $Revision: 1.9 $
 * @author  Michael Meyling
 */
public final class SaxErrorHandler implements ErrorHandler {

    /** File that is parsed. */
    private final File file;

    /** Collects errors. */
    private final ExceptionList list;

    /**
     * Constructor.
     *
     * @param   file    File that is parsed.
     * @param   list    Collector for the SAX exceptions.
     */
    public SaxErrorHandler(final File file, final ExceptionList list) {
        super();
        this.file = file;
        this.list = list;
    }


    /* (non-Javadoc)
     * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
     */
    public final void warning(final SAXParseException e) throws SAXException {
        list.add(new SyntaxException(e, file));
    }

    /* (non-Javadoc)
     * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
     */
    public final void error(final SAXParseException e) throws SAXException {
        list.add(new SyntaxException(e, file));
    }

    /* (non-Javadoc)
     * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
     */
    public final void fatalError(final SAXParseException e) throws SAXException {
        list.add(new SyntaxException(e, file));
        throw e;
    }

}
