Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Qizx/open 4.1 API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.qizx.api.util
Class XMLSerializer

    java.lang.Object
      com.qizx.xdm.AttributeList
          com.qizx.xdm.XMLPushStreamBase
              com.qizx.api.util.XMLSerializer

All Implemented Interfaces:
  XMLPushStream, Attributes

    public class XMLSerializer

extends com.qizx.xdm.XMLPushStreamBase
implements XMLPushStream

An implementation of XMLPushStream that serializes into XML, XHTML, HTML or plain text.

Can be used to export a `Node`: see `Item.export(XMLPushStream)`

Field Summary
`static String` | `AUTO_DTD` name of option used to inhibit the automatic generation of DOCTYPE (extension): value is a boolean (true by default) that indicates that a DOCTYPE should be generated on documents stored in XML Libraries, having properties System/Public ID.
`static String` | `DOCTYPE_PUBLIC` name of option specifying the Public Id of the DTD declaration
`static String` | `DOCTYPE_SYSTEM` name of option specifying the System Id of the DTD declaration
`static String` | `ENCODING` name of option specifying the output encoding: the value must be a valid encoding name, supported by the JRE.
`static String` | `ESCAPE_URI_ATTRIBUTES` name of option escape-uri-attributes (NOT IMPLEMENTED)
`static String` | `INCLUDE_CONTENT_TYPE` name of option specifying the Content-Type meta in HTML
`static String` | `INDENT` name of option specifying the whether the output is indented: value is a boolean "yes" or "no".
`static String` | `INDENT_VALUE` name of option specifying the indentation (extension): value is an integer which represents the number of spaces.
`static String` | `MEDIA_TYPE` name of option specifying the media type (NOT IMPLEMENTED)
`static String` | `METHOD` name of option specifying the output style: the value must be "XML", "HTML", "XHTML", "TEXT".
`static String` | `OMIT_XML_DECLARATION` name of option enabling or disabling the XML declaration.
`static String` | `STANDALONE` name of option specifying 'standalone' in the XML declaration.
`static String` | `STRIP_COMMENT` name of option specifying the omission of comments (extension): value is a boolean (false by default) that indicates that comments must be stripped (when set to true).
`static String` | `STRIP_PI` name of option specifying the omission of processing instructions (extension): value is a boolean (false by default) that indicates that PI must be stripped (when set to true).
`static String` | `VERSION` name of option specifying the XML version.

Fields inherited from interface com.qizx.api.XMLPushStream
`NSCOPY_NOPRESERVE_INHERIT, NSCOPY_NOPRESERVE_NOINHERIT, NSCOPY_PRESERVE_INHERIT, NSCOPY_PRESERVE_NOINHERIT`

Constructor Summary
`XMLSerializer()` Constructs a XMLSerializer with default XML output method.
`XMLSerializer(OutputStream output, String encoding)` Constructs a XMLSerializer with an output stream and an encoding name.
`XMLSerializer(String method)` Constructs a XMLSerializer with specification of an output method.
`XMLSerializer(Writer output)` Constructs a XMLSerializer with an output writer.

Method Summary
`void` | `flush()` Flush of the output flow.
`String` | `getEncoding()` Returns the current encoding.
`BufferedWriter` | `getOutput()` Gets the current output as a BufferedWriter.
`boolean` | `hasAutoDTD()`
`void` | `output(Node node)` Serializes a node and its subtree.
`void` | `println()` Outputs an end-of-line.
`void` | `putAtomText(String value)` Puts the value of an atomic item.
`void` | `putComment(String contents)` Puts a Comment event.
`void` | `putDocumentEnd()` Puts a Document End event.
`boolean` | `putDocumentStart()` Puts a Document Start event.
`void` | `putElementEnd(QName name)` Puts an Element End event.
`void` | `putNodeCopy(Node node, int copyNsMode)` Traverse and generate a subtree.
`void` | `putProcessingInstruction(String target, String contents)` Puts a Processing-instruction event.
`void` | `putText(String value)` Puts a Text Fragment event.
`void` | `reset()` Prepares the serialization of another tree.
`String` | `serializeToString(Node node)` Serializes a node and its subtree as a string.
`void` | `setEncoding(String encoding)` Sets the option ENCODING.
`void` | `setIndent(int value)` Extension: defines the number of spaces used for one level of indentation.
`void` | `setOmitXMLDeclaration(boolean omit)` Sets the option OMIT_XML_DECLARATION
`void` | `setOption(String option, String value)` Sets an option.
`void` | `setOutput(OutputStream output)` Defines or redefines the output.
`void` | `setOutput(OutputStream output, String encoding)` Defines or redefines the output.
`void` | `setOutput(Writer output)` Defines or redefines the output.

Methods inherited from class com.qizx.xdm.XMLPushStreamBase
`abort, defineContextMappings, getNSPrefix, getNSURI, isAtRoot, maxVolumeReached, noSpace, putAtom, putAttribute, putChars, putDTD, putElementStart, putLongAtom, putNamespace, putNamespaces, putNodeCopy, putNodeText, setCheckNS, setMaxVolume, setTrace`

Methods inherited from class com.qizx.xdm.AttributeList
`addAttribute, getAttributeCount, getIndex, getIndex, getIndex, getLength, getLocalName, getNamespaceContext, getNamespaceCount, getNamespacePrefix, getNamespaceURI, getQName, getType, getType, getType, getURI, getValue, getValue, getValue`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface com.qizx.api.XMLPushStream
`getNSPrefix, getNSURI, putAttribute, putChars, putDTD, putElementStart, putNamespace, putNamespaces`

Field Detail

### METHOD

    public static final String METHOD

  name of option specifying the output style: the value must be "XML", "HTML", "XHTML", "TEXT".

  See Also:
    Constant Field Values

### ENCODING

    public static final String ENCODING

  name of option specifying the output encoding: the value must be a valid encoding name, supported by the JRE.

  See Also:
    Constant Field Values

### VERSION

    public static final String VERSION

  name of option specifying the XML version. Value must be "1.0" or "1.1"

  See Also:
    Constant Field Values

### OMIT_XML_DECLARATION

    public static final String OMIT_XML_DECLARATION

  name of option enabling or disabling the XML declaration. Value must be boolean "true", "false, "yes", "no". Automatically enabled when the options VERSION, STANDALONE or ENCODING (other than UTF-8) are set

  See Also:
    Constant Field Values

### STANDALONE

    public static final String STANDALONE

  name of option specifying 'standalone' in the XML declaration. Value must be "yes" or "no"

  See Also:
    Constant Field Values

### DOCTYPE_SYSTEM

    public static final String DOCTYPE_SYSTEM

  name of option specifying the System Id of the DTD declaration

  See Also:
    Constant Field Values

### DOCTYPE_PUBLIC

    public static final String DOCTYPE_PUBLIC

  name of option specifying the Public Id of the DTD declaration

  See Also:
    Constant Field Values

### INCLUDE_CONTENT_TYPE

    public static final String INCLUDE_CONTENT_TYPE

  name of option specifying the Content-Type meta in HTML

  See Also:
    Constant Field Values

### MEDIA_TYPE

    public static final String MEDIA_TYPE

  name of option specifying the media type (NOT IMPLEMENTED)

  See Also:
    Constant Field Values

### ESCAPE_URI_ATTRIBUTES

    public static final String ESCAPE_URI_ATTRIBUTES

  name of option escape-uri-attributes (NOT IMPLEMENTED)

  See Also:
    Constant Field Values

### INDENT

    public static final String INDENT

  name of option specifying the whether the output is indented: value is a boolean "yes" or "no". The number of speces (default 2) is specified by option INDENT_VALUE

  See Also:
    Constant Field Values

### INDENT_VALUE

    public static final String INDENT_VALUE

  name of option specifying the indentation (extension): value is an integer which represents the number of spaces. If negative, the indentation is disabled.

  See Also:
    Constant Field Values

### STRIP_PI

    public static final String STRIP_PI

  name of option specifying the omission of processing instructions (extension): value is a boolean (false by default) that indicates that PI must be stripped (when set to true).

  See Also:
    Constant Field Values

### STRIP_COMMENT

    public static final String STRIP_COMMENT

  name of option specifying the omission of comments (extension): value is a boolean (false by default) that indicates that comments must be stripped (when set to true).

  See Also:
    Constant Field Values

### AUTO_DTD

    public static final String AUTO_DTD

  name of option used to inhibit the automatic generation of DOCTYPE (extension): value is a boolean (true by default) that indicates that a DOCTYPE should be generated on documents stored in XML Libraries, having properties System/Public ID.

  See Also:
    Constant Field Values

Constructor Detail

### XMLSerializer

    public XMLSerializer()

  Constructs a XMLSerializer with default XML output method.

### XMLSerializer

    public XMLSerializer(OutputStream output,
                         String encoding)
                  throws DataModelException

  Constructs a XMLSerializer with an output stream and an encoding name.

  Parameters:
    `output` - an open output stream
    `encoding` - the name of a supported encoding, or null to use the default platform encoding
  Throws:
    `DataModelException` - for an invalid encoding

### XMLSerializer

    public XMLSerializer(Writer output)

  Constructs a XMLSerializer with an output writer.

  Attention: Encoding must be specified separately through options. Should be compatible with the writer.

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

### XMLSerializer

    public XMLSerializer(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.

Method Detail

### setOutput

    public void setOutput(OutputStream output,
                          String encoding)
                   throws DataModelException

  Defines or redefines the output.

  Parameters:
    `output` - an open output stream
    `encoding` - the name of a supported encoding, or null to use the default platform encoding
  Throws:
    `DataModelException` - for an invalid encoding

### setOutput

    public void setOutput(Writer output)
                   throws DataModelException

  Defines or redefines the output.

  Throws:
    `DataModelException` - for an invalid encoding

### setOutput

    public void setOutput(OutputStream output)
                   throws DataModelException

  Defines or redefines the output.

  The encoding is UTF-8.

  Throws:
    `DataModelException`

### getOutput

    public BufferedWriter getOutput()

  Gets the current output as a BufferedWriter.

### getEncoding

    public String getEncoding()

  Returns the current encoding.

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

  Returns:
    the current encoding as a String (default is UTF-8)

### setEncoding

    public void setEncoding(String encoding)
                     throws DataModelException

  Sets the option ENCODING. Caution: does not affect the encoding of the output stream if any.

  Parameters:
    `encoding` - a supported encoding or null for UTF-8
  Throws:
    `DataModelException` - for an invalid encoding

### hasAutoDTD

    public boolean hasAutoDTD()

### setOmitXMLDeclaration

    public void setOmitXMLDeclaration(boolean omit)

  Sets the option OMIT_XML_DECLARATION

  Parameters:
    `omit` - true to omit the declaration

### output

    public void output(Node node)
                throws DataModelException

  Serializes a node and its subtree. Calls reset() before serialization and flush() after serialization.

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

### putNodeCopy

    public void putNodeCopy(Node node,
                            int copyNsMode)
                     throws DataModelException

  Description copied from class: `com.qizx.xdm.XMLPushStreamBase`
  Traverse and generate a subtree.

  Specified by:
    `putNodeCopy` in interface `XMLPushStream`
  Overrides:
    `putNodeCopy` in class `com.qizx.xdm.XMLPushStreamBase`
  Parameters:
    `node` - Node to include in the output flow.
    `copyNsMode` - one of the 4 combinations of PRESERVE and INHERIT. The normal mode is NSCOPY_PRESERVE_INHERIT.
  Throws:
    `DataModelException` - reasons

### serializeToString

    public String serializeToString(Node node)
                             throws DataModelException

  Serializes a node and its subtree as a string.

  Parameters:
    `node` - node to serialize. If it is not a document, the XML header is not generated.
  Returns:
    a String representing the serialization of the node. The 'encoding' option is not used.
  Throws:
    `DataModelException` - wraps an output error

### setOption

    public void setOption(String option,
                          String value)
                   throws DataModelException

  Sets an option.

  Supported options:

  - "method" : value is "XML" (default), "XHTML", "HTML" or "TEXT"
  - "encoding" : an encoding supported by Java.
  - "version" : simply generated in XML declaration, not checked.
  - "omit-xml-declaration" : value is "yes" or "no".
  - "standalone" : value is "yes" or "no".
  - "doctype-system" : system id of DTD.
  - "doctype-public" : public id of DTD.
  - "media-type" :
  - "escape-uri-attributes" : value is "yes" or "no".
  - "include-content-type" :
  - "indent" : value is "yes" or "no".
  - "indent-value" : integer number of spaces used for indenting
  - "auto-dtd": boolean (defaults to true) if DTD information is found in document, then generate a DOCTYPE declaration from it. (non-standard).

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

### setIndent

    public void setIndent(int value)

  Extension: defines the number of spaces used for one level of indentation.

  Parameters:
    `value` - the number of spaces for indentation. If < 0, disables indentation.

### reset

    public void reset()

  Prepares the serialization of another tree.

  Overrides:
    `reset` in class `com.qizx.xdm.XMLPushStreamBase`

### flush

    public void flush()
               throws DataModelException

  Flush of the output flow.

  It is strongly recommended to call this method at end of a serialization except if you use `output(Node)` which calls it, or if the Node to serialize is a document-node (because putDocumentEnd calls this method automatically).

  Specified by:
    `flush` in interface `XMLPushStream`
  Overrides:
    `flush` in class `com.qizx.xdm.XMLPushStreamBase`
  Throws:
    `DataModelException` - wraps a possible output error (IOException).

### putDocumentStart

    public boolean putDocumentStart()
                             throws DataModelException

  Description copied from interface: `XMLPushStream`
  Puts a Document Start event. This method should be called first if the result is meant to be a well-formed document. However it it possible to omit it (and putDocumentEnd) if the desired result is an element.

  Specified by:
    `putDocumentStart` in interface `XMLPushStream`
  Overrides:
    `putDocumentStart` in class `com.qizx.xdm.XMLPushStreamBase`
  Returns:
    false if the current stream position is already inside a node (this event is then ignored)
  Throws:
    `DataModelException` - reasons

### putDocumentEnd

    public void putDocumentEnd()
                        throws DataModelException

  Description copied from interface: `XMLPushStream`
  Puts a Document End event.

  Specified by:
    `putDocumentEnd` in interface `XMLPushStream`
  Overrides:
    `putDocumentEnd` in class `com.qizx.xdm.XMLPushStreamBase`
  Throws:
    `DataModelException` - reasons

### putElementEnd

    public void putElementEnd(QName name)
                       throws DataModelException

  Description copied from interface: `XMLPushStream`
  Puts an Element End event. Should balance putElementStart exactly, else the result could be incorrect.

  Specified by:
    `putElementEnd` in interface `XMLPushStream`
  Overrides:
    `putElementEnd` in class `com.qizx.xdm.XMLPushStreamBase`
  Parameters:
    `name` - qualified name of the element
  Throws:
    `DataModelException` - reasons

### putText

    public void putText(String value)
                 throws DataModelException

  Description copied from interface: `XMLPushStream`
  Puts a Text Fragment event.

  A text fragment should appear inside an element. Consecutive text events are coalesced into one. An empty text fragment is discarded.

  Specified by:
    `putText` in interface `XMLPushStream`
  Parameters:
    `value` - a fragment of text
  Throws:
    `DataModelException` - reasons

### putAtomText

    public void putAtomText(String value)
                     throws DataModelException

  Description copied from class: `com.qizx.xdm.XMLPushStreamBase`
  Puts the value of an atomic item. Differs from putText by a space added automatically if needed.

  Overrides:
    `putAtomText` in class `com.qizx.xdm.XMLPushStreamBase`
  Throws:
    `DataModelException`

### putProcessingInstruction

    public void putProcessingInstruction(String target,
                                         String contents)
                                  throws DataModelException

  Description copied from interface: `XMLPushStream`
  Puts a Processing-instruction event.

  Specified by:
    `putProcessingInstruction` in interface `XMLPushStream`
  Overrides:
    `putProcessingInstruction` in class `com.qizx.xdm.XMLPushStreamBase`
  Parameters:
    `target` - target (name) of the PI
    `contents` - contents of the PI
  Throws:
    `DataModelException` - reasons

### putComment

    public void putComment(String contents)
                    throws DataModelException

  Description copied from interface: `XMLPushStream`
  Puts a Comment event.

  Specified by:
    `putComment` in interface `XMLPushStream`
  Overrides:
    `putComment` in class `com.qizx.xdm.XMLPushStreamBase`
  Parameters:
    `contents` - contents of a comment.
  Throws:
    `DataModelException` - reasons

### println

    public void println()

  Outputs an end-of-line.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| © 2010 Axyana Software
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD