Qizx/open API

net.axyana.qizxopen.dm
Class XMLSerializer

java.lang.Object
  extended bynet.axyana.qizxopen.dm.XMLEventReceiverBase
      extended bynet.axyana.qizxopen.dm.XMLSerializer
All Implemented Interfaces:
XMLEventReceiver
Direct Known Subclasses:
HTMLSerializer

public class XMLSerializer
extends XMLEventReceiverBase

Serializes a DataModel Node and its subtree to an output stream. Supports several output methods: XML, XHTML, HTML, and TEXT.

A Serializer is first instantiated, then several options can be defined through setOption(java.lang.String, java.lang.String), including the output method. An output stream can be specified with setOutput(Writer).

To serialize a node, use the output(Node) method.


Field Summary
static java.lang.String DOCTYPE_PUBLIC
           
static java.lang.String DOCTYPE_SYSTEM
           
static java.lang.String ENCODING
           
static java.lang.String ESCAPE_URI_ATTRIBUTES
           
static java.lang.String INCLUDE_CONTENT_TYPE
           
static java.lang.String INDENT
           
static java.lang.String INDENT_VALUE
           
static java.lang.String MEDIA_TYPE
           
static java.lang.String METHOD
           
static java.lang.String OMIT_XML_DECLARATION
           
static java.lang.String STANDALONE
           
static java.lang.String VERSION
           
 
Constructor Summary
XMLSerializer()
          Constructs a XMLSerializer with default XML output method.
XMLSerializer(java.lang.String method)
          Constructs a XMLSerializer with specification of an output method.
XMLSerializer(java.io.Writer output)
          Constructs a XMLSerializer with an output writer.
 
Method Summary
 void evAtomText(java.lang.String value)
          Text of an atom.
 void evComment(java.lang.String value)
          A comment node.
 void evDocumentEnd()
          Ends a document.
 void evDocumentStart()
          Starts a document.
 void evElementEnd(QName name)
          Ends an element.
 void evPI(java.lang.String target, java.lang.String value)
          A processing-instruction node.
 void evText(java.lang.String value)
          Text chunk inside an element.
 java.lang.String getEncoding()
          Returns the current encoding.
 java.io.BufferedWriter getOutput()
          Gets the current output as a Bufferedriter.
 void output(Node node)
          Serializes a node and its subtree.
 void reset()
          [internal: implementation of interface XMLEventReceiver] Prepares the serialization of another tree.
 void setDepth(int maxDepth)
          Extension: defines a maximum tree depth.
 void setIndent(int indent)
          Extension: defines the number of spaces used for one level of indentation.
 void setOption(java.lang.String option, java.lang.String value)
          Sets an option.
 void setOptions(XMLSerialOptions options)
           
 void setOutput(java.io.OutputStream output, java.lang.String encoding)
          Defines or redefines the output.
 void setOutput(java.io.Writer output)
          Defines or redefines the output.
 void terminate()
          [internal: implementation of interface XMLEventReceiver]
 void traverse(Node node)
          Lower-level output method.
 
Methods inherited from class net.axyana.qizxopen.dm.XMLEventReceiverBase
abort, definePrefixHints, evAtom, evAttribute, evDTD, evElementStart, evNamespace, maxVolumeReached, resolvePrefix, setMaxVolume, setTrace, traverse, traverse
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

METHOD

public static final java.lang.String METHOD
See Also:
Constant Field Values

ENCODING

public static final java.lang.String ENCODING
See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION
See Also:
Constant Field Values

OMIT_XML_DECLARATION

public static final java.lang.String OMIT_XML_DECLARATION
See Also:
Constant Field Values

STANDALONE

public static final java.lang.String STANDALONE
See Also:
Constant Field Values

DOCTYPE_SYSTEM

public static final java.lang.String DOCTYPE_SYSTEM
See Also:
Constant Field Values

DOCTYPE_PUBLIC

public static final java.lang.String DOCTYPE_PUBLIC
See Also:
Constant Field Values

MEDIA_TYPE

public static final java.lang.String MEDIA_TYPE
See Also:
Constant Field Values

ESCAPE_URI_ATTRIBUTES

public static final java.lang.String ESCAPE_URI_ATTRIBUTES
See Also:
Constant Field Values

INCLUDE_CONTENT_TYPE

public static final java.lang.String INCLUDE_CONTENT_TYPE
See Also:
Constant Field Values

INDENT

public static final java.lang.String INDENT
See Also:
Constant Field Values

INDENT_VALUE

public static final java.lang.String INDENT_VALUE
See Also:
Constant Field Values
Constructor Detail

XMLSerializer

public XMLSerializer()
Constructs a XMLSerializer with default XML output method.


XMLSerializer

public XMLSerializer(java.lang.String method)
              throws DataModelException
Constructs a XMLSerializer with specification of an output method.

Parameters:
method - output method name (case-insensitive): XML, XHTML, HTML, or TEXT.
Throws:
DataModelException - when the method name is invalid.

XMLSerializer

public XMLSerializer(java.io.Writer output)
Constructs a XMLSerializer with an output writer.

Parameters:
output - an open Writer, does not need to be buffered.
Method Detail

output

public void output(Node node)
            throws DataModelException
Serializes a node and its subtree.

Parameters:
node - node to serialize. If it is not a document, the XML header is not generated.
Throws:
DataModelException

setOutput

public void setOutput(java.io.OutputStream output,
                      java.lang.String encoding)
Defines or redefines the output.


setOutput

public void setOutput(java.io.Writer output)
Defines or redefines the output.


getOutput

public java.io.BufferedWriter getOutput()
Gets the current output as a Bufferedriter.


setOptions

public void setOptions(XMLSerialOptions options)
                throws DataModelException
Throws:
DataModelException

setOption

public void setOption(java.lang.String option,
                      java.lang.String value)
               throws DataModelException
Sets an option.

Supported options:

Parameters:
option - name of the option (see above).
value - option value in string form.
Throws:
DataModelException - on bad option name or value.

setDepth

public void setDepth(int maxDepth)
Extension: defines a maximum tree depth. Subtrees deeper than this value appear as an ellipsis '...'.


setIndent

public void setIndent(int indent)
Extension: defines the number of spaces used for one level of indentation.


getEncoding

public java.lang.String getEncoding()
Returns the current encoding.

The encoding can have been defined by setOutput or by setOption.


traverse

public void traverse(Node node)
              throws DataModelException
Lower-level output method. Must be preceded by reset(), and optionally startDocument().

Throws:
DataModelException

reset

public void reset()
[internal: implementation of interface XMLEventReceiver]

Prepares the serialization of another tree.

Specified by:
reset in interface XMLEventReceiver
Overrides:
reset in class XMLEventReceiverBase

terminate

public void terminate()
               throws DataModelException
[internal: implementation of interface XMLEventReceiver]

Specified by:
terminate in interface XMLEventReceiver
Overrides:
terminate in class XMLEventReceiverBase
Throws:
DataModelException

evDocumentStart

public void evDocumentStart()
                     throws DataModelException
Description copied from interface: XMLEventReceiver
Starts a document.

It is not called in the case only a fragment is generated.

Specified by:
evDocumentStart in interface XMLEventReceiver
Overrides:
evDocumentStart in class XMLEventReceiverBase
Throws:
DataModelException

evDocumentEnd

public void evDocumentEnd()
                   throws DataModelException
Description copied from interface: XMLEventReceiver
Ends a document. Must be balanced by a matching startDocument().

Specified by:
evDocumentEnd in interface XMLEventReceiver
Overrides:
evDocumentEnd in class XMLEventReceiverBase
Throws:
DataModelException

evElementEnd

public void evElementEnd(QName name)
                  throws DataModelException
Description copied from interface: XMLEventReceiver
Ends an element. Discards prefix/namespace mappings possibly defined by the element.

Specified by:
evElementEnd in interface XMLEventReceiver
Overrides:
evElementEnd in class XMLEventReceiverBase
Throws:
DataModelException

evText

public void evText(java.lang.String value)
Description copied from interface: XMLEventReceiver
Text chunk inside an element. No space is generated before or after.


evAtomText

public void evAtomText(java.lang.String value)
Description copied from interface: XMLEventReceiver
Text of an atom. The difference with text() is that a space in requested between two atoms.


evPI

public void evPI(java.lang.String target,
                 java.lang.String value)
Description copied from interface: XMLEventReceiver
A processing-instruction node.


evComment

public void evComment(java.lang.String value)
Description copied from interface: XMLEventReceiver
A comment node.


© 2005 Axyana Software