net.sf.xolite.sax
Class SaxXMLSerializer

java.lang.Object
  extended by net.sf.xolite.sax.SaxXMLSerializer
All Implemented Interfaces:
XMLSerializer

public class SaxXMLSerializer
extends Object
implements XMLSerializer

XMLSerializer passing all the serialization events to a SAX ContentHandler.

Author:
Olivier Berlanger

Constructor Summary
SaxXMLSerializer()
           
SaxXMLSerializer(ContentHandler theHandler)
           
 
Method Summary
 void attribute(String localName, String value)
          Add an attribute to the element that was just started.
 void attribute(String namespaceUri, String localName, String value)
          Add an attribute to the element that was just started.
 void characters(String text)
          Add character content of an element.
 void charactersMultiLine(String text)
          Same as characters but the text (supposed to be multi-line) is formatted to be an indented text block.
 void endDocument()
          End the current XML document.
 void endElement(String namespaceUri, String localName)
          End an XML element.
 ContentHandler getContentHandler()
           
 Object getCustomObject(Object key)
          Get back any custom object that was put in with the putCustomObject(key, value) method.
 void putCustomObject(Object key, Object value)
          Put a custom object in an internal Map.
 void serialize(XMLSerializable root)
           
 void setContentHandler(ContentHandler theHandler)
           
 void simpleElement(String namespaceUri, String localName, String text)
          This is a helper method useful to add a simpleType element in one call.
 void startDocument()
          Start an XML document.
 void startElement(String namespaceUri, String localName)
          Start an XML element.
 void startPrefixMapping(String prefix, String namespaceUri)
          Define a prefix mapping.
static boolean stringEquals(Object obj1, Object obj2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SaxXMLSerializer

public SaxXMLSerializer()

SaxXMLSerializer

public SaxXMLSerializer(ContentHandler theHandler)
Method Detail

setContentHandler

public void setContentHandler(ContentHandler theHandler)

getContentHandler

public ContentHandler getContentHandler()

serialize

public void serialize(XMLSerializable root)
               throws XMLSerializeException
Throws:
XMLSerializeException

startDocument

public void startDocument()
                   throws XMLSerializeException
Description copied from interface: XMLSerializer
Start an XML document.

Specified by:
startDocument in interface XMLSerializer
Throws:
XMLSerializeException

startElement

public void startElement(String namespaceUri,
                         String localName)
                  throws XMLSerializeException
Description copied from interface: XMLSerializer
Start an XML element.

Specified by:
startElement in interface XMLSerializer
Parameters:
namespaceUri - The element namespace URI (can be null if namespace are not used)
localName - The element local name (a.k.a. NCName)
Throws:
XMLSerializeException - if required action cannot be done (implementation dependent).

attribute

public void attribute(String localName,
                      String value)
               throws XMLSerializeException
Description copied from interface: XMLSerializer
Add an attribute to the element that was just started. All the call to this method must immediately follow a startElement call. attribute. This attribute use no namespace.

Specified by:
attribute in interface XMLSerializer
Parameters:
localName - The attribute local name (a.k.a. NCName)
value - the attribute value (null is treated as empty string).
Throws:
XMLSerializeException - if you don't call this method just after startElement or if required action cannot be done (implementation dependent).

attribute

public void attribute(String namespaceUri,
                      String localName,
                      String value)
               throws XMLSerializeException
Description copied from interface: XMLSerializer
Add an attribute to the element that was just started. All the call to this method must immediately follow a startElement call. attribute

Specified by:
attribute in interface XMLSerializer
Parameters:
namespaceUri - The attribute namespace URI. This URI is usually null because most of the time, attributes don't use a namespace.
localName - The attribute local name (a.k.a. NCName)
value - the attribute value (null is treated as empty string).
Throws:
XMLSerializeException - if you don't call this method just after startElement or if required action cannot be done (implementation dependent).

characters

public void characters(String text)
                throws XMLSerializeException
Description copied from interface: XMLSerializer
Add character content of an element. This method must be called between startElement (possibly followed by attribute) and endElement. If this method is called several times for the same element, the texts are concatenated.

Specified by:
characters in interface XMLSerializer
Parameters:
text - text of the currently started element.
Throws:
XMLSerializeException - if you don't call this method just beteween startElement and endElement or if required action cannot be done (implementation dependent).

charactersMultiLine

public void charactersMultiLine(String text)
                         throws XMLSerializeException
Description copied from interface: XMLSerializer
Same as characters but the text (supposed to be multi-line) is formatted to be an indented text block.
The result will look like:
            <tag>
                some text
                spanning multiple
                lines.
            </tag>
 
While usual output would have given:
            <tag>some text
      spanning multiple
      lines.</tag>
 
The original text can be retrieved (when parsing) with the ElementText.getMultilineText(..) method. This method will automatically remove the added space.

Specified by:
charactersMultiLine in interface XMLSerializer
Parameters:
text - the text to serialize in XML
Throws:
XMLSerializeException
See Also:
ElementText.getMultilineText(String, XMLEventParser)

endElement

public void endElement(String namespaceUri,
                       String localName)
                throws XMLSerializeException
Description copied from interface: XMLSerializer
End an XML element.

Specified by:
endElement in interface XMLSerializer
Parameters:
namespaceUri - The element namespace URI (can be null if namespace are not used)
localName - The element local name (a.k.a. NCName)
Throws:
XMLSerializeException - if required action cannot be done (implementation dependent).

endDocument

public void endDocument()
                 throws XMLSerializeException
Description copied from interface: XMLSerializer
End the current XML document.

Specified by:
endDocument in interface XMLSerializer
Throws:
XMLSerializeException

getCustomObject

public Object getCustomObject(Object key)
Description copied from interface: XMLSerializer
Get back any custom object that was put in with the putCustomObject(key, value) method.

Specified by:
getCustomObject in interface XMLSerializer
Parameters:
key - key of the custom object.
Returns:
the custom object.

putCustomObject

public void putCustomObject(Object key,
                            Object value)
Description copied from interface: XMLSerializer
Put a custom object in an internal Map.
It can be retrieved later with getCustomObject(key) method.

Specified by:
putCustomObject in interface XMLSerializer
Parameters:
key - key of the custom object.
value - custom object.

simpleElement

public void simpleElement(String namespaceUri,
                          String localName,
                          String text)
                   throws XMLSerializeException
Description copied from interface: XMLSerializer
This is a helper method useful to add a simpleType element in one call. It is strictly equivalent to the following sequence:
 startElement(namespaceUri, localName);
 characters(text);
 endElement(namespaceUri, localName);
 

Specified by:
simpleElement in interface XMLSerializer
Parameters:
namespaceUri - The element namespace URI (can be null if namespace are not used)
localName - The element local name (a.k.a. NCName)
text - text of the element.
Throws:
XMLSerializeException

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String namespaceUri)
                        throws XMLSerializeException
Description copied from interface: XMLSerializer
Define a prefix mapping. This method associate the given prefix to the given namespace. So when a node of the given namespace will be serialized, the given prefix will be used to denote the namespace (and the prefix declaration will be inserted when necessary).

This method should be called for each namespace URI before the first time they are used.

If the given namespace is already associated to another prefix (or the same prefix), this method call is ignored (i.e. first association wins).

If the given prefix is already associated to an other namespace, a new prefix is generated and mapped at the place of the given one.

Specified by:
startPrefixMapping in interface XMLSerializer
Parameters:
prefix - a prefix (can be "" for default prefix mapping)
namespaceUri - a namespace URI
Throws:
XMLSerializeException - if prefix or namespaceUri is null or if required action cannot be done (implementation dependent).

stringEquals

public static boolean stringEquals(Object obj1,
                                   Object obj2)


Copyright © 2012. All Rights Reserved.