4,10 → 4,10 |
* Coded by: Group 5, software practice summer 2003 |
* University of Bielefeld, Germany |
* |
* @version $Revision: 1.54 $ |
* @version $Revision: 1.55 $ |
* |
* Last modification: $Date: 2003/07/25 11:52:30 $ |
* $Id: Validator.java,v 1.54 2003/07/25 11:52:30 smcsporr Exp $ |
* Last modification: $Date: 2003/07/26 15:56:05 $ |
* $Id: Validator.java,v 1.55 2003/07/26 15:56:05 smcsporr Exp $ |
*/ |
|
package src.parser; |
47,13 → 47,13 |
* It can be used to parse and validate DOM document implementations against |
* a Document Type Definition (DTD) or an XML schema. |
* |
* A <code>Validator</code> instance uses an instance of the <code>ValidationErrorHandler</code> class |
* to catch and handle SAX warning and error events. These events are used to |
* A <code>Validator</code> instance uses an instance of the <code>ValidationErrorHandler</code> |
* class to catch and handle SAX warning and error events. These events are used to |
* decide, whether a document is valid or not. |
* |
* @author S. McSporran |
* |
* @version $Revision: 1.54 $ Last modification: $Date: 2003/07/25 11:52:30 $ |
* @version $Revision: 1.55 $ Last modification: $Date: 2003/07/26 15:56:05 $ |
*/ |
public class Validator { |
|
170,7 → 170,7 |
/** |
* This method creates an instance of a <code>Transformer</code> object |
* which is used by this class to generate an output stream from |
* a <code>Document </code> object. |
* a <code>Document</code> object. |
* |
* @see javax.xml.transform.Transformer |
* |
189,7 → 189,7 |
/* Catch and log creation errors. */ |
catch (TransformerConfigurationException tce) { |
setStatIcon(StatusInterface.ICON_ERROR); |
sendStatMessage("Transformer cannot be created: " + tce.getMessage()); |
sendStatMessage("[Validator] Transformer cannot be created: " + tce.getMessage()); |
} |
} |
|
235,12 → 235,12 |
* validation feature. |
*/ |
catch (SAXNotRecognizedException snre) { |
log(LogInterface.TYPE_ERROR,activeParser + " does not support validation."); |
log(LogInterface.TYPE_ERROR,"[Validator] " + activeParser + " does not support validation."); |
} |
|
/* Send a message to the logging area, if the feature cannot be activated. */ |
catch (SAXNotSupportedException snse) { |
log(LogInterface.TYPE_ERROR,"The validation feature cannot be activated now."); |
log(LogInterface.TYPE_ERROR,"[Validator] The validation feature cannot be activated now."); |
} |
} |
|
265,12 → 265,14 |
* dynamic validation feature. |
*/ |
catch (SAXNotRecognizedException snre) { |
log(LogInterface.TYPE_ERROR,activeParser + " does not support dynamic validation."); |
log(LogInterface.TYPE_ERROR,"[Validator] " + activeParser + |
" does not support dynamic validation."); |
} |
|
/* Send a message to the logging area, if the feature cannot be activated. */ |
catch (SAXNotSupportedException snse) { |
log(LogInterface.TYPE_ERROR,"The dynamic validation feature cannot be activated now."); |
log(LogInterface.TYPE_ERROR, |
"[Validator] The dynamic validation feature cannot be activated now."); |
} |
} |
|
295,12 → 297,14 |
* XML schema validation. |
*/ |
catch (SAXNotRecognizedException snre) { |
log(LogInterface.TYPE_ERROR,activeParser + " does not support schema validation."); |
log(LogInterface.TYPE_ERROR,"[Validator] " + activeParser + |
" does not support schema validation."); |
} |
|
/* Send a message to the logging area, if the feature cannot be activated. */ |
catch (SAXNotSupportedException snse) { |
log(LogInterface.TYPE_ERROR,"The schema validation support cannot be activated now."); |
log(LogInterface.TYPE_ERROR, |
"[Validator] The schema validation support cannot be activated now."); |
} |
} |
|
324,12 → 328,14 |
* namespace processing. |
*/ |
catch (SAXNotRecognizedException snre) { |
log(LogInterface.TYPE_ERROR,activeParser + " does not support namespace processing."); |
log(LogInterface.TYPE_ERROR,"[Validator] " + activeParser + |
" does not support namespace processing."); |
} |
|
/* Send a message to the logging area, if the feature cannot be activated. */ |
catch (SAXNotSupportedException snse) { |
log(LogInterface.TYPE_ERROR,"The namespace processing feature cannot be activated now."); |
log(LogInterface.TYPE_ERROR, |
"[Validator] The namespace processing feature cannot be activated now."); |
} |
} |
|
353,12 → 359,14 |
* break on fatal error skipping. |
*/ |
catch (SAXNotRecognizedException snre) { |
log(LogInterface.TYPE_ERROR,activeParser + " does not support the continue-after-fatal-error feature."); |
log(LogInterface.TYPE_ERROR,"[Validator] " + activeParser + |
" does not support the continue-after-fatal-error feature."); |
} |
|
/* Send a message to the logging area, if the feature cannot be activated. */ |
catch (SAXNotSupportedException snse) { |
log(LogInterface.TYPE_ERROR,"The continue-after-fatal-error feature cannot be activated now."); |
log(LogInterface.TYPE_ERROR, |
"[Validator] The continue-after-fatal-error feature cannot be activated now."); |
} |
} |
|
365,6 → 373,9 |
/** |
* This method validates a DOM document object. |
* |
* To validate an XML document, a grammar is required, either a Document Type |
* Definition or an XML schema that is linked with the document. |
* |
* @param doc The document to be validated. |
* |
* @return <code>true</code>, if the document fits to it's specified grammar, |
408,7 → 419,7 |
/* Use the StringBuffer as a new InputSource for parsing. */ |
InputSource inputSrc = new InputSource(new StringReader(buffer.toString())); |
if ((docFile != null)) { |
inputSrc.setSystemId(docFile.getPath()); |
inputSrc.setSystemId(docFile.toURI().toString()); |
} |
activeParser.parse(inputSrc); |
} |
415,7 → 426,8 |
|
/* Catch and log parsing errors. */ |
catch (SAXException se) { |
log(LogInterface.TYPE_ERROR, "Validation processing error: " + se.getMessage()); |
log(LogInterface.TYPE_ERROR, "[Validator] Validation processing error: " + |
se.getMessage()); |
|
/* Set valid status to false in case of parsing errors. */ |
eHandler.setValid(false); |
422,7 → 434,8 |
} |
|
catch (IOException ioe) { |
log(LogInterface.TYPE_ERROR, "Validation I/O-error: " + ioe.getMessage()); |
log(LogInterface.TYPE_ERROR, "[Validator] Validation I/O-error: " + |
ioe.getMessage()); |
|
/* Set valid status to false in case of I/O errors. */ |
eHandler.setValid(false); |
431,7 → 444,7 |
|
/* Catch and log transformation errors. */ |
catch (TransformerException te) { |
log(LogInterface.TYPE_ERROR, "Transformer error: " + te.getMessage()); |
log(LogInterface.TYPE_ERROR, "[Validator] Transformer error: " + te.getMessage()); |
|
/* Set valid status to false in case of transformation errors. */ |
eHandler.setValid(false); |
463,7 → 476,8 |
|
/* Catch and log parsing errors. */ |
catch (SAXException se) { |
log(LogInterface.TYPE_ERROR, "Validation processing error: " + se.getMessage()); |
log(LogInterface.TYPE_ERROR, "[Validator] Validation processing error: " + |
se.getMessage()); |
|
/* Set valid status to false in case of parsing errors. */ |
eHandler.setValid(false); |
470,7 → 484,8 |
} |
|
catch (IOException ioe) { |
log(LogInterface.TYPE_ERROR, "Validation I/O-error: " + ioe.getMessage()); |
log(LogInterface.TYPE_ERROR, "[Validator] Validation I/O-error: " + |
ioe.getMessage()); |
|
/* Set valid status to false in case of I/O errors. */ |
eHandler.setValid(false); |