org.apache.xml.serialize
Class DOMSerializerImpl

java.lang.Object
  |
  +--org.apache.xml.serialize.DOMSerializerImpl
All Implemented Interfaces:
org.w3c.dom.DOMConfiguration, org.w3c.dom.ls.DOMSerializer

public class DOMSerializerImpl
extends java.lang.Object
implements org.w3c.dom.ls.DOMSerializer, org.w3c.dom.DOMConfiguration

Implemenatation of DOM Level 3 org.w3c.ls.DOMSerializer by delegating serialization calls to XMLSerializer. DOMSerializer provides an API for serializing (writing) a DOM document out in an XML document. The XML data is written to an output stream. During serialization of XML data, namespace fixup is done when possible as defined in DOM Level 3 Core, Appendix B.

Version:
$Id: DOMSerializerImpl.java,v 1.3 2003/07/30 19:18:38 elena Exp $
Author:
Elena Litani, IBM, Gopal Sharma, Sun Microsystems, Arun Yadav, Sun Microsystems

Constructor Summary
DOMSerializerImpl()
          Constructs a new DOMSerializer.
 
Method Summary
 boolean canSetParameter(java.lang.String name, java.lang.Object state)
          DOM L3-EXPERIMENTAL: Check if parameter can be set
 org.w3c.dom.DOMConfiguration getConfig()
          The DOMConfiguration object used by the DOMSerializer when serializing a DOM node.
 org.w3c.dom.ls.DOMSerializerFilter getFilter()
          When the application provides a filter, the serializer will call out to the filter before serializing each Node.
 java.lang.String getNewLine()
          DOM L3 EXPERIMENTAL: The end-of-line sequence of characters to be used in the XML being written out.
 java.lang.Object getParameter(java.lang.String name)
          DOM L3-EXPERIMENTAL: Getter for boolean and object parameters
 void setFilter(org.w3c.dom.ls.DOMSerializerFilter filter)
          When the application provides a filter, the serializer will call out to the filter before serializing each Node.
 void setNewLine(java.lang.String newLine)
          DOM L3 EXPERIMENTAL: The end-of-line sequence of characters to be used in the XML being written out.
 void setParameter(java.lang.String name, java.lang.Object value)
          DOM L3-EXPERIMENTAL: Setter for boolean and object parameters
 boolean write(org.w3c.dom.Node node, org.w3c.dom.ls.DOMOutput destination)
          Serialize the specified node as described above in the general description of the DOMSerializer interface.
 java.lang.String writeToString(org.w3c.dom.Node wnode)
          DOM L3 EXPERIMENTAL: Serialize the specified node as described above in the description of DOMSerializer.
 boolean writeURI(org.w3c.dom.Node node, java.lang.String URI)
          Serialize the specified node as described above in the general description of the DOMSerializer interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMSerializerImpl

public DOMSerializerImpl()
Constructs a new DOMSerializer. The constructor turns on the namespace support in XMLSerializer and initializes the following fields: fNSBinder, fLocalNSBinder, fSymbolTable, fEmptySymbol, fXmlSymbol, fXmlnsSymbol, fNamespaceCounter, fFeatures.

Method Detail

getConfig

public org.w3c.dom.DOMConfiguration getConfig()
Description copied from interface: org.w3c.dom.ls.DOMSerializer
The DOMConfiguration object used by the DOMSerializer when serializing a DOM node.
In addition to the parameters recognized in the [DOM Level 3 Core] , the DOMConfiguration objects for DOMSerializer adds, or modifies, the following parameters:
"canonical-form"
true
[optional] This formatting writes the document according to the rules specified in [Canonical XML]. Setting this parameter to true will set the parameter " format-pretty-print" to false.
false
[required] (default) Do not canonicalize the output.
"discard-default-content"
true
[required] (default) Use the Attr.specified attribute to decide what attributes should be discarded. Note that some implementations might use whatever information available to the implementation (i.e. XML schema, DTD, the Attr.specified attribute, and so on) to determine what attributes and content to discard if this parameter is set to true.
false
[required]Keep all attributes and all content.
"format-pretty-print"
true
[optional] Formatting the output by adding whitespace to produce a pretty-printed, indented, human-readable form. The exact form of the transformations is not specified by this specification. Pretty-printing changes the content of the document and may affect the validity of the document, validating implementations should preserve validity. Setting this parameter to true will set the parameter " canonical-form" to false.
false
[required] (default) Don't pretty-print the result.
"ignore-unknown-character-denormalizations"
true
[required] (default) If, while verifying full normalization when [XML 1.1] is supported, a character is encountered for which the normalization properties cannot be determined, then raise a "unknown-character-denormalization" warning (instead of raising an error, if this parameter is not set) and ignore any possible denormalizations caused by these characters. IMO it would make sense to move this parameter into the DOM Level 3 Core spec, and the error/warning should be defined there.
false
[optional] Report an fatal error if a character is encountered for which the processor cannot determine the normalization properties.
"normalize-characters"
This parameter is equivalent to the one defined by DOMConfiguration in [DOM Level 3 Core] . Unlike in the Core, the default value for this parameter is true. While DOM implementations are not required to support fully normalizing the characters in the document according to the rules defined in [CharModel] supplemented by the definitions of relevant constructs from Section 2.13 of [XML 1.1], this parameter must be activated by default if supported.
"xml-declaration"
true
[required] (default) If a Document, Element, or Entity node is serialized, the XML declaration, or text declaration, should be included. The version (Document.xmlVersion if the document is a Level 3 document, and the version is non-null, otherwise use the value "1.0"), and possibly an encoding ( DOMSerializer.encoding, or Document.actualEncoding or Document.xmlEncoding if the document is a Level 3 document) is specified in the serialized XML declaration.
false
[required] Do not serialize the XML and text declarations. Report a "xml-declaration-needed" warning if this will cause problems (i.e. the serialized data is of an XML version other than [XML 1.0], or an encoding would be needed to be able to re-parse the serialized data).

The parameters " well-formed", " namespaces", and " namespace-declarations" cannot be set to false.

Specified by:
getConfig in interface org.w3c.dom.ls.DOMSerializer

setParameter

public void setParameter(java.lang.String name,
                         java.lang.Object value)
                  throws org.w3c.dom.DOMException
DOM L3-EXPERIMENTAL: Setter for boolean and object parameters

Specified by:
setParameter in interface org.w3c.dom.DOMConfiguration
Parameters:
name - The name of the parameter to set.
value - The new value or null if the user wishes to unset the parameter. While the type of the value parameter is defined as DOMUserData, the object type must match the type defined by the definition of the parameter. For example, if the parameter is "error-handler", the value must be of type DOMErrorHandler.
org.w3c.dom.DOMException

canSetParameter

public boolean canSetParameter(java.lang.String name,
                               java.lang.Object state)
DOM L3-EXPERIMENTAL: Check if parameter can be set

Specified by:
canSetParameter in interface org.w3c.dom.DOMConfiguration
Parameters:
name - The name of the parameter to check.
state - An object. if null, the returned value is true.
Returns:
true if the parameter could be successfully set to the specified value, or false if the parameter is not recognized or the requested value is not supported. This does not change the current value of the parameter itself.

getParameter

public java.lang.Object getParameter(java.lang.String name)
                              throws org.w3c.dom.DOMException
DOM L3-EXPERIMENTAL: Getter for boolean and object parameters

Specified by:
getParameter in interface org.w3c.dom.DOMConfiguration
Parameters:
name - The name of the parameter.
Returns:
The current object associated with the specified parameter or null if no object has been associated or if the parameter is not supported.
org.w3c.dom.DOMException

writeToString

public java.lang.String writeToString(org.w3c.dom.Node wnode)
                               throws org.w3c.dom.DOMException
DOM L3 EXPERIMENTAL: Serialize the specified node as described above in the description of DOMSerializer. The result of serializing the node is returned as a string. Writing a Document or Entity node produces a serialized form that is well formed XML. Writing other node types produces a fragment of text in a form that is not fully defined by this document, but that should be useful to a human for debugging or diagnostic purposes.

Specified by:
writeToString in interface org.w3c.dom.ls.DOMSerializer
Parameters:
wnode - The node to be written.
Returns:
Returns the serialized data, or null in case a failure occured and the failure wasn't canceled by the error handler.
Throws:
org.w3c.dom.DOMException - DOMSTRING_SIZE_ERR: The resulting string is too long to fit in a DOMString.

setNewLine

public void setNewLine(java.lang.String newLine)
DOM L3 EXPERIMENTAL: The end-of-line sequence of characters to be used in the XML being written out. The only permitted values are these:
null
Use a default end-of-line sequence. DOM implementations should choose the default to match the usual convention for text files in the environment being used. Implementations must choose a default sequence that matches one of those allowed by 2.11 "End-of-Line Handling".
CR
The carriage-return character (#xD).
CR-LF
The carriage-return and line-feed characters (#xD #xA).
LF
The line-feed character (#xA).

The default value for this attribute is null.

Specified by:
setNewLine in interface org.w3c.dom.ls.DOMSerializer

getNewLine

public java.lang.String getNewLine()
DOM L3 EXPERIMENTAL: The end-of-line sequence of characters to be used in the XML being written out. The only permitted values are these:
null
Use a default end-of-line sequence. DOM implementations should choose the default to match the usual convention for text files in the environment being used. Implementations must choose a default sequence that matches one of those allowed by 2.11 "End-of-Line Handling".
CR
The carriage-return character (#xD).
CR-LF
The carriage-return and line-feed characters (#xD #xA).
LF
The line-feed character (#xA).

The default value for this attribute is null.

Specified by:
getNewLine in interface org.w3c.dom.ls.DOMSerializer

getFilter

public org.w3c.dom.ls.DOMSerializerFilter getFilter()
When the application provides a filter, the serializer will call out to the filter before serializing each Node. Attribute nodes are never passed to the filter. The filter implementation can choose to remove the node from the stream or to terminate the serialization early.

Specified by:
getFilter in interface org.w3c.dom.ls.DOMSerializer

setFilter

public void setFilter(org.w3c.dom.ls.DOMSerializerFilter filter)
When the application provides a filter, the serializer will call out to the filter before serializing each Node. Attribute nodes are never passed to the filter. The filter implementation can choose to remove the node from the stream or to terminate the serialization early.

Specified by:
setFilter in interface org.w3c.dom.ls.DOMSerializer

write

public boolean write(org.w3c.dom.Node node,
                     org.w3c.dom.ls.DOMOutput destination)
Serialize the specified node as described above in the general description of the DOMSerializer interface. The output is written to the supplied DOMOutput.
When writing to a DOMOutput, the encoding is found by looking at the encoding information that is reachable through the DOMOutput and the item to be written (or its owner document) in this order:
  1. DOMOutput.encoding,
  2. Document.actualEncoding,
  3. Document.xmlEncoding.

If no encoding is reachable through the above properties, a default encoding of "UTF-8" will be used.
If the specified encoding is not supported an "unsupported-encoding" error is raised.
If no output is specified in the DOMOutput, a "no-output-specified" error is raised.

Specified by:
write in interface org.w3c.dom.ls.DOMSerializer
Parameters:
node - The node to serialize.
destination - The destination for the serialized DOM.
Returns:
Returns true if node was successfully serialized and false in case the node couldn't be serialized.

writeURI

public boolean writeURI(org.w3c.dom.Node node,
                        java.lang.String URI)
Serialize the specified node as described above in the general description of the DOMSerializer interface. The output is written to the supplied URI.
When writing to a URI, the encoding is found by looking at the encoding information that is reachable through the item to be written (or its owner document) in this order:
  1. Document.actualEncoding,
  2. Document.xmlEncoding.

If no encoding is reachable through the above properties, a default encoding of "UTF-8" will be used.
If the specified encoding is not supported an "unsupported-encoding" error is raised.

Specified by:
writeURI in interface org.w3c.dom.ls.DOMSerializer
Parameters:
node - The node to serialize.
URI - The URI to write to.
Returns:
Returns true if node was successfully serialized and false in case the node couldn't be serialized.


Copyright ? 1999-2003 Apache XML Project. All Rights Reserved.