Top Description Fields Constructors Methods
org.apache.xml.serialize

public abstract Class BaseMarkupSerializer

extends Object
implements ContentHandler, DocumentHandler, LexicalHandler, DTDHandler, DeclHandler, DOMSerializer, Serializer
Class Inheritance
All Implemented Interfaces
org.apache.xml.serialize.Serializer, org.apache.xml.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
org.apache.xml.serialize.HTMLSerializer, org.apache.xml.serialize.TextSerializer, org.apache.xml.serialize.XMLSerializer
Imports
java.io.IOException, .OutputStream, .Writer, java.util.Hashtable, .Vector, org.apache.xerces.dom.DOMErrorImpl, .DOMLocatorImpl, .DOMMessageFormatter, org.apache.xerces.util.XMLChar, 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

This class was deprecated in Xerces 2.9.0. It is recommended that new applications use the DOM Level 3 LSSerializer or JAXP's Transformation API for XML (TrAX) for serializing XML. See the Xerces documentation for more information.

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
Version
$Revision: 923974 $ $Date: 2010-03-17 02:17:04 +0530 (Wed, 17 Mar 2010) $
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

Holds array of all element states that have been entered.

protected EncodingInfo
_encodingInfo

Deprecated as a consequence of EncodingInfo being deprecated.
protected OutputFormat
_format

The output format associated with this serializer.

protected boolean
_indenting

True if indenting printer.

private OutputStream
_output

The output stream.

protected Hashtable<K, V>
_prefixes

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

private boolean
_prepared

True if the serializer has been prepared.

private Vector<E>
_preRoot

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

protected Printer
_printer

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)

Deprecated as a consequence of OutputFormat being deprecated.
Protected constructor can only be used by derived class.

Method Summary

Modifier and TypeMethod and Description
public ContentHandler
asContentHandler()

Implements org.apache.xml.serialize.Serializer.asContentHandler.

Return a ContentHandler interface into this serializer.
public DocumentHandler
asDocumentHandler()

Implements org.apache.xml.serialize.Serializer.asDocumentHandler.

Deprecated as a consequence of DocumentHandler being deprecated.
Return a DocumentHandler interface into this serializer.
public DOMSerializer
asDOMSerializer()

Implements org.apache.xml.serialize.Serializer.asDOMSerializer.

Deprecated as a consequence of DOMSerializer being deprecated.
Return a DOMSerializer interface into this serializer.
public void
attributeDecl(String
The name of the associated element.
eName
,
String
The name of the attribute.
aName
,
String
A string representing the attribute type.
type
,
String
A string representing the attribute defaulting mode ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if none of these applies.
valueDefault
,
String
A string representing the attribute's default value, or null if there is none.
value
)

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

Report an attribute type declaration.
public void
characters(char[]
the characters from the XML document
chars
,
int
the start position in the array
start
,
int
the number of characters to read from the array
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[]
An array holding the characters in the comment.
chars
,
int
The starting position in the array.
start
,
int
The number of characters to use from the array.
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
()

Deprecated as a consequence of ElementState being deprecated.
Must be called by a method about to print any type of content.
public void
elementDecl(String
The element type name.
name
,
String
The content model as a normalized 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
The name of the entity that is ending.
name
)

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

Report the end of an entity.
public void
public void
endPrefixMapping(String
the prefix that was being mapped. This is the empty string when a default mapping scope ends.
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)

Deprecated as a consequence of ElementState being deprecated.
Enter a new element state for the specified element.
public void
externalEntityDecl(String
The name of the entity. If it is a parameter entity, the name will begin with '%'.
name
,
String
The entity's public identifier, or null if none was given.
publicId
,
String
The entity's system identifier.
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
()

Deprecated as a consequence of ElementState being deprecated.
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[]
the characters from the XML document
chars
,
int
the start position in the array
start
,
int
the number of characters to read from the array
length
)

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

Receive notification of ignorable whitespace in element content.
public void
internalEntityDecl(String
The name of the entity. If it is a parameter entity, the name will begin with '%'.
name
,
String
The replacement text of the entity.
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
()

Deprecated as a consequence of ElementState being deprecated.
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
The notation name.
name
,
String
The notation's public identifier, or null if none was given.
publicId
,
String
The notation's system identifier, or null if none was given.
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
processingInstruction(String
the processing instruction target
target
,
String
the processing instruction data, or null if none was supplied. The data does not include any whitespace separating it from the target
code
)

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

Receive notification of a processing instruction.
public void
public boolean
public void
serialize(Element
The element to serialize
elem
)

Implements org.apache.xml.serialize.DOMSerializer.serialize.

Serializes the DOM element using the previously specified writer and output format.
public void
serialize(DocumentFragment
The document fragment to serialize
frag
)

Implements org.apache.xml.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 org.apache.xml.serialize.DOMSerializer.serialize.

Serializes the DOM document using the previously specified writer and output format.
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
an object that can return the location of any SAX document event
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 org.apache.xml.serialize.Serializer.setOutputByteStream.

Specifies an output stream to which the document should be serialized.
public void
setOutputCharStream(Writer writer)

Implements org.apache.xml.serialize.Serializer.setOutputCharStream.

Specifies a writer to which the document should be serialized.
public void
setOutputFormat(OutputFormat
The output format to use
format
)

Implements org.apache.xml.serialize.Serializer.setOutputFormat.

Deprecated as a consequence of OutputFormat being deprecated.
Specifies an output format for this serializer.
public void
skippedEntity(String
the name of the skipped entity. If it is a parameter entity, the name will begin with '%', and if it is the external DTD subset, it will be the string "[dtd]"
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
The document type name.
name
,
String
The declared public identifier for the external DTD subset, or null if none was declared.
publicId
,
String
The declared system identifier for the external DTD subset, or null if none was declared. (Note that this is not resolved against the document base URI.)
systemId
)

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

Report the start of DTD declarations, if any.
public void
startEntity(String
The name of the entity. If it is a parameter entity, the name will begin with '%', and if it is the external DTD subset, it will be "[dtd]".
name
)

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

Report the beginning of some internal and external XML entities.
public void
public void
startPrefixMapping(String
the Namespace prefix being declared. An empty string is used for the default element namespace, which has no prefix.
prefix
,
String
the Namespace URI the prefix is mapped to
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
The unparsed entity's name.
name
,
String
The entity's public identifier, or null if none was given.
publicId
,
String
The entity's system identifier.
systemId
,
String
The name of the associated notation.
notationName
)

Implements org.xml.sax.DTDHandler.unparsedEntityDecl.

Receive notification of an unparsed entity declaration event.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait