/*-
 *  Copyright 2022 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
 * 
 *  This file is part of CityDoctor2.
 *
 *  CityDoctor2 is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  CityDoctor2 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 Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with CityDoctor2.  If not, see <https://www.gnu.org/licenses/>.
 */
package de.hft.stuttgart.citydoctor2.mapper.citygml3;

import java.util.ArrayList;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXParseException;

public class GMLValidationHandler implements ErrorHandler {
	
	private static final Logger logger = LogManager.getLogger(GMLValidationHandler.class);
	private List<String> messages = new ArrayList<>();
	
	@Override
	public void error(SAXParseException exception) {
		String message = "[" + exception.getLineNumber() + ", " + exception.getColumnNumber() + "] "
				+ exception.getMessage();
		logger.error(message);
		messages.add(message);
	}

	@Override
	public void warning(SAXParseException exception) {
		String message = "[" + exception.getLineNumber() + ", " + exception.getColumnNumber() + "] "
				+ exception.getMessage();
		logger.warn(message);
		messages.add(message);
	}

	@Override
	public void fatalError(SAXParseException exception) {
		String message = "[" + exception.getLineNumber() + ", " + exception.getColumnNumber() + "] "
				+ exception.getMessage();
		logger.fatal(message);
		messages.add(message);
	}
	
	public List<String> getMessages() {
		return messages;
	}

}
