All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jwat.tools.validators.XmlErrorHandler Maven / Gradle / Ivy

Go to download

JWAT-Tools uses the available JWAT libraries to make high level tasks available either from command-line or programmatically. Common tasks include: Test, Compress, Decompress, CDX, Arc2Warc. More specialised tasks include: Changed, ContainerMD, Delete, Extract, Interval, PathIndex, Unpack, Headers2CDX.

There is a newer version: 0.7.1
Show newest version
package org.jwat.tools.validators;

import org.jwat.common.Diagnosis;
import org.jwat.common.DiagnosisType;
import org.jwat.tools.tasks.test.TestFileResultItemDiagnosis;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class XmlErrorHandler implements ErrorHandler {

	protected TestFileResultItemDiagnosis itemDiagnosis;

	@Override
	public void fatalError(SAXParseException exception) throws SAXException {
		if (itemDiagnosis != null) {
			Diagnosis diagnosis = new Diagnosis(DiagnosisType.ERROR, "XML document",
					"Line " + exception.getLineNumber(),
					"Column " + exception.getColumnNumber(),
					exception.getMessage());
			itemDiagnosis.errors.add(diagnosis);
		} else {
			System.out.println("Line " + exception.getLineNumber() + ", Column " + exception.getColumnNumber() + ": " + exception.getMessage());
		}
	}

	@Override
	public void error(SAXParseException exception) throws SAXException {
		if (itemDiagnosis != null) {
			Diagnosis diagnosis = new Diagnosis(DiagnosisType.ERROR, "XML document",
					"Line " + exception.getLineNumber(),
					"Column " + exception.getColumnNumber(),
					exception.getMessage());
			itemDiagnosis.errors.add(diagnosis);
		} else {
			System.out.println("Line " + exception.getLineNumber() + ", Column " + exception.getColumnNumber() + ": " + exception.getMessage());
		}
	}

	@Override
	public void warning(SAXParseException exception) throws SAXException {
		if (itemDiagnosis != null) {
			Diagnosis diagnosis = new Diagnosis(DiagnosisType.ERROR, "XML document",
					"Line " + exception.getLineNumber(),
					"Column " + exception.getColumnNumber(),
					exception.getMessage());
			itemDiagnosis.warnings.add(diagnosis);
		} else {
			System.out.println("Line " + exception.getLineNumber() + ", Column " + exception.getColumnNumber() + ": " + exception.getMessage());
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy