4,10 → 4,10 |
* Coded by: Group 5, software practice summer 2003 |
* University of Bielefeld, Germany |
* |
* @version $Revision: 1.26 $ |
* @version $Revision: 1.27 $ |
* |
* Last modification: $Date: 2003/07/25 11:52:17 $ |
* $Id: ValidationErrorHandler.java,v 1.26 2003/07/25 11:52:17 smcsporr Exp $ |
* Last modification: $Date: 2003/07/25 14:53:55 $ |
* $Id: ValidationErrorHandler.java,v 1.27 2003/07/25 14:53:55 smcsporr Exp $ |
*/ |
|
package src.parser; |
24,7 → 24,8 |
/** |
* The <b><code>ValidationErrorHandler</code></b> class supplies an error handler for the |
* <code>Validator</code> class. |
* An error handler retrieves and handles error events sent by a SAX parser. These |
* |
* An error handler receives and handles error events sent by a SAX parser. These |
* errors include warnings, errors and fatal errors. |
* |
* @see org.apache.xml.utils.DefaultErrorHandler |
31,7 → 32,7 |
* |
* @author S. McSporran |
* |
* @version $Revision: 1.26 $ Last modification: $Date: 2003/07/25 11:52:17 $ |
* @version $Revision: 1.27 $ Last modification: $Date: 2003/07/25 14:53:55 $ |
*/ |
public class ValidationErrorHandler extends DefaultErrorHandler { |
|
45,9 → 46,9 |
private StatusInterface statusInterfaceReference; |
|
/** |
* This method resets the internal validation status to <code>true</code>. A document |
* is valid by default and it's validation status only changes to false, if an error or |
* fatal error occured. |
* This method resets the internal validation status to <code>true</code>. |
* A document is valid by default and it's validation status only changes to false, |
* if an error or fatal error occured. |
* The valid status can only be reset to <code>true</code> from external classes, so |
* only nonvalid XML documents will get a nonvalid status. |
* |
79,33 → 80,51 |
|
/** |
* A method that catches SAX warnings and sends them to the log panel. |
* |
* Additionally, location informations will be diplayed that point to the |
* area where a warning event was fired inside the validated XML document. |
* Please note, that the location informations provided by the parser are |
* only a guess and not sufficient for exact location of the problem. |
* |
* Warnings indicate that something might be missing or incorrect in an XML file, |
* while no XML wellformedness rule has been broken. |
* while no XML wellformedness rule has been broken. A parser will be able to |
* continue to process a document after invoking this method. |
* |
* @param saxpe A warning event sent by a SAX parser. |
* |
* author S. McSporran |
* |
* Last revision: 11-Jul-2003 |
* Last revision: 28-Jul-2003 |
*/ |
public void warning(SAXParseException saxpe) { |
|
String warningMessage = "Warning: " + saxpe.getMessage() + " at line" + |
saxpe.getLineNumber() + ", column " + saxpe.getColumnNumber(); |
log(LogInterface.TYPE_WARNING, warningMessage); |
setNewPoint(new Point(saxpe.getLineNumber(), saxpe.getColumnNumber())); |
/* Check, if locator informations are available. */ |
if((saxpe.getLineNumber() != -1) && (saxpe.getColumnNumber() != -1)) { |
String warningMessage = "[Validator] Warning: " + saxpe.getMessage() + " at line" + |
saxpe.getLineNumber() + ", character no. " + saxpe.getColumnNumber(); |
log(LogInterface.TYPE_WARNING, warningMessage); |
setNewPoint(new Point(saxpe.getLineNumber(), saxpe.getColumnNumber())); |
} else { |
log(LogInterface.TYPE_WARNING, "[Validator] Warning: " + saxpe.getMessage()); |
} |
} |
|
/** |
* A method that catches SAX errors and sends them to the log panel. Errors |
* occur during validation, if a grammar rule has been broken, but the parser |
* will be able to continue. |
* A method that catches SAX errors and sends them to the log panel. |
* |
* Additionally, location informations will be diplayed that point to the |
* area where an error event was fired inside the validated XML document. |
* Please note, that the location informations provided by the parser are |
* only a guess and not sufficient for exact location of the problem. |
* |
* Errors occur during validation, if a grammar rule has been broken, for example. |
* A parser will continue to process a document after invoking this method. |
* |
* @param saxpe An error event sent by a SAX parser. |
* |
* author S. McSporran |
* |
* Last revision: 12-Jul-2003 |
* Last revision: 28-Jul-2003 |
*/ |
public void error(SAXParseException saxpe) { |
|
112,22 → 131,35 |
/* Set valid status to false, if any error occured. */ |
valid = false; |
|
String errorMessage = "Error: " + saxpe.getMessage() + " at line " + |
saxpe.getLineNumber() + ", column " + saxpe.getColumnNumber(); |
log(LogInterface.TYPE_ERROR, errorMessage); |
setNewPoint(new Point(saxpe.getLineNumber(), saxpe.getColumnNumber())); |
/* Check, if locator informations are available. */ |
if((saxpe.getLineNumber() != -1) && (saxpe.getColumnNumber() != -1)) { |
String errorMessage = "[Validator] Error: " + saxpe.getMessage() + " at line " + |
saxpe.getLineNumber() + ", character no. " + saxpe.getColumnNumber(); |
log(LogInterface.TYPE_ERROR, errorMessage); |
setNewPoint(new Point(saxpe.getLineNumber(), saxpe.getColumnNumber())); |
} else { |
log(LogInterface.TYPE_ERROR, "[Validator] Error: " + saxpe.getMessage()); |
} |
} |
|
/** |
* A method that catches SAX fatal errors and sends them to the log panel. |
* |
* Additionally, location informations will be diplayed that point to the |
* area where a fatal error event was fired inside the validated XML document. |
* Please note, that the location informations provided by the parser are |
* only a guess and not sufficient for exact location of the problem. |
* |
* Fatal errors indicate that a grammar rule has been broken that makes continued |
* parsing impossible. |
* parsing impossible. This includes violations of the well-formedness constraints. |
* It's assumed that a parser will not be able to process a document correctly |
* after invoking this method, so the parsing process will be stopped by default. |
* |
* @param saxpe A fatal error event sent by a SAX parser. |
* |
* author S. McSporran |
* |
* Last revision: 11-Jul-2003 |
* Last revision: 28-Jul-2003 |
*/ |
public void fatalError(SAXParseException saxpe) { |
|
134,10 → 166,15 |
/* Set valid status to false, if any fatal error occured. */ |
valid = false; |
|
String errorMessage = "Fatal error: " + saxpe.getMessage() + " at line " + |
saxpe.getLineNumber() + ", column " + saxpe.getColumnNumber(); |
log(LogInterface.TYPE_ERROR, errorMessage); |
setNewPoint(new Point(saxpe.getLineNumber(), saxpe.getColumnNumber())); |
/* Check, if locator informations are available. */ |
if((saxpe.getLineNumber() != -1) && (saxpe.getColumnNumber() != -1)) { |
String errorMessage = "[Validator] Fatal error: " + saxpe.getMessage() + " at line " + |
saxpe.getLineNumber() + ", character no. " + saxpe.getColumnNumber(); |
log(LogInterface.TYPE_ERROR, errorMessage); |
setNewPoint(new Point(saxpe.getLineNumber(), saxpe.getColumnNumber())); |
} else { |
log(LogInterface.TYPE_ERROR, "[Validator] Fatal error: " + saxpe.getMessage()); |
} |
} |
|
/** |
186,7 → 223,15 |
logInterfaceReference.log(i,message); |
} |
|
/** Sets a new point in the status panel. */ |
/** |
* Sets a new point in the status panel. |
* |
* This info is used to give a little more detail about where in the document |
* an error happened. |
* |
* @param p A <code>Point</code> object, pointing to a specific line and character |
* where an error occured. |
*/ |
private void setNewPoint(Point p) { |
statusInterfaceReference.setPoint(p); |
} |