org.apache.xml.serialize

Class DOMSerializerImpl

Implemented Interfaces:
DOMConfiguration, org.w3c.dom.ls.LSSerializer

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

EXPERIMENTAL: Implemenatation of DOM Level 3 org.w3c.ls.LSSerializer by delegating serialization calls to XMLSerializer. LSSerializer 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.16 2004/02/10 17:25:26 elena Exp $

Authors:
Elena Litani, IBM
Gopal Sharma, Sun Microsystems
Arun Yadav, Sun Microsystems

Field Summary

protected static short
CDATA
protected static short
COMMENTS
protected static short
DISCARDDEFAULT
protected static short
DOM_ELEMENT_CONTENT_WHITESPACE
protected static short
ENTITIES
protected static short
INFOSET
protected static short
NAMESPACES
protected static short
NSDECL
protected static short
SPLITCDATA
protected static short
WELLFORMED
protected static short
XMLDECL
protected short
features
REVISIT: Currently we handle 3 different configurations, would be nice just have one configuration that has different recognized parameters depending if it is used in Core/LS.

Constructor Summary

DOMSerializerImpl()
Constructs a new LSSerializer.

Method Summary

boolean
canSetParameter(String name, Object state)
DOM L3-EXPERIMENTAL: Check if parameter can be set
DOMConfiguration
getDomConfig()
org.w3c.dom.ls.LSSerializerFilter
getFilter()
When the application provides a filter, the serializer will call out to the filter before serializing each Node.
String
getNewLine()
DOM L3 EXPERIMENTAL: The end-of-line sequence of characters to be used in the XML being written out.
Object
getParameter(String name)
DOM L3-EXPERIMENTAL: Getter for boolean and object parameters
DOMStringList
getParameterNames()
DOM Level 3 Core CR - Experimental.
void
setFilter(org.w3c.dom.ls.LSSerializerFilter filter)
When the application provides a filter, the serializer will call out to the filter before serializing each Node.
void
setNewLine(String newLine)
DOM L3 EXPERIMENTAL: The end-of-line sequence of characters to be used in the XML being written out.
void
setParameter(String name, Object value)
DOM L3-EXPERIMENTAL: Setter for boolean and object parameters
boolean
write(org.w3c.dom.Node node, org.w3c.dom.ls.LSOutput destination)
Serialize the specified node as described above in the general description of the LSSerializer interface.
String
writeToString(org.w3c.dom.Node wnode)
DOM L3 EXPERIMENTAL: Serialize the specified node as described above in the description of LSSerializer.
boolean
writeToURI(org.w3c.dom.Node node, String URI)
Serialize the specified node as described above in the general description of the LSSerializer interface.

Field Details

CDATA

protected static final short CDATA

Field Value:
8


COMMENTS

protected static final short COMMENTS

Field Value:
32


DISCARDDEFAULT

protected static final short DISCARDDEFAULT

Field Value:
64


DOM_ELEMENT_CONTENT_WHITESPACE

protected static final short DOM_ELEMENT_CONTENT_WHITESPACE

Field Value:
1024


ENTITIES

protected static final short ENTITIES

Field Value:
4


INFOSET

protected static final short INFOSET

Field Value:
128


NAMESPACES

protected static final short NAMESPACES

Field Value:
1


NSDECL

protected static final short NSDECL

Field Value:
512


SPLITCDATA

protected static final short SPLITCDATA

Field Value:
16


WELLFORMED

protected static final short WELLFORMED

Field Value:
2


XMLDECL

protected static final short XMLDECL

Field Value:
256


features

protected short features
REVISIT: Currently we handle 3 different configurations, would be nice just have one configuration that has different recognized parameters depending if it is used in Core/LS.

Constructor Details

DOMSerializerImpl

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

Method Details

canSetParameter

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


getDomConfig

public DOMConfiguration getDomConfig()
Specified by:
getDomConfig in interface org.w3c.dom.ls.LSSerializer


getFilter

public org.w3c.dom.ls.LSSerializerFilter 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.LSSerializer


getNewLine

public 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.LSSerializer


getParameter

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


getParameterNames

public DOMStringList getParameterNames()
DOM Level 3 Core CR - Experimental. The list of the parameters supported by this DOMConfiguration object and for which at least one value can be set by the application. Note that this list can also contain parameter names defined outside this specification.


setFilter

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


setNewLine

public void setNewLine(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.LSSerializer


setParameter

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


write

public boolean write(org.w3c.dom.Node node,
                     org.w3c.dom.ls.LSOutput destination)
            throws org.w3c.dom.ls.LSException
Serialize the specified node as described above in the general description of the LSSerializer interface. The output is written to the supplied LSOutput.
When writing to a LSOutput, the encoding is found by looking at the encoding information that is reachable through the LSOutput and the item to be written (or its owner document) in this order:
  1. LSOutput.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 LSOutput, a "no-output-specified" error is raised.
Specified by:
write in interface org.w3c.dom.ls.LSSerializer

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.


writeToString

public String writeToString(org.w3c.dom.Node wnode)
            throws org.w3c.dom.DOMException,
                   org.w3c.dom.ls.LSException
DOM L3 EXPERIMENTAL: Serialize the specified node as described above in the description of LSSerializer. 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.LSSerializer

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.


writeToURI

public boolean writeToURI(org.w3c.dom.Node node,
                          String URI)
            throws org.w3c.dom.ls.LSException
Serialize the specified node as described above in the general description of the LSSerializer 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:
writeToURI in interface org.w3c.dom.ls.LSSerializer

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 B) 1999-2004 Apache XML Project. All Rights Reserved.