org.apache.xml.serialize
Class DOMWriterImpl

java.lang.Object
  |
  +--org.apache.xml.serialize.DOMWriterImpl
All Implemented Interfaces:
org.apache.xerces.dom3.DOMConfiguration, org.w3c.dom.ls.DOMWriter

public class DOMWriterImpl
extends java.lang.Object
implements org.w3c.dom.ls.DOMWriter, org.apache.xerces.dom3.DOMConfiguration

Implemenatation of DOM Level 3 org.w3c.ls.DOMWriter by delegating serialization calls to XMLSerializer. DOMWriter 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: DOMWriterImpl.java,v 1.10 2003/01/03 21:51:25 neilg Exp $
Author:
Elena Litani, IBM

Constructor Summary
DOMWriterImpl()
          Constructs a new DOMWriter.
 
Method Summary
 boolean canSetParameter(java.lang.String name, java.lang.Object state)
          DOM L3-EXPERIMENTAL: Check if parameter can be set
 org.apache.xerces.dom3.DOMConfiguration getConfig()
          The configuration used when a document is loaded.
 java.lang.String getEncoding()
          DOM L3 EXPERIMENTAL: The character encoding in which the output will be written.
 org.apache.xerces.dom3.DOMErrorHandler getErrorHandler()
          The error handler that will receive error notifications during serialization.
 org.w3c.dom.ls.DOMWriterFilter 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 setEncoding(java.lang.String encoding)
          DOM L3 EXPERIMENTAL: The character encoding in which the output will be written.
 void setErrorHandler(org.apache.xerces.dom3.DOMErrorHandler errorHandler)
          DOM L3 EXPERIMENTAL: The error handler that will receive error notifications during serialization.
 void setFilter(org.w3c.dom.ls.DOMWriterFilter 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 writeNode(java.io.OutputStream destination, org.w3c.dom.Node wnode)
          DOM L3 EXPERIMENTAL: Write out the specified node as described above in the description of DOMWriter.
 java.lang.String writeToString(org.w3c.dom.Node wnode)
          DOM L3 EXPERIMENTAL: Serialize the specified node as described above in the description of DOMWriter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMWriterImpl

public DOMWriterImpl()
Constructs a new DOMWriter. 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.apache.xerces.dom3.DOMConfiguration getConfig()
Description copied from interface: org.w3c.dom.ls.DOMWriter
The configuration used when a document is loaded.
In addition to the boolean parameters and parameters recognized in the Core module, the DOMConfiguration objects for DOMWriter adds, or modifies, the following boolean parameters:
"entity-resolver"
This parameter is equivalent to the "entity-resolver" parameter defined in DOMBuilder.config.
"xml-declaration"
true
[required] (default) If a Document Node or an Entity node is serialized, the XML declaration, or text declaration, should be included Document.version and/or an encoding is specified.
false
[required] Do not serialize the XML and text declarations.
"canonical-form"
true
[optional] This formatting writes the document according to the rules specified in [Canonical XML]. Setting this boolean parameter to true will set the boolean parameter "format-pretty-print" to false.
false
[ required] (default) Do not canonicalize the output.
"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. Setting this boolean parameter to true will set the boolean parameter "canonical-form" to false.
false
[required] (default) Don't pretty-print the result.
"normalize-characters"
This boolean parameter is equivalent to the one defined by DOMConfiguration in [DOM Level 3 Core]. Unlike in the Core, the default value for this boolean parameter is true. While DOM implementations are not required to implement the W3C Text Normalization defined in [CharModel], this boolean parameter must be activated by default if supported.
"unknown-characters"
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 ignore any possible denormalizations caused by these characters.
false
[optional] Report an fatal error if a character is encountered for which the processor can not determine the normalization properties.
Specified by:
getConfig in interface org.w3c.dom.ls.DOMWriter

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.apache.xerces.dom3.DOMConfiguration
Following copied from interface: org.apache.xerces.dom3.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. Should we allow implementations to raise exception if the type does not match? INVALID_ACCESS_ERR seems the closest exception code...
Throws:
org.w3c.dom.DOMException - NOT_SUPPORTED_ERR: Raised when the parameter name is recognized but the requested value cannot be set.
NOT_FOUND_ERR: Raised when the parameter name is not recognized.

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.apache.xerces.dom3.DOMConfiguration
Following copied from interface: org.apache.xerces.dom3.DOMConfiguration
Parameters:
name - The name of the parameter to check.
value - 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.apache.xerces.dom3.DOMConfiguration
Following copied from interface: org.apache.xerces.dom3.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. "by a DOM application" prevents a DOM implementation to return its default behavior (such as the default "schema-type") if any.
Throws:
org.w3c.dom.DOMException - NOT_FOUND_ERR: Raised when the parameter name is not recognized.

getEncoding

public java.lang.String getEncoding()
DOM L3 EXPERIMENTAL: The character encoding in which the output will be written.
The encoding to use when writing is determined as follows: If the encoding attribute has been set, that value will be used.If the encoding attribute is null or empty, but the item to be written includes an encoding declaration, that value will be used.If neither of the above provides an encoding name, a default encoding of "UTF-8" will be used.
The default value is null.
Specified by:
getEncoding in interface org.w3c.dom.ls.DOMWriter

setEncoding

public void setEncoding(java.lang.String encoding)
DOM L3 EXPERIMENTAL: The character encoding in which the output will be written.
The encoding to use when writing is determined as follows: If the encoding attribute has been set, that value will be used.If the encoding attribute is null or empty, but the item to be written includes an encoding declaration, that value will be used.If neither of the above provides an encoding name, a default encoding of "UTF-8" will be used.
The default value is null.
Specified by:
setEncoding in interface org.w3c.dom.ls.DOMWriter

getErrorHandler

public org.apache.xerces.dom3.DOMErrorHandler getErrorHandler()
The error handler that will receive error notifications during serialization. The node where the error occured is passed to this error handler, any modification to nodes from within an error callback should be avoided since this will result in undefined, implementation dependent behavior.

setErrorHandler

public void setErrorHandler(org.apache.xerces.dom3.DOMErrorHandler errorHandler)
DOM L3 EXPERIMENTAL: The error handler that will receive error notifications during serialization. The node where the error occured is passed to this error handler, any modification to nodes from within an error callback should be avoided since this will result in undefined, implementation dependent behavior.

writeNode

public boolean writeNode(java.io.OutputStream destination,
                         org.w3c.dom.Node wnode)
DOM L3 EXPERIMENTAL: Write out the specified node as described above in the description of DOMWriter. 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:
writeNode in interface org.w3c.dom.ls.DOMWriter
Parameters:
destination - The destination for the data to be written.
wnode - The Document or Entity node to be written. For other node types, something sensible should be written, but the exact serialized form is not specified.
Returns:
Returns true if node was successfully serialized and false in case a failure occured and the failure wasn't canceled by the error handler.
Throws:
none -  

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 DOMWriter. 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.DOMWriter
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.DOMWriter

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.DOMWriter

getFilter

public org.w3c.dom.ls.DOMWriterFilter 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.DOMWriter

setFilter

public void setFilter(org.w3c.dom.ls.DOMWriterFilter 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.DOMWriter


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