![JAR search and dependency download from the Maven repository](/logo.png)
net.anotheria.asg.generator.validation.XMLAgainstXSDErrorHandler Maven / Gradle / Ivy
package net.anotheria.asg.generator.validation;
import net.anotheria.asg.generator.util.IncludeDocumentsBean;
import net.anotheria.asg.generator.util.IncludedDocuments;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
/**
* XMLAgainstXSDErrorHandler class.
*
* @author vzarva
* @version $Id: $Id
*/
public class XMLAgainstXSDErrorHandler extends DefaultHandler{
private boolean hasErrors = false;
private IncludedDocuments includedDocuments = null;
/**
* Constructor for XMLAgainstXSDErrorHandler.
*
* @param includedDocuments a {@link net.anotheria.asg.generator.util.IncludedDocuments} object.
*/
public XMLAgainstXSDErrorHandler(IncludedDocuments includedDocuments) {
this.includedDocuments = includedDocuments;
}
/** {@inheritDoc} */
public void error (SAXParseException e) {
setHasErrors(true);
System.out.println(getErrorMessage("error",e,includedDocuments));
}
/** {@inheritDoc} */
public void warning (SAXParseException e) {
System.out.println(getErrorMessage("warning",e,includedDocuments));
}
/** {@inheritDoc} */
public void fatalError (SAXParseException e) {
System.out.println(getErrorMessage("fatal",e,includedDocuments));
e.printStackTrace();
System.exit(1);
}
/**
* getErrorMessage.
*
* @param errorType a {@link java.lang.String} object.
* @param e a {@link org.xml.sax.SAXParseException} object.
* @param includedDocuments a {@link net.anotheria.asg.generator.util.IncludedDocuments} object.
* @return a {@link java.lang.String} object.
*/
public String getErrorMessage(String errorType,SAXParseException e, IncludedDocuments includedDocuments){
String message = "Validating "+errorType+" : "+e.getMessage() + " in line : "+e.getLineNumber();
if (includedDocuments == null){
return message;
}
IncludeDocumentsBean idb = includedDocuments.getIncludeDocumentByLine(e.getLineNumber());
if (idb == null){
return message;
}
int lineWithError= e.getLineNumber() - idb.getInsertLine();
message = "Validating "+errorType+" : "+e.getMessage() +" in document : "+ idb.getDocumentName()+" in line : "+lineWithError;
return message;
}
/**
* isHasErrors.
*
* @return a boolean.
*/
public boolean isHasErrors() {
return hasErrors;
}
/**
* Setter for the field hasErrors
.
*
* @param hasErrors a boolean.
*/
public void setHasErrors(boolean hasErrors) {
this.hasErrors = hasErrors;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy