Top Description Fields Constructors Methods
com.sun.org.apache.xml.internal.serialize

public Class DOMSerializerImpl

extends Object
implements LSSerializer, DOMConfiguration
Class Inheritance
All Implemented Interfaces
org.w3c.dom.DOMConfiguration, org.w3c.dom.ls.LSSerializer
Annotations
@Deprecated
Imports
com.sun.org.apache.xerces.internal.dom.AbortException, .CoreDocumentImpl, .DOMErrorImpl, .DOMLocatorImpl, .DOMMessageFormatter, .DOMNormalizer, .DOMStringListImpl, com.sun.org.apache.xerces.internal.impl.Constants, .XMLEntityManager, com.sun.org.apache.xerces.internal.util.DOMUtil, .NamespaceSupport, .SymbolTable, .XML11Char, .XMLChar, java.io.IOException, .OutputStream, .StringWriter, .UnsupportedEncodingException, .Writer, java.lang.reflect.Method, java.util.ArrayList, .List, org.w3c.dom.Attr, .Comment, .DOMConfiguration, .DOMError, .DOMErrorHandler, .DOMException, .DOMStringList, .Document, .DocumentFragment, .Element, .NamedNodeMap, .Node, .ProcessingInstruction, org.w3c.dom.ls.LSException, .LSOutput, .LSSerializer, .LSSerializerFilter

Deprecated

As of JDK 9, Xerces 2.9.0, replaced by com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl

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.
Authors
Elena Litani, IBM, Gopal Sharma, Sun Microsystems, Arun Yadav, Sun Microsystems, Sunitha Reddy, Sun Microsystems

Field Summary

Modifier and TypeField and Description
protected static final short
protected static final short
protected static final short
protected static final short
protected static final short
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.

private final DOMErrorImpl
private DOMErrorHandler
private final DOMLocatorImpl
private DOMStringList
protected static final short
protected static final short
protected static final short
protected static final short
private XMLSerializer
serializer

References Deprecated XMLSerializer is deprecated or references (maybe indirectly) at least one deprecated element.
protected static final short
protected static final short
private XML11Serializer
xml11Serializer

References Deprecated XML11Serializer is deprecated or references (maybe indirectly) at least one deprecated element.
protected static final short

Constructor Summary

AccessConstructor and Description
public
DOMSerializerImpl()

Constructs a new LSSerializer.

Method Summary

Modifier and TypeMethod and Description
private String
private String
private String
public boolean
canSetParameter(String
The name of the parameter to check.
name
,
Object
An object. if null, the returned value is true.
state
)

Implements org.w3c.dom.DOMConfiguration.canSetParameter.

DOM L3-EXPERIMENTAL: Check if parameter can be set

private void
copySettings(XMLSerializer src, XMLSerializer dest)
References Deprecated XMLSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

public DOMConfiguration
getDomConfig()

Implements org.w3c.dom.ls.LSSerializer.getDomConfig.

The DOMConfiguration object used by the LSSerializer when serializing a DOM node.

public LSSerializerFilter
getFilter()

Implements org.w3c.dom.ls.LSSerializer.getFilter.

When the application provides a filter, the serializer will call out to the filter before serializing each Node.

public String
getNewLine()

Implements org.w3c.dom.ls.LSSerializer.getNewLine.

DOM L3 EXPERIMENTAL: The end-of-line sequence of characters to be used in the XML being written out.

public Object
getParameter(String
The name of the parameter.
name
)

Implements org.w3c.dom.DOMConfiguration.getParameter.

DOM L3-EXPERIMENTAL: Getter for boolean and object parameters

public DOMStringList
getParameterNames()

Implements org.w3c.dom.DOMConfiguration.getParameterNames.

DOM Level 3 Core CR - Experimental.

private void
initSerializer(XMLSerializer ser)
References Deprecated XMLSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

private void
prepareForSerialization(XMLSerializer ser, Node node)
References Deprecated XMLSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

public void
setFilter(LSSerializerFilter filter)

Implements org.w3c.dom.ls.LSSerializer.setFilter.

When the application provides a filter, the serializer will call out to the filter before serializing each Node.

public void
setNewLine(String newLine)

Implements org.w3c.dom.ls.LSSerializer.setNewLine.

DOM L3 EXPERIMENTAL: The end-of-line sequence of characters to be used in the XML being written out.

public void
setParameter(String
The name of the parameter to set.
name
,
Object
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.
value
)

Implements org.w3c.dom.DOMConfiguration.setParameter.

DOM L3-EXPERIMENTAL: Setter for boolean and object parameters

private void
verify(Node node, boolean verifyNames, boolean xml11Version)

public boolean

Returns:

Returns true if node was successfully serialized and false in case the node couldn't be serialized.
write
(Node
The node to serialize.
node
,
LSOutput
The destination for the serialized DOM.
destination
)

Implements org.w3c.dom.ls.LSSerializer.write.

Serialize the specified node as described above in the general description of the LSSerializer interface.

public String

Returns:

Returns the serialized data
writeToString
(Node
The node to be written.
wnode
)

Implements org.w3c.dom.ls.LSSerializer.writeToString.

DOM L3 EXPERIMENTAL: Serialize the specified node as described above in the description of LSSerializer.

public boolean

Returns:

Returns true if node was successfully serialized and false in case the node couldn't be serialized.
writeToURI
(Node
The node to serialize.
node
,
String
The URI to write to.
URI
)

Implements org.w3c.dom.ls.LSSerializer.writeToURI.

Serialize the specified node as described above in the general description of the LSSerializer interface.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CDATAback to summary
protected static final short CDATA
COMMENTSback to summary
protected static final short COMMENTS
DISCARDDEFAULTback to summary
protected static final short DISCARDDEFAULT
DOM_ELEMENT_CONTENT_WHITESPACEback to summary
protected static final short DOM_ELEMENT_CONTENT_WHITESPACE
ENTITIESback to summary
protected static final short ENTITIES
featuresback to summary
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.

fErrorback to summary
private final DOMErrorImpl fError
fErrorHandlerback to summary
private DOMErrorHandler fErrorHandler
fLocatorback to summary
private final DOMLocatorImpl fLocator
fRecognizedParametersback to summary
private DOMStringList fRecognizedParameters
INFOSETback to summary
protected static final short INFOSET
NAMESPACESback to summary
protected static final short NAMESPACES
NSDECLback to summary
protected static final short NSDECL
PRETTY_PRINTback to summary
protected static final short PRETTY_PRINT
serializerback to summary
private XMLSerializer serializer

References Deprecated

XMLSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

SPLITCDATAback to summary
protected static final short SPLITCDATA
WELLFORMEDback to summary
protected static final short WELLFORMED
xml11Serializerback to summary
private XML11Serializer xml11Serializer

References Deprecated

XML11Serializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

XMLDECLback to summary
protected static final short XMLDECL

Constructor Detail

DOMSerializerImplback to summary
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 Detail

_getInputEncodingback to summary
private String _getInputEncoding(Node node)
_getXmlEncodingback to summary
private String _getXmlEncoding(Node node)
_getXmlVersionback to summary
private String _getXmlVersion(Node node)
canSetParameterback to summary
public boolean canSetParameter(String name, Object state)

Implements org.w3c.dom.DOMConfiguration.canSetParameter.

DOM L3-EXPERIMENTAL: Check if parameter can be set

Parameters
name:String

Doc from org.w3c.dom.DOMConfiguration.canSetParameter.

The name of the parameter to check.

state:Object

Doc from org.w3c.dom.DOMConfiguration.canSetParameter.

An object. if null, the returned value is true.

Returns:boolean

Doc from org.w3c.dom.DOMConfiguration.canSetParameter.

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.

copySettingsback to summary
private void copySettings(XMLSerializer src, XMLSerializer dest)

References Deprecated

XMLSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

getDomConfigback to summary
public DOMConfiguration getDomConfig()

Implements org.w3c.dom.ls.LSSerializer.getDomConfig.

Doc from org.w3c.dom.ls.LSSerializer.getDomConfig.

The DOMConfiguration object used by the LSSerializer when serializing a DOM node.
In addition to the parameters recognized by the DOMConfiguration interface defined in [DOM Level 3 Core] , the DOMConfiguration objects for LSSerializer adds, or modifies, the following parameters:

"canonical-form"
true
[optional] Writes the document according to the rules specified in [Canonical XML]. In addition to the behavior described in "canonical-form" [DOM Level 3 Core] , setting this parameter to true will set the parameters "format-pretty-print", "discard-default-content", and "xml-declaration ", to false. Setting one of those parameters to true will set this parameter to false. Serializing an XML 1.1 document when "canonical-form" is true will generate a fatal error.
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.
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.
false
[optional] Report a 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 appendix E 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 the output encoding (see LSSerializer.write for details on how to find the output encoding) are 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).
getFilterback to summary
public LSSerializerFilter getFilter()

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

getNewLineback to summary
public String getNewLine()

Implements org.w3c.dom.ls.LSSerializer.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.
getParameterback to summary
public Object getParameter(String name) throws DOMException

Implements org.w3c.dom.DOMConfiguration.getParameter.

DOM L3-EXPERIMENTAL: Getter for boolean and object parameters

Parameters
name:String

Doc from org.w3c.dom.DOMConfiguration.getParameter.

The name of the parameter.

Returns:Object

Doc from org.w3c.dom.DOMConfiguration.getParameter.

The current object associated with the specified parameter or null if no object has been associated or if the parameter is not supported.

Exceptions
DOMException:

Doc from org.w3c.dom.DOMConfiguration.getParameter.

NOT_FOUND_ERR: Raised when the parameter name is not recognized.

getParameterNamesback to summary
public DOMStringList getParameterNames()

Implements org.w3c.dom.DOMConfiguration.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.

initSerializerback to summary
private void initSerializer(XMLSerializer ser)

References Deprecated

XMLSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

prepareForSerializationback to summary
private void prepareForSerialization(XMLSerializer ser, Node node)

References Deprecated

XMLSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

setFilterback to summary
public void setFilter(LSSerializerFilter filter)

Implements org.w3c.dom.ls.LSSerializer.setFilter.

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.

setNewLineback to summary
public void setNewLine(String newLine)

Implements org.w3c.dom.ls.LSSerializer.setNewLine.

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.
setParameterback to summary
public void setParameter(String name, Object value) throws DOMException

Implements org.w3c.dom.DOMConfiguration.setParameter.

DOM L3-EXPERIMENTAL: Setter for boolean and object parameters

Parameters
name:String

Doc from org.w3c.dom.DOMConfiguration.setParameter.

The name of the parameter to set.

value:Object

Doc from org.w3c.dom.DOMConfiguration.setParameter.

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.

Exceptions
DOMException:

Doc from org.w3c.dom.DOMConfiguration.setParameter.

NOT_FOUND_ERR: Raised when the parameter name is not recognized.
NOT_SUPPORTED_ERR: Raised when the parameter name is recognized but the requested value cannot be set.
TYPE_MISMATCH_ERR: Raised if the value type for this parameter name is incompatible with the expected value type.

verifyback to summary
private void verify(Node node, boolean verifyNames, boolean xml11Version)
writeback to summary
public boolean write(Node node, LSOutput destination) throws LSException

Implements org.w3c.dom.ls.LSSerializer.write.

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.
Parameters
node:Node

The node to serialize.

destination:LSOutput

The destination for the serialized DOM.

Returns:boolean

Returns true if node was successfully serialized and false in case the node couldn't be serialized.

Exceptions
LSException:

Doc from org.w3c.dom.ls.LSSerializer.write.

SERIALIZE_ERR: Raised if the LSSerializer was unable to serialize the node. DOM applications should attach a DOMErrorHandler using the parameter "error-handler" if they wish to get details on the error.

writeToStringback to summary
public String writeToString(Node wnode) throws DOMException, LSException

Implements org.w3c.dom.ls.LSSerializer.writeToString.

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.

Parameters
wnode:Node

The node to be written.

Returns:String

Returns the serialized data

Exceptions
DOMException:
DOMSTRING_SIZE_ERR: The resulting string is too long to fit in a DOMString.
LSException:
SERIALIZE_ERR: Unable to serialize the node. DOM applications should attach a DOMErrorHandler using the parameter "error-handler" to get details on error.
writeToURIback to summary
public boolean writeToURI(Node node, String URI) throws LSException

Implements org.w3c.dom.ls.LSSerializer.writeToURI.

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.inputEncoding,
  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.
Parameters
node:Node

The node to serialize.

URI:String

The URI to write to.

Returns:boolean

Returns true if node was successfully serialized and false in case the node couldn't be serialized.

Exceptions
LSException:

Doc from org.w3c.dom.ls.LSSerializer.writeToURI.

SERIALIZE_ERR: Raised if the LSSerializer was unable to serialize the node. DOM applications should attach a DOMErrorHandler using the parameter "error-handler" if they wish to get details on the error.