eu.xtreemos.xosd.utilities.xmlextractor
Class XMLSearchContextFactory

java.lang.Object
  extended by eu.xtreemos.xosd.utilities.xmlextractor.XMLSearchContextFactory

public class XMLSearchContextFactory
extends java.lang.Object

Implemented same functions as comprise XMLExtractor service. This class should be used to contact XMLValidatorAndParser functionalities.

Author:
ales.cernivec@xlab.si

Nested Class Summary
static class XMLSearchContextFactory.SchemaType
          Enum that contains paths to schemas used by XML parser.
 
Field Summary
private  java.util.Hashtable<java.lang.String,java.lang.Object> data
          Data passed as argument into factory.
(package private) static java.lang.String delim
           
(package private) static org.apache.log4j.Logger logger
           
static java.lang.String pathToRootSchemas
           
private  XMLSearchEngine searchEngine
          This is search engine that can be used to traverse data.
private  XMLValidatorAndParser validatorAndParser
          Validator and parser used for parsing document.
 
Constructor Summary
XMLSearchContextFactory(java.io.File xmlFile)
          Constructs content holder for XMLValidatorAndParser, XMLSearchEngine and Hashtable which contain all information used for parsing and searching the content of the XML document passed as File.
XMLSearchContextFactory(java.lang.String xmlContent)
          Constructs content holder for XMLValidatorAndParser, XMLSearchEngine and Hashtable which contain all information used for parsing and searching the content of the XML document passed as String.
 
Method Summary
 java.util.Hashtable<java.lang.String,java.lang.Object> getData()
          Gets data from which is has been just parsed.
static XMLSearchEngine getInstance(java.io.File xmlFile, XMLSearchContextFactory.SchemaType xsdSchema)
          Creates an instance of XMLSearchEngine with data from file.
static XMLSearchEngine getInstance(java.util.Hashtable<java.lang.String,java.lang.Object> data)
          Creates an instance of XMLSearchEngine instance based on data passed as Hashtable.
static XMLSearchEngine getInstance(java.lang.String xmlString, XMLSearchContextFactory.SchemaType xsdSchema)
          Creates an instance of XMLSearchEngine instance based on data passed as String.
 XMLSearchEngine getSearchEngine()
          Gets XMLSearchEngine instance which was created during parsing of the document passed as an argument.
static java.lang.String getStringFromFile(java.io.File path)
          Reads file and returns content in text format.
static java.util.Hashtable<java.lang.String,java.lang.Object> getXMLObject(java.lang.String path, XMLSearchContextFactory.SchemaType schemaType)
          Transform an XML stored in a file into a hash table containing the searchable elements of the source XML.
static java.util.Hashtable<java.lang.String,java.lang.Object> getXMLObjectFromDocument(org.w3c.dom.Document xmlDocument, XMLSearchContextFactory.SchemaType schemaType)
           
static java.util.Hashtable<java.lang.String,java.lang.Object> getXMLObjectFromString(java.lang.String xmlSchema, XMLSearchContextFactory.SchemaType schemaType)
          Returns data in hashtable from xmlDocument.
private static java.util.ArrayList hashtableGetValue(java.lang.String regexKey, java.util.Hashtable<java.lang.String,java.lang.Object> hash)
          The method gets an ArrayList corresponding to the matches via regular expression.
private  void iterateAndFind()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

searchEngine

private XMLSearchEngine searchEngine
This is search engine that can be used to traverse data.


data

private java.util.Hashtable<java.lang.String,java.lang.Object> data
Data passed as argument into factory.


validatorAndParser

private XMLValidatorAndParser validatorAndParser
Validator and parser used for parsing document.


logger

static final org.apache.log4j.Logger logger

delim

static java.lang.String delim

pathToRootSchemas

public static final java.lang.String pathToRootSchemas
Constructor Detail

XMLSearchContextFactory

public XMLSearchContextFactory(java.io.File xmlFile)
                        throws java.lang.Exception
Constructs content holder for XMLValidatorAndParser, XMLSearchEngine and Hashtable which contain all information used for parsing and searching the content of the XML document passed as File.

Parameters:
xmlFile - XML document to parse
Throws:
java.lang.Exception

XMLSearchContextFactory

public XMLSearchContextFactory(java.lang.String xmlContent)
                        throws java.lang.Exception
Constructs content holder for XMLValidatorAndParser, XMLSearchEngine and Hashtable which contain all information used for parsing and searching the content of the XML document passed as String. Use getSearchEngine() and getData() methods.

Parameters:
xmlContent - XML document to parse
Throws:
java.lang.Exception
Method Detail

getInstance

public static XMLSearchEngine getInstance(java.lang.String xmlString,
                                          XMLSearchContextFactory.SchemaType xsdSchema)
                                   throws java.lang.Exception
Creates an instance of XMLSearchEngine instance based on data passed as String. If scheme is NullSchema, there is no checking against any scheme.

Parameters:
xmlString - String used as XML data
xsdSchema -
Returns:
Throws:
java.lang.Exception

getInstance

public static XMLSearchEngine getInstance(java.util.Hashtable<java.lang.String,java.lang.Object> data)
                                   throws java.lang.Exception
Creates an instance of XMLSearchEngine instance based on data passed as Hashtable.

Parameters:
data - Hashtable of data
Returns:
instance of XMLSearchEngine
Throws:
java.lang.Exception

getInstance

public static XMLSearchEngine getInstance(java.io.File xmlFile,
                                          XMLSearchContextFactory.SchemaType xsdSchema)
                                   throws java.lang.Exception
Creates an instance of XMLSearchEngine with data from file. If scheme is NullSchema, there is no checking against any scheme.

Parameters:
xmlFile - used for data
xsdSchema - schema
Returns:
XMLSearchEngine for searching data from file
Throws:
java.lang.Exception

getXMLObject

public static java.util.Hashtable<java.lang.String,java.lang.Object> getXMLObject(java.lang.String path,
                                                                                  XMLSearchContextFactory.SchemaType schemaType)
                                                                           throws java.security.InvalidParameterException,
                                                                                  java.io.IOException,
                                                                                  org.xml.sax.SAXException
Transform an XML stored in a file into a hash table containing the searchable elements of the source XML. The elements of the hashtable are either strings for simple tags, instances of Hashtable for complex structures, and instances of ArrayList for multiple entries having the same key.

Parameters:
path - The path to the xml file on the file system of the service's host.
schemaType - The type of schema.
Returns:
A Hashtable containing the searchable elements of the source XML.
Throws:
org.xml.sax.SAXException
java.io.IOException
java.security.InvalidParameterException

getXMLObjectFromDocument

public static java.util.Hashtable<java.lang.String,java.lang.Object> getXMLObjectFromDocument(org.w3c.dom.Document xmlDocument,
                                                                                              XMLSearchContextFactory.SchemaType schemaType)
                                                                                       throws java.lang.Exception
Parameters:
xmlDocument -
schemaType -
Returns:
Throws:
java.lang.Exception

getXMLObjectFromString

public static java.util.Hashtable<java.lang.String,java.lang.Object> getXMLObjectFromString(java.lang.String xmlSchema,
                                                                                            XMLSearchContextFactory.SchemaType schemaType)
                                                                                     throws java.lang.Exception
Returns data in hashtable from xmlDocument. Schema is chosen from schemaType

Parameters:
xmlDocument -
schemaType -
Returns:
Throws:
java.lang.Exception

getStringFromFile

public static java.lang.String getStringFromFile(java.io.File path)
                                          throws java.lang.Exception
Reads file and returns content in text format.

Parameters:
path - Path to file
Returns:
content of file as string
Throws:
java.lang.Exception

getSearchEngine

public XMLSearchEngine getSearchEngine()
Gets XMLSearchEngine instance which was created during parsing of the document passed as an argument.

Returns:
XMLSearchEngine engine that can be used to search the content of the data

getData

public java.util.Hashtable<java.lang.String,java.lang.Object> getData()
Gets data from which is has been just parsed.

Returns:
Hashtable holds data from parsed XML document.

iterateAndFind

private void iterateAndFind()

hashtableGetValue

private static java.util.ArrayList hashtableGetValue(java.lang.String regexKey,
                                                     java.util.Hashtable<java.lang.String,java.lang.Object> hash)
The method gets an ArrayList corresponding to the matches via regular expression.

Parameters:
regexKey - the regular expression with which the keys should be compared
hash - the hashtable with keys to compare
Returns:
ArrayList with values from the matchin keys; empty ArrayList otherwise
See Also:
expressions: http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#sum