eu.xtreemos.xosd.factory.utils.parsers
Class XMLValidatorAndParser

java.lang.Object
  extended by eu.xtreemos.xosd.factory.utils.parsers.XMLValidatorAndParser

public class XMLValidatorAndParser
extends java.lang.Object

Validates the XML document against the XSD schema using org.w3c.dom packages. Parses the XML document and puts the data into a mixed ArrayList and Hashtable structure. Hashtables (key/value) pairs correspond to the (XML tag/XML value) pairs.

Where multiple values are assigned to the same key (defined in XSD as sequence) and ArrayList is put to the Hashtable value.

Where the value of the key is a complex type, the key is of type of Hashtable.

The output is used in XMLSearchEngine

Version:
1.0
Author:
danielv
See Also:
XMLSearchEngine

Field Summary
(package private) static org.apache.log4j.Logger logger
           
 
Constructor Summary
XMLValidatorAndParser()
          Default constructor for XMLValidatorAndParser.
 
Method Summary
protected  java.util.Hashtable<java.lang.String,java.lang.Object> loadSchema(java.io.InputStream xmlSchemaStream, java.lang.String xsdSchemaFile)
          The method that performs the actual parsing and validating of the XML document accessable via an input stream.
 java.util.Hashtable<java.lang.String,java.lang.Object> loadSchema(java.lang.String xmlString)
          Validates the XML document against the XSD schema using org.w3c.dom packages.
 java.util.Hashtable<java.lang.String,java.lang.Object> loadSchema(java.lang.String xmlSchemaFile, java.lang.String xsdSchemaFile)
          Validates the XML document in a file against the XSD schema using org.w3c.dom packages.
 java.util.Hashtable<java.lang.String,java.lang.Object> loadSchemaFromElement(org.w3c.dom.Document xmlDocument, java.lang.String xsdSchemaFile)
          Validates the XML document against the XSD schema using org.w3c.dom packages.
 java.util.Hashtable<java.lang.String,java.lang.Object> loadSchemaFromString(java.lang.String xmlSchema, java.lang.String xsdSchemaFile)
          Validates the XML document in a string against the XSD schema using org.w3c.dom packages.
private  void loadXML(org.w3c.dom.Node element, java.util.Hashtable<java.lang.String,java.lang.Object> inHash)
          Parses the XML document and puts the data into a mixed ArrayList and Hashtable structure.
static void main(java.lang.String[] args)
          main method - used just for testing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static org.apache.log4j.Logger logger
Constructor Detail

XMLValidatorAndParser

public XMLValidatorAndParser()
Default constructor for XMLValidatorAndParser.

Method Detail

loadXML

private void loadXML(org.w3c.dom.Node element,
                     java.util.Hashtable<java.lang.String,java.lang.Object> inHash)
              throws java.lang.Exception
Parses the XML document and puts the data into a mixed ArrayList and Hashtable structure. Hashtables (key/value) pairs correspond to the (XML tag/XML value) pairs.

Where multiple values are assigned to the same key (defined in XSD as sequence) and ArrayList is put to the Hashtable value.

Where the value of the key is a complex type, the key is of type of Hashtable.

Where element is a leaf node with attributes, attributes and value of the node are added into Hashtable, key of the node is named with keyword "value". If "value" is already name of some attribute, string formed with concatenation of the node's name and "Value". If key name cannot be specified, exception is thrown. User should be aware how to access to nodes value.

If node is leave without attributes, simply value is assigned to the key (named by node's name).

Parameters:
element - the root element of the XML tree
inHash - the Hashtable for this subtree
Throws:
java.lang.Exception
See Also:
loadSchema(String, String)

loadSchema

protected java.util.Hashtable<java.lang.String,java.lang.Object> loadSchema(java.io.InputStream xmlSchemaStream,
                                                                            java.lang.String xsdSchemaFile)
                                                                     throws java.io.IOException,
                                                                            org.xml.sax.SAXException
The method that performs the actual parsing and validating of the XML document accessable via an input stream.

Parameters:
xmlSchemaStream - The stream containing the XML document contents.
xsdSchemaFile - The full path to the file containing the XML schema in an XSD document.
Returns:
A collection containing the items of the XML document. The elements are either a ArrayList instances representing all elements that have the same key, or Hashtable instances where a key represents a complex structure.
Throws:
java.io.IOException
org.xml.sax.SAXException
See Also:
XMLSearchEngine

loadSchema

public java.util.Hashtable<java.lang.String,java.lang.Object> loadSchema(java.lang.String xmlSchemaFile,
                                                                         java.lang.String xsdSchemaFile)
                                                                  throws java.io.IOException,
                                                                         org.xml.sax.SAXException
Validates the XML document in a file against the XSD schema using org.w3c.dom packages. Parses the XML document and puts the data into a mixed ArrayList and Hashtable structure. Hashtables (key/value) pairs correspond to the (XML tag/XML value) pairs.

Where multiple values are assigned to the same key (defined in XSD as sequence) and ArrayList is put to the Hashtable value.

Where the value of the key is a complex type, the key is of type of Hashtable.

Parameters:
xmlSchemaFile - The full path to the XML document
xsdSchemaFile - The full path to the XSD document; if null, no validation is performed
Returns:
A Hashtable with the parsed XML
Throws:
java.io.IOException
org.xml.sax.SAXException
See Also:
XMLSearchEngine

loadSchemaFromString

public java.util.Hashtable<java.lang.String,java.lang.Object> loadSchemaFromString(java.lang.String xmlSchema,
                                                                                   java.lang.String xsdSchemaFile)
                                                                            throws java.io.IOException,
                                                                                   org.xml.sax.SAXException
Validates the XML document in a string against the XSD schema using org.w3c.dom packages. Parses the XML document and puts the data into a mixed ArrayList and Hashtable structure. Hashtables (key/value) pairs correspond to the (XML tag/XML value) pairs.

Where multiple values are assigned to the same key (defined in XSD as sequence) and ArrayList is put to the Hashtable value.

Where the value of the key is a complex type, the key is of type of Hashtable.

Parameters:
xmlSchema - The contents of the XML document
xsdSchemaFile - The full path to the XSD document; if null, no validation is performed
Returns:
A Hashtable with the parsed XML
Throws:
java.io.IOException
org.xml.sax.SAXException
See Also:
XMLSearchEngine

loadSchemaFromElement

public java.util.Hashtable<java.lang.String,java.lang.Object> loadSchemaFromElement(org.w3c.dom.Document xmlDocument,
                                                                                    java.lang.String xsdSchemaFile)
                                                                             throws java.io.IOException,
                                                                                    org.xml.sax.SAXException
Validates the XML document against the XSD schema using org.w3c.dom packages. Parses the XML document and puts the data into a mixed ArrayList and Hashtable structure. Hashtables (key/value) pairs correspond to the (XML tag/XML value) pairs. Same as above, only XML document-element is not read from file but passed as parameter.

Where multiple values are assigned to the same key (defined in XSD as sequence) and ArrayList is put to the Hashtable value.

Where the value of the key is a complex type, the key is of type of Hashtable.

Parameters:
xmlDocument - XML document element (received & transformed by ResourceQuery)
xsdSchemaFile - The full path to the XSD document; if null, no validation is performed
Returns:
A Hashtable with the parsed XML
Throws:
java.io.IOException
org.xml.sax.SAXException
See Also:
XMLSearchEngine

loadSchema

public java.util.Hashtable<java.lang.String,java.lang.Object> loadSchema(java.lang.String xmlString)
                                                                  throws java.io.IOException,
                                                                         org.xml.sax.SAXException
Validates the XML document against the XSD schema using org.w3c.dom packages. Parses the XML document and puts the data into a mixed ArrayList and Hashtable structure. Hashtables (key/value) pairs correspond to the (XML tag/XML value) pairs.

Where multiple values are assigned to the same key (defined in XSD as sequence) and ArrayList is put to the Hashtable value.

Where the value of the key is a complex type, the key is of type of Hashtable.

Parameters:
xmlString - String containing XML
Returns:
A Hashtable with the parsed XML
Throws:
java.io.IOException
org.xml.sax.SAXException
See Also:
XMLSearchEngine

main

public static void main(java.lang.String[] args)
main method - used just for testing.