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

public abstract Class BaseMarkupSerializer

extends Object
implements ContentHandler, DocumentHandler, LexicalHandler, DTDHandler, DeclHandler, DOMSerializer, Serializer
Class Inheritance
All Implemented Interfaces
com.sun.org.apache.xml.internal.serialize.Serializer, com.sun.org.apache.xml.internal.serialize.DOMSerializer, org.xml.sax.ext.DeclHandler, org.xml.sax.DTDHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.DocumentHandler, org.xml.sax.ContentHandler
Known Direct Subclasses
com.sun.org.apache.xml.internal.serialize.HTMLSerializer, com.sun.org.apache.xml.internal.serialize.TextSerializer, com.sun.org.apache.xml.internal.serialize.XMLSerializer
Annotations
@Deprecated
Imports
com.sun.org.apache.xerces.internal.dom.DOMErrorImpl, .DOMLocatorImpl, .DOMMessageFormatter, com.sun.org.apache.xerces.internal.util.XMLChar, java.io.IOException, .OutputStream, .Writer, java.util.ArrayList, .HashMap, .List, .Map, org.w3c.dom.DOMError, .DOMErrorHandler, .Document, .DocumentFragment, .DocumentType, .Element, .Node, org.w3c.dom.ls.LSException, .LSSerializerFilter, org.w3c.dom.traversal.NodeFilter, org.xml.sax.ContentHandler, .DTDHandler, .DocumentHandler, .Locator, .SAXException, org.xml.sax.ext.DeclHandler, .LexicalHandler

Deprecated

As of JDK 9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation is replaced by that of Xalan. Main class com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl is replaced by com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl.

Base class for a serializer supporting both DOM and SAX pretty serializing of XML/HTML/XHTML documents. Derives classes perform the method-specific serializing, this class provides the common serializing mechanisms.

The serializer must be initialized with the proper writer and output format before it can be used by calling setOutputCharStream or setOutputByteStream for the writer and setOutputFormat for the output format.

The serializer can be reused any number of times, but cannot be used concurrently by two threads.

If an output stream is used, the encoding is taken from the output format (defaults to UTF-8). If a writer is used, make sure the writer uses the same encoding (if applies) as specified in the output format.

The serializer supports both DOM and SAX. DOM serializing is done by calling serialize(Document) and SAX serializing is done by firing SAX events and using the serializer as a document handler. This also applies to derived class.

If an I/O exception occurs while serializing, the serializer will not throw an exception directly, but only throw it at the end of serializing (either DOM or SAX's org.xml.sax.DocumentHandler#endDocument.

For elements that are not specified as whitespace preserving, the serializer will potentially break long text lines at space boundaries, indent lines, and serialize elements on separate lines. Line terminators will be regarded as spaces, and spaces at beginning of line will be stripped.

When indenting, the serializer is capable of detecting seemingly element content, and serializing these elements indented on separate lines. An element is serialized indented when it is the first or last child of an element, or immediate following or preceding another element.

Authors
Assaf Arkin, Rahul Srivastava, Elena Litani, IBM, Sunitha Reddy
See Also
Serializer, org.w3c.dom.ls.LSSerializer

Field Summary

Modifier and TypeField and Description
protected String
_docTypePublicId

The system identifier of the document type, if known.

protected String
_docTypeSystemId

The system identifier of the document type, if known.

private int
_elementStateCount

The index of the next state to place in the array, or one plus the index of the current state.

private ElementState[]
_elementStates

References Deprecated ElementState is deprecated or references (maybe indirectly) at least one deprecated element.
Holds array of all element states that have been entered.
protected EncodingInfo
_encodingInfo

References Deprecated EncodingInfo is deprecated or references (maybe indirectly) at least one deprecated element.
protected OutputFormat
_format

References Deprecated OutputFormat is deprecated or references (maybe indirectly) at least one deprecated element.
The output format associated with this serializer.
protected boolean
_indenting

True if indenting printer.

private OutputStream
_output

The output stream.

protected Map<String, String>
_prefixes

Association between namespace URIs (keys) and prefixes (values).

private boolean
_prepared

True if the serializer has been prepared.

private List<String>
_preRoot

List holding comments and PIs that come before the root element (even after it), see serializePreRoot.

protected Printer
_printer

References Deprecated Printer is deprecated or references (maybe indirectly) at least one deprecated element.
The printer used for printing text parts.
protected boolean
_started

If the document has been started (header serialized), this flag is set to true so it's not started twice.

private Writer
_writer

The underlying writer.

protected Node
fCurrentNode

Current node that is being processed

protected final DOMErrorImpl
protected DOMErrorHandler
protected LSSerializerFilter
protected short
protected final StringBuffer
fStrBuffer

Temporary buffer to store character data

Constructor Summary

AccessConstructor and Description
protected
BaseMarkupSerializer(OutputFormat format)
References Deprecated OutputFormat is deprecated or references (maybe indirectly) at least one deprecated element.

Protected constructor can only be used by derived class.

Method Summary

Modifier and TypeMethod and Description
public ContentHandler
public DocumentHandler
asDocumentHandler()

Implements com.sun.org.apache.xml.internal.serialize.Serializer.asDocumentHandler.

References Deprecated DocumentHandler is deprecated or references (maybe indirectly) at least one deprecated element.

Return a DocumentHandler interface into this serializer.

public DOMSerializer
asDOMSerializer()

Implements com.sun.org.apache.xml.internal.serialize.Serializer.asDOMSerializer.

References Deprecated DOMSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

Return a DOMSerializer interface into this serializer.

public void
attributeDecl(String eName, String aName, String type, String valueDefault, String value)

Implements org.xml.sax.ext.DeclHandler.attributeDecl.

Report an attribute type declaration.

public void
characters(char[] chars, int start, int length)

Implements org.xml.sax.ContentHandler.characters, org.xml.sax.DocumentHandler.characters.

Receive notification of character data.

protected void
characters(String
The text to print
text
)

Called to print the text contents in the prevailing element format.

protected void
checkUnboundNamespacePrefixedNode(Node
The node to check for unbound namespace prefices
node
)

DOM level 3: Check a node to determine if it contains unbound namespace prefixes.

protected void
pack-priv final void
clearDocumentState()

Clears document state.

public void
comment(char[] chars, int start, int length)

Implements org.xml.sax.ext.LexicalHandler.comment.

Report an XML comment anywhere in the document.

public void
protected ElementState

Returns:

The current element state
content
()
References Deprecated ElementState is deprecated or references (maybe indirectly) at least one deprecated element.

Must be called by a method about to print any type of content.

public void
elementDecl(String name, String model)

Implements org.xml.sax.ext.DeclHandler.elementDecl.

Report an element type declaration.

public void
endCDATA()

Implements org.xml.sax.ext.LexicalHandler.endCDATA.

Report the end of a CDATA section.

public void
endDocument()

Implements org.xml.sax.ContentHandler.endDocument, org.xml.sax.DocumentHandler.endDocument.

Called at the end of the document to wrap it up.

public void
endDTD()

Implements org.xml.sax.ext.LexicalHandler.endDTD.

Report the end of DTD declarations.

public void
endEntity(String name)

Implements org.xml.sax.ext.LexicalHandler.endEntity.

Report the end of an entity.

public void
public void
endPrefixMapping(String prefix)

Implements org.xml.sax.ContentHandler.endPrefixMapping.

End the scope of a prefix-URI mapping.

public void
protected ElementState

Returns:

Current element state, or null
enterElementState
(String namespaceURI, String localName, String rawName, boolean preserveSpace)
References Deprecated ElementState is deprecated or references (maybe indirectly) at least one deprecated element.

Enter a new element state for the specified element.

public void
externalEntityDecl(String name, String publicId, String systemId)

Implements org.xml.sax.ext.DeclHandler.externalEntityDecl.

Report a parsed external entity declaration.

protected void
fatalError(String message)

protected ElementState

Returns:

Current element state
getElementState
()
References Deprecated ElementState is deprecated or references (maybe indirectly) at least one deprecated element.

Return the state of the current element.

protected abstract String

Returns:

Character entity name, or null
getEntityRef
(int
Character value
ch
)

Returns the suitable entity reference for this character value, or null if no such entity exists.

protected String

Returns:

The namespace prefix if known, or null
getPrefix
(String
The namespace URI
namespaceURI
)

Returns the namespace prefix for the specified URI.

public void
ignorableWhitespace(char[] chars, int start, int length)

Implements org.xml.sax.ContentHandler.ignorableWhitespace, org.xml.sax.DocumentHandler.ignorableWhitespace.

Receive notification of ignorable whitespace in element content.

public void
internalEntityDecl(String name, String value)

Implements org.xml.sax.ext.DeclHandler.internalEntityDecl.

Report an internal entity declaration.

protected boolean

Returns:

True if in the state of the document
isDocumentState
()

Returns true if in the state of the document.

protected ElementState

Returns:

Previous element state
leaveElementState
()
References Deprecated ElementState is deprecated or references (maybe indirectly) at least one deprecated element.

Leave the current element state and return to the state of the parent element.

protected DOMError

Returns:

a DOMError
modifyDOMError
(String message, short severity, String type, Node node)

The method modifies global DOM error object

public void
notationDecl(String name, String publicId, String systemId)

Implements org.xml.sax.DTDHandler.notationDecl.

Receive notification of a notation declaration event.

protected void
protected void
protected void
printDoctypeURL(String
The document type url to print
url
)

Print a document type public or system identifier URL.

protected void
printEscaped(int ch)

protected void
printEscaped(String
The string to escape
source
)

Escapes a string so it may be printed as text content or attribute value.

pack-priv final void
printHex(int ch)

Escapes chars

protected void
printText(char[]
The text to print
chars
,
int
The start offset
start
,
int
The number of characters
length
,
boolean
Space preserving flag
preserveSpace
,
boolean
Print unescaped
unescaped
)

Called to print additional text with whitespace handling.

protected void
printText(String text, boolean preserveSpace, boolean unescaped)

public final void
public void
public boolean
public void
serialize(Element
The element to serialize
elem
)

Implements com.sun.org.apache.xml.internal.serialize.DOMSerializer.serialize.

Serializes the DOM element using the previously specified writer and output format.

public void
serialize(Node
Node to serialize
node
)

Serializes a node using the previously specified writer and output format.

public void
serialize(DocumentFragment
The document fragment to serialize
frag
)

Implements com.sun.org.apache.xml.internal.serialize.DOMSerializer.serialize.

Serializes the DOM document fragmnt using the previously specified writer and output format.

public void
serialize(Document
The document to serialize
doc
)

Implements com.sun.org.apache.xml.internal.serialize.DOMSerializer.serialize.

Serializes the DOM document using the previously specified writer and output format.

protected void
protected void
protected abstract void
serializeElement(Element
The element to serialize
elem
)

Called to serializee the DOM element.

protected void
serializeNode(Node
The node to serialize
node
)

Serialize the DOM node.

protected void
serializePreRoot()

Comments and PIs cannot be serialized before the root element, because the root element serializes the document type, which generally comes first.

public void
setDocumentLocator(Locator locator)

Implements org.xml.sax.ContentHandler.setDocumentLocator, org.xml.sax.DocumentHandler.setDocumentLocator.

Receive an object for locating the origin of SAX document events.

public void
setOutputByteStream(OutputStream output)

Implements com.sun.org.apache.xml.internal.serialize.Serializer.setOutputByteStream.

Specifies an output stream to which the document should be serialized.

public void
setOutputCharStream(Writer writer)

Implements com.sun.org.apache.xml.internal.serialize.Serializer.setOutputCharStream.

Specifies a writer to which the document should be serialized.

public void
setOutputFormat(OutputFormat format)

Implements com.sun.org.apache.xml.internal.serialize.Serializer.setOutputFormat.

References Deprecated OutputFormat is deprecated or references (maybe indirectly) at least one deprecated element.

Specifies an output format for this serializer.

public void
skippedEntity(String name)

Implements org.xml.sax.ContentHandler.skippedEntity.

Receive notification of a skipped entity.

public void
startCDATA()

Implements org.xml.sax.ext.LexicalHandler.startCDATA.

Report the start of a CDATA section.

public void
startDocument()

Implements org.xml.sax.ContentHandler.startDocument, org.xml.sax.DocumentHandler.startDocument.

Receive notification of the beginning of a document.

public final void
startDTD(String name, String publicId, String systemId)

Implements org.xml.sax.ext.LexicalHandler.startDTD.

Report the start of DTD declarations, if any.

public void
startEntity(String name)

Implements org.xml.sax.ext.LexicalHandler.startEntity.

Report the beginning of some internal and external XML entities.

public void
public void
startPrefixMapping(String prefix, String uri)

Implements org.xml.sax.ContentHandler.startPrefixMapping.

Begin the scope of a prefix-URI Namespace mapping.

public void
protected void
surrogates(int high, int low, boolean inContent)

public void
unparsedEntityDecl(String name, String publicId, String systemId, String notationName)

Implements org.xml.sax.DTDHandler.unparsedEntityDecl.

Receive notification of an unparsed entity declaration event.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait