jcreek.cke.importexport.xml
Class XMLvalidater

java.lang.Object
  extended byjcreek.cke.importexport.xml.DefaultGeneralParser
      extended byjcreek.cke.importexport.xml.XMLvalidater

public class XMLvalidater
extends DefaultGeneralParser

The intention of this class is to help validate a XML file by specifying a Schema file. The XML file is first coarse tested if it is a valid XML file, and if that the case then the correct Schema path (the local Schema) is set. Then the validation against the specified Schema is performed. In case of faults during the validation, the error-messages are logged and may be retrieved.

Author:
Stein L. Tomassen, NTNU 2002

Field Summary
 
Fields inherited from class jcreek.cke.importexport.xml.DefaultGeneralParser
DEFFERED_DOM, INCLUDE_IGNORABLE_WHITESPACE, NAMESPACES, SCHEMA_FULL_SUPPORT, SCHEMA_SUPPORT, VALIDATION
 
Constructor Summary
XMLvalidater(org.w3c.dom.Document document, java.lang.String schemaPath)
          Initializes the parser for validation by specifying a DOM document and the schema path.
XMLvalidater(java.io.Reader source, java.lang.String schemaPath)
          Initializes the parser for validation by specifying a java.io.Reader with the DOM document and the schema path.
XMLvalidater(java.lang.String filepath, java.lang.String schemaPath)
          Initializes the parser for validation by specifying a file path to the DOM document and the schema path.
 
Method Summary
protected  void correctSchemaPath(org.w3c.dom.Node node)
          A method that tries to locate where in the DOM document the Schema is set.
 java.lang.String getDocRootNodeName(org.w3c.dom.Document document)
          A method that retrieves the node name of the root node of the DOM document node.
 org.w3c.dom.Document getDocument()
          A method that returns the DOM document.
 java.lang.String getErrorMsg()
          Returns the Exception message
 java.lang.String getSchemaPath()
          Returns the schema file name and path of the message
protected  void initParser(java.io.Reader source)
          Initializes the parser.
 boolean isValid()
          Checks to see if the message is a valid message according to the specified schema in the constructor
 
Methods inherited from class jcreek.cke.importexport.xml.DefaultGeneralParser
anyFaults, getAllFaultMsg, getErrorsMsg, getFatalErrorsMsg, getNumberOfErrors, getNumberOfFatalErrors, getNumberOfWarnings, getWarningsMsg, initParser, parse, parse, parse, parse, setFeature
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLvalidater

public XMLvalidater(java.lang.String filepath,
                    java.lang.String schemaPath)
Initializes the parser for validation by specifying a file path to the DOM document and the schema path. If the validation was successful may be checked with the method: isValid()

Parameters:
filepath - the file path to the DOM document to validate
schemaPath - the path to the local schema to validate against
See Also:
jcreek.cke.helpers.xml.XMLvalidater#isValid()

XMLvalidater

public XMLvalidater(java.io.Reader source,
                    java.lang.String schemaPath)
Initializes the parser for validation by specifying a java.io.Reader with the DOM document and the schema path. If the validation was successful may be checked with the method: isValid()

Parameters:
source - a Reader with the DOM document to validate
schemaPath - the path to the local schema to validate against
See Also:
jcreek.cke.helpers.xml.XMLvalidater#isValid()

XMLvalidater

public XMLvalidater(org.w3c.dom.Document document,
                    java.lang.String schemaPath)
Initializes the parser for validation by specifying a DOM document and the schema path. If the validatton was successful may be checked with the method: isValid()

Parameters:
document - the DOM document to validate
schemaPath - the path to the local schema to validate against
See Also:
jcreek.cke.helpers.xml.XMLvalidater#isValid()
Method Detail

getDocument

public org.w3c.dom.Document getDocument()
A method that returns the DOM document.

Returns:
the DOM document specified in the constructor

isValid

public boolean isValid()
Checks to see if the message is a valid message according to the specified schema in the constructor

Returns:
true if it is a valid message, otherwise false will be returned

getSchemaPath

public java.lang.String getSchemaPath()
Returns the schema file name and path of the message

Returns:
the schema file name

getDocRootNodeName

public java.lang.String getDocRootNodeName(org.w3c.dom.Document document)
A method that retrieves the node name of the root node of the DOM document node.

Parameters:
document - the DOM document to handle
Returns:
the node name of the root node if found, does otherwise return null

getErrorMsg

public java.lang.String getErrorMsg()
Returns the Exception message

Returns:
a string with the Exception message

initParser

protected void initParser(java.io.Reader source)
Initializes the parser. Used by the constructors.

Parameters:
source - the source of the document to parse

correctSchemaPath

protected void correctSchemaPath(org.w3c.dom.Node node)
A method that tries to locate where in the DOM document the Schema is set. Nevertheless, the correct schema path is set to the local schema. This procedure is important to ensure that the schema path is correct in able to validate the document.

This method is recursive, but ends when the correct schema path is set. The schema used is the one specified in the constructors, and this method is also called by the constructors.

Parameters:
node - the root node of the DOM document


Created at IDI, NTNU by the Artificial Intelligence and Learning group