org.xquark.serialize
Class BasicXMLSerializer

java.lang.Object
  |
  +--org.xml.sax.helpers.XMLFilterImpl
        |
        +--org.xquark.util.DefaultXMLFilter
              |
              +--org.xquark.serialize.BasicXMLSerializer
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.XMLFilter, org.xml.sax.XMLReader

public class BasicXMLSerializer
extends org.xquark.util.DefaultXMLFilter

A simple SAX2 XML serializer implementing SAX ContentHandler and LexicalHandler. IMPORTANT : Contrary to XMLSerializer, SAX2 XMLReader http://xml.org/sax/features/namespaces and http://xml.org/sax/features/namespace-prefixes features must be set to true for this serializer to work properly.


Constructor Summary
BasicXMLSerializer(java.io.OutputStream out)
          Creates new BasicXMLSerializer
BasicXMLSerializer(java.io.OutputStream out, java.lang.String encoding)
          Creates new BasicXMLSerializer
BasicXMLSerializer(java.io.Writer out)
          Creates new BasicXMLSerializer
BasicXMLSerializer(java.io.Writer out, java.lang.String encoding)
          Creates new BasicXMLSerializer
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void close()
          Closes the user stream.
 void comment(char[] ch, int start, int length)
           
 void completeStartTag()
           
 void endCDATA()
           
 void endDocument()
           
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
           
 void flush()
          Flushes the user stream.
 boolean getAutoStreamClose()
          Return the value set for stream automatic close feature.
 boolean getCanonicalOutput()
          Accessor to the current ordering mode for attributes.
 java.lang.String getDefaultEncoding()
           
 boolean getGenerateXMLDeclaration()
          Accessor to the current flag for XML declaration generation.
 boolean getIndent()
           
 boolean getUseIgnorableWhitespaces()
           
 void ignorableWhitespace(char[] ch, int start, int length)
           
 void processingInstruction(java.lang.String target, java.lang.String data)
           
 void reset()
          Reset internal state before reuse.
 void setAutoStreamClose(boolean close)
          Enable automatic close of the output user stream on endDocument() event.
 void setCanonicalOutput(boolean mode)
          Set the ordering mode for attributes.
 void setDefaultEncoding(java.lang.String encoding)
          Set the character encoding.
 void setGenerateEncodingDeclaration(boolean enable)
          Enable encoding attribute generation in XML declaration on startDocument() event.
 void setGenerateXMLDeclaration(boolean enable)
          Enable XML declaration generation on startDocument() event.
 void setIndent(boolean indent)
          Set the indenting mode.
 void setOutputStream(java.io.OutputStream out)
          Set the OutputStream where the serializer writes bytes.
 void setUseIgnorableWhitespaces(boolean use)
          Turn on or off the use of ignorable whitespace for indentation.
 void setWriter(java.io.Writer out)
          Set the Writer where the serializer writes characters.
 void startCDATA()
           
 void startDocument()
           
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
           
 
Methods inherited from class org.xquark.util.DefaultXMLFilter
endDTD, endEntity, getLexicalHandler, getProperty, setLexicalHandler, setProperty, startDTD, startEntity
 
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, notationDecl, parse, parse, resolveEntity, setContentHandler, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicXMLSerializer

public BasicXMLSerializer(java.io.OutputStream out)
                   throws java.io.UnsupportedEncodingException
Creates new BasicXMLSerializer

Parameters:
out - the OutputStream where the serializer writes bytes. For instance a FileOutputStream.

BasicXMLSerializer

public BasicXMLSerializer(java.io.Writer out)
Creates new BasicXMLSerializer

Parameters:
out - the writer where the serializer writes characters. For instance a FileOutputStream.

BasicXMLSerializer

public BasicXMLSerializer(java.io.OutputStream out,
                          java.lang.String encoding)
                   throws java.io.UnsupportedEncodingException
Creates new BasicXMLSerializer

Parameters:
out - the writer where the serializer writes characters. For instance a FileOutputStream.
encoding - a string for the MIME encoding (must be supported by the JDK used)
See Also:
OutputStream

BasicXMLSerializer

public BasicXMLSerializer(java.io.Writer out,
                          java.lang.String encoding)
Creates new BasicXMLSerializer

Parameters:
out - the OutputStream where the serializer writes bytes. For instance a FileOutputStream.
encoding - a string for the MIME encoding (must be compatible with the encoding used by the writer)
Method Detail

setOutputStream

public void setOutputStream(java.io.OutputStream out)
                     throws java.io.UnsupportedEncodingException
Set the OutputStream where the serializer writes bytes. Once this methods is called output Writer is created with the current encoding and will not change.

Parameters:
out - the OutputStream where the serializer writes bytes. For instance a FileOutputStream.
java.io.UnsupportedEncodingException

setWriter

public void setWriter(java.io.Writer out)
Set the Writer where the serializer writes characters. Once this methods is called output encoding is set with the current value and will not change.

Parameters:
out - the writer where the serializer writes characters. For instance a FileOutputStream.

setIndent

public void setIndent(boolean indent)
Set the indenting mode. Warning: Default behavior is to perform automatic indentation ( ignorable whitespaces generated by the XML processor are ignored).

Parameters:
indent - if true, tabs are used at the beginning of lines to indent the output file.

setUseIgnorableWhitespaces

public void setUseIgnorableWhitespaces(boolean use)
Turn on or off the use of ignorable whitespace for indentation. Warning: This flag is ignored if automatic indentation is on.

Parameters:
use - if true (the default), ignorable whitespace are used for indentation unless automatic indentation is on.

setCanonicalOutput

public void setCanonicalOutput(boolean mode)
Set the ordering mode for attributes. The default behavior is to perform no ordering.

Parameters:
mode - If true, ordering is performed following the Canonical XML W3C recommendation. If false, attributes are serialized as passed by the SAX2 XMLReader.

setDefaultEncoding

public void setDefaultEncoding(java.lang.String encoding)
Set the character encoding.

Parameters:
encoding - a string specifying the character encoding, which must be supported by the JDK. Example: UTF-8, ISO-8859-1

setGenerateXMLDeclaration

public void setGenerateXMLDeclaration(boolean enable)
Enable XML declaration generation on startDocument() event.

Parameters:
enable - XML Declaration is generated if true. Default is true.

setGenerateEncodingDeclaration

public void setGenerateEncodingDeclaration(boolean enable)
Enable encoding attribute generation in XML declaration on startDocument() event. Considered only if XML decleration enabled.

Parameters:
enable - encoding declaration generation if true. Default is true.

setAutoStreamClose

public void setAutoStreamClose(boolean close)
Enable automatic close of the output user stream on endDocument() event.

Parameters:
close - Output stream will be closed if true. Default is false.

getIndent

public boolean getIndent()
Returns:
the indenting mode.

getUseIgnorableWhitespaces

public boolean getUseIgnorableWhitespaces()
Returns:
the status of the use of gnorable whitespace by the serializer.

getCanonicalOutput

public boolean getCanonicalOutput()
Accessor to the current ordering mode for attributes.

Returns:
the current ordering mode for attributes.

getDefaultEncoding

public java.lang.String getDefaultEncoding()
Returns:
the character encoding in use, if previously specified.

getGenerateXMLDeclaration

public boolean getGenerateXMLDeclaration()
Accessor to the current flag for XML declaration generation.

Returns:
if true, the XML declaration will be generated.

getAutoStreamClose

public boolean getAutoStreamClose()
Return the value set for stream automatic close feature.

See Also:
setAutoStreamClose(boolean).

reset

public void reset()
Reset internal state before reuse.


close

public void close()
Closes the user stream.


flush

public void flush()
Flushes the user stream.


startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.XMLFilterImpl
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.XMLFilterImpl
org.xml.sax.SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Overrides:
ignorableWhitespace in class org.xml.sax.helpers.XMLFilterImpl
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.XMLFilterImpl
org.xml.sax.SAXException

completeStartTag

public void completeStartTag()

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Overrides:
processingInstruction in class org.xml.sax.helpers.XMLFilterImpl
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.XMLFilterImpl
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.XMLFilterImpl
org.xml.sax.SAXException

startCDATA

public void startCDATA()
                throws org.xml.sax.SAXException
Specified by:
startCDATA in interface org.xml.sax.ext.LexicalHandler
Overrides:
startCDATA in class org.xquark.util.DefaultXMLFilter
org.xml.sax.SAXException

endCDATA

public void endCDATA()
              throws org.xml.sax.SAXException
Specified by:
endCDATA in interface org.xml.sax.ext.LexicalHandler
Overrides:
endCDATA in class org.xquark.util.DefaultXMLFilter
org.xml.sax.SAXException

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws org.xml.sax.SAXException
Specified by:
comment in interface org.xml.sax.ext.LexicalHandler
Overrides:
comment in class org.xquark.util.DefaultXMLFilter
org.xml.sax.SAXException


Copyright © 2004 Université de Versailles Saint-Quentin, XQuark Group. All rights reserved.