com.ls.util.xml
Class XMLComplexHandler

java.lang.Object
  |
  +--com.ls.util.xml.XMLComplexHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, IXMLHandler

public class XMLComplexHandler
extends Object
implements org.xml.sax.ContentHandler, IXMLHandler

Processes xml structures as read from any input source and returns the Map implementation of a XMLFragment of that structures.

Version:
$Revision: 1.6 $
Author:
Last modified by $Author: OHittmeyer $

Constructor Summary
XMLComplexHandler()
          constructs an XMLComplexHandler instance, which creates an instance of XMLReader.
 
Method Summary
 String buildString(String documentType, Map xmlMapping)
          creates the string representation of an xml structure as specified in the given map.
 void characters(char[] ch, int start, int length)
          any character within an element node will be interpreted as the value of this element node.
 Map convertAttributesToMap(org.xml.sax.Attributes attributeList)
          converts the given instance of Attributes into a Map and returns it.
 void endDocument()
          if the document is finished there should be only one map left in the list.
 void endElement(String namespaceURI, String localName, String qName)
          if the Parser receives the end tag of an element, he will remove it from the list of stuff to parse.
 void endPrefixMapping(String prefix)
          end the scope of a prefix-URI mapping. This method is currently not be used in this class.
 void ignorableWhitespace(char[] ch, int start, int length)
          receives notification of ignorable whitespace in element content. This method is currently not be used in this class.
 Map parse(org.xml.sax.InputSource inputSource)
          parses an xml structure as read from the given input source and returns a map view on it.
 Map parse(Reader readerSource)
          parses a xml structure as read from the given Reader and returns a map view on it.
 Map parse(String stringSource)
          parses a xml structure as read from the given String and returns a map view on it.
 void processingInstruction(String target, String data)
          receives notification of a processing instruction. This method is currently not be used in this class.
 void setDocumentLocator(org.xml.sax.Locator locator)
          receive an object for locating the origin of SAX document events. This method is currently not be used in this class.
 void skippedEntity(String name)
          receive notification of a skipped entity. This method is currently not be used in this class.
 void startDocument()
          receives notification of the beginning of a document. The SAX parser will invoke this method only once, before any other methods in this interface or in DTDHandler (except for setDocumentLocator).
 void startElement(String namespaceURI, String localName, String qName, org.xml.sax.Attributes attributeList)
          receive notification of the beginning of an element.
 void startPrefixMapping(String prefix, String uri)
          begins the scope of a prefix-URI Namespace mapping. This method is currently not be used in this class.
 void write(Writer writer, String documentType, Map xmlMapping)
          creates the string representation of an xml structure as specified in the given map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLComplexHandler

public XMLComplexHandler()
                  throws ProgrammingException
constructs an XMLComplexHandler instance, which creates an instance of XMLReader. Note: For instantiating an XMLReader this method is trying to get the value of the org.xml.sax.driver system property.
If that property is not set, the org.apache.crimson.parser.XMLReaderImpl implementation of XMLReader will be taken as default.
Method Detail

parse

public Map parse(org.xml.sax.InputSource inputSource)
          throws XMLException,
                 IllegalArgumentException,
                 ProgrammingException
parses an xml structure as read from the given input source and returns a map view on it.
Specified by:
parse in interface IXMLHandler
Parameters:
inputSource - the source from where to get the xml structure
Returns:
Map view on a created XMLFragment object
Throws:
XMLException - if the parsing process fails
IllegalArgumentException - if the given inputSource is null
ProgrammingException - if this.xmlParser is null
See Also:
XMLFragment

parse

public Map parse(Reader readerSource)
          throws XMLException,
                 IllegalArgumentException,
                 ProgrammingException
parses a xml structure as read from the given Reader and returns a map view on it.
Specified by:
parse in interface IXMLHandler
Parameters:
readerSource - the source from where to get the xml structure
Returns:
a Map view on the created XMLFragment object
Throws:
XMLException - if the parsing process fails
IllegalArgumentException - if the given reader is null
ProgrammingException - if this.xmlParser is null
See Also:
XMLFragment

parse

public Map parse(String stringSource)
          throws XMLException,
                 IllegalArgumentException,
                 ProgrammingException
parses a xml structure as read from the given String and returns a map view on it.
Specified by:
parse in interface IXMLHandler
Parameters:
stringSource - the source from where to get the xml structure
Returns:
a Map view on the created XMLFragment object
Throws:
XMLException - if the parsing process fails
IllegalArgumentException - if the given source is null
ProgrammingException - if this.xmlParser is null
See Also:
XMLFragment

buildString

public String buildString(String documentType,
                          Map xmlMapping)
                   throws XMLException
creates the string representation of an xml structure as specified in the given map. Hereby documentType will become the root element of this structure. Note: This implementation awaits the map to contain only String/String mappings in order to perform successful. If you want to specify more complex (nested) structures, please pass an XMLFragment.
Parameters:
documentType - specifies the root element of the new xml structure
xmlMapping - contains element/content mappings to be used in the new xml structure
Returns:
string representation of xml structure
Throws:
XMLException - if the conversion to xml fails
See Also:
XMLFragment

write

public void write(Writer writer,
                  String documentType,
                  Map xmlMapping)
           throws XMLException,
                  IllegalArgumentException
creates the string representation of an xml structure as specified in the given map. Hereby documentType will become the root element of this structure. The final string will be written to the specified Writer. Note: This implementation awaits the Map to contain only String/String mappings in order to perform successful. If you want to specify more complex (nested) structures, please pass an XMLFragment.
Parameters:
writer - Writer to which the xml string should be written
documentType - specifies the root element of the new xml structure
xmlMapping - contains element/content mappings to be used in the new xml structure
Throws:
XMLException - if the conversion to xml fails
IllegalArgumentException - if one of the arguments is is null, or if the xmlMapping map is empty
See Also:
XMLFragment

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
receive an object for locating the origin of SAX document events.

This method is currently not be used in this class.

Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler
Parameters:
locator - not being used ...

startDocument

public void startDocument()
receives notification of the beginning of a document.

The SAX parser will invoke this method only once, before any other methods in this interface or in DTDHandler (except for setDocumentLocator).

Specified by:
startDocument in interface org.xml.sax.ContentHandler

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws org.xml.sax.SAXException
receives notification of a processing instruction.

This method is currently not be used in this class.

Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Parameters:
target - not being used ...
data - not being used ...
Throws:
org.xml.sax.SAXException - if any error occurs

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
receives notification of ignorable whitespace in element content.

This method is currently not be used in this class.

Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Parameters:
ch - not being used ...
start - not being used ...
length - not being used ...
Throws:
org.xml.sax.SAXException - if any error occurs

skippedEntity

public void skippedEntity(String name)
                   throws org.xml.sax.SAXException
receive notification of a skipped entity.

This method is currently not be used in this class.

Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Parameters:
name - not being used ...
Throws:
org.xml.sax.SAXException - if any error occurs

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
begins the scope of a prefix-URI Namespace mapping.

This method is currently not be used in this class.

Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Parameters:
prefix - not being used ...
uri - not being used ...

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         org.xml.sax.Attributes attributeList)
                  throws org.xml.sax.SAXException
receive notification of the beginning of an element.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Parameters:
namespaceURI - the namespace uri of that element
localName - the name of that element
qName - the fully qualified name of that element
attributeList - the attributes of that element
Throws:
org.xml.sax.SAXException - if the conversion to xml fails

characters

public void characters(char[] ch,
                       int start,
                       int length)
any character within an element node will be interpreted as the value of this element node.
Specified by:
characters in interface org.xml.sax.ContentHandler
Parameters:
ch - characters from the xml document
start - start position in the array
length - number of characters to be read from the array

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
if the Parser receives the end tag of an element, he will remove it from the list of stuff to parse. If the element has sub elements, those will be parsed first.
Specified by:
endElement in interface org.xml.sax.ContentHandler
Parameters:
namespaceURI - the namespace uri of that element
localName - the name of that element
qName - the fully qualified name of that element

endPrefixMapping

public void endPrefixMapping(String prefix)
end the scope of a prefix-URI mapping.

This method is currently not be used in this class.

Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Parameters:
prefix - not be used ...

endDocument

public void endDocument()
if the document is finished there should be only one map left in the list.
Specified by:
endDocument in interface org.xml.sax.ContentHandler

convertAttributesToMap

public Map convertAttributesToMap(org.xml.sax.Attributes attributeList)
converts the given instance of Attributes into a Map and returns it.
Parameters:
attributeList - the instance of Attributes
Returns:
a Map representation of the attributeList