nu.staldal.xodus
Class Serializer

java.lang.Object
  extended by nu.staldal.xodus.Serializer
All Implemented Interfaces:
java.lang.Appendable, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.ext.DeclHandler, org.xml.sax.ext.LexicalHandler
Direct Known Subclasses:
HTMLSerializer, TextSerializer, XMLSerializer

public abstract class Serializer
extends java.lang.Object
implements org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.DTDHandler, org.xml.sax.ext.DeclHandler, java.lang.Appendable

Serialize SAX2 events to its textual XML representation.

Support output to XML, XHTML, HTML and Text. Full support for XML namespaces.

The ContentHandler.startDocument() and ContentHandler.endDocument() method must be used.

Output properties controls the serialization process, it uses the keys in javax.xml.transform.OutputKeys.

The METHOD output property must be specified. It can be "xml", "xhtml", "text" or "html".

The CDATA_SECTION_ELEMENTS output property is not supported.

The ENCODING output property defaults to UTF-8 for XML and XHTML, and to ISO-8859-1 for Text and HTML.

The "html" output method does not escape non-ASCII characters in URI attribute values, as specified in the XSLT 1.0 specification.

javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING and javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING can be used as processingInstruction targets to disable output escaping.

The methods specified in the Appendable interface will act like the characters(java.lang.CharSequence) methods.

Illegal XML/HTML output may be created for inproper input, this class does not make effort to detect errors.

If the StreamResult specifies a Writer or Appendable, non-ASCII characters will not be escaped. "<", ">", "&", '"' and "'" are always escaped properly.


Field Summary
protected  XMLCharacterEncoder out
           
protected  OutputConfig outputConfig
           
protected  java.lang.String systemId
           
 
Constructor Summary
protected Serializer(javax.xml.transform.stream.StreamResult result, OutputConfig outputConfig)
           
 
Method Summary
abstract  void characters(java.lang.CharSequence cs)
          Alternative method for convenience and efficiency (no need to copy a String into a char[]).
abstract  void comment(java.lang.CharSequence cs)
          Alternative method for convenience and efficiency (no need to copy a String into a char[]).
static Serializer createSerializer(javax.xml.transform.stream.StreamResult result, java.util.Properties outputProperties)
          Factory method, create a new Serializer.
protected  void finishOutput()
          Finish writing to output.
abstract  void ignorableWhitespace(java.lang.CharSequence cs)
          Alternative method for convenience and efficiency (no need to copy a String into a char[]).
protected  void newline()
          Write a newline.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xml.sax.ContentHandler
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping
 
Methods inherited from interface org.xml.sax.ext.LexicalHandler
comment, endCDATA, endDTD, endEntity, startCDATA, startDTD, startEntity
 
Methods inherited from interface org.xml.sax.DTDHandler
notationDecl, unparsedEntityDecl
 
Methods inherited from interface org.xml.sax.ext.DeclHandler
attributeDecl, elementDecl, externalEntityDecl, internalEntityDecl
 
Methods inherited from interface java.lang.Appendable
append, append, append
 

Field Detail

outputConfig

protected final OutputConfig outputConfig

systemId

protected final java.lang.String systemId

out

protected final XMLCharacterEncoder out
Constructor Detail

Serializer

protected Serializer(javax.xml.transform.stream.StreamResult result,
                     OutputConfig outputConfig)
              throws java.lang.IllegalArgumentException,
                     java.io.IOException,
                     java.io.UnsupportedEncodingException
Throws:
java.lang.IllegalArgumentException
java.io.IOException
java.io.UnsupportedEncodingException
Method Detail

createSerializer

public static Serializer createSerializer(javax.xml.transform.stream.StreamResult result,
                                          java.util.Properties outputProperties)
                                   throws java.lang.IllegalArgumentException,
                                          java.io.IOException,
                                          java.io.UnsupportedEncodingException
Factory method, create a new Serializer.

Parameters:
result - specifies where to write the textual representation.
outputProperties - output properties, uses OutputKeys
Returns:
a new Serializer
Throws:
java.io.UnsupportedEncodingException - if the ENCODING output property is invalid.
java.lang.IllegalArgumentException - if any other output property is invalid.
java.io.IOException - if the result is invalid.

finishOutput

protected void finishOutput()
                     throws java.io.IOException
Finish writing to output. Does not close output if an OutputStream or Writer was provided.

Throws:
java.io.IOException

newline

protected void newline()
                throws java.io.IOException
Write a newline.

Throws:
java.io.IOException

characters

public abstract void characters(java.lang.CharSequence cs)
                         throws org.xml.sax.SAXException
Alternative method for convenience and efficiency (no need to copy a String into a char[]).

Parameters:
cs - a CharSequence, e.g. a String.
Throws:
org.xml.sax.SAXException - declared to throw SAXException to be consistent with ContentHandler

ignorableWhitespace

public abstract void ignorableWhitespace(java.lang.CharSequence cs)
                                  throws org.xml.sax.SAXException
Alternative method for convenience and efficiency (no need to copy a String into a char[]).

Parameters:
cs - a CharSequence, e.g. a String.
Throws:
org.xml.sax.SAXException - declared to throw SAXException to be consistent with ContentHandler

comment

public abstract void comment(java.lang.CharSequence cs)
                      throws org.xml.sax.SAXException
Alternative method for convenience and efficiency (no need to copy a String into a char[]).

Parameters:
cs - a CharSequence, e.g. a String.
Throws:
org.xml.sax.SAXException - declared to throw SAXException to be consistent with ContentHandler