org.apache.xml.serialize

Class TextSerializer

Implemented Interfaces:
ContentHandler, DeclHandler, DocumentHandler, DTDHandler, LexicalHandler, DOMSerializer, Serializer

public class TextSerializer
extends BaseMarkupSerializer

Implements a text serializer supporting both DOM and SAX serializing. For usage instructions see Serializer.

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 TextSerializer and SAX serializing is done by firing SAX events and using the serializer as a document handler.

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.

Version:
$Revision: 476047 $ $Date: 2006-11-16 23:27:45 -0500 (Thu, 16 Nov 2006) $
Author:
Assaf Arkin
See Also:
Serializer

Field Summary

Fields inherited from class org.apache.xml.serialize.BaseMarkupSerializer

_docTypePublicId, _docTypeSystemId, _encodingInfo, _format, _indenting, _prefixes, _printer, _started, fCurrentNode, fDOMError, fDOMErrorHandler, fDOMFilter, fStrBuffer, features

Constructor Summary

TextSerializer()
Constructs a new serializer.

Method Summary

protected void
characters(String text, boolean unescaped)
void
characters(char[] chars, int start, int length)
void
comment(String text)
void
comment(char[] chars, int start, int length)
protected ElementState
content()
void
endElement(String tagName)
void
endElement(String namespaceURI, String localName, String rawName)
void
endElementIO(String tagName)
protected String
getEntityRef(int ch)
void
processingInstructionIO(String target, String code)
protected void
serializeElement(Element elem)
Called to serialize a DOM element.
protected void
serializeNode(Node node)
Serialize the DOM node.
void
setOutputFormat(OutputFormat format)
protected void
startDocument(String rootTagName)
Called to serialize the document's DOCTYPE by the root element.
void
startElement(String tagName, AttributeList attrs)
void
startElement(String namespaceURI, String localName, String rawName, Attributes attrs)

Methods inherited from class org.apache.xml.serialize.BaseMarkupSerializer

asContentHandler, asDOMSerializer, asDocumentHandler, attributeDecl, characters, characters, checkUnboundNamespacePrefixedNode, comment, comment, content, elementDecl, endCDATA, endDTD, endDocument, endEntity, endNonEscaping, endPrefixMapping, endPreserving, enterElementState, externalEntityDecl, fatalError, getElementState, getEntityRef, getPrefix, ignorableWhitespace, internalEntityDecl, isDocumentState, leaveElementState, modifyDOMError, notationDecl, prepare, printCDATAText, printDoctypeURL, printEscaped, printEscaped, printText, printText, processingInstruction, processingInstructionIO, reset, serialize, serialize, serialize, serializeElement, serializeNode, serializePreRoot, setDocumentLocator, setOutputByteStream, setOutputCharStream, setOutputFormat, skippedEntity, startCDATA, startDTD, startDocument, startEntity, startNonEscaping, startPrefixMapping, startPreserving, surrogates, unparsedEntityDecl

Constructor Details

TextSerializer

public TextSerializer()
Constructs a new serializer. The serializer cannot be used without calling TextSerializer or TextSerializer first.

Method Details

characters

protected void characters(String text,
                          boolean unescaped)
            throws IOException

characters

public void characters(char[] chars,
                       int start,
                       int length)
            throws SAXException
Overrides:
characters in interface BaseMarkupSerializer

comment

public void comment(String text)
Overrides:
comment in interface BaseMarkupSerializer

comment

public void comment(char[] chars,
                    int start,
                    int length)
Overrides:
comment in interface BaseMarkupSerializer

content

protected ElementState content()
Overrides:
content in interface BaseMarkupSerializer

endElement

public void endElement(String tagName)
            throws SAXException

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String rawName)
            throws SAXException

endElementIO

public void endElementIO(String tagName)
            throws IOException

getEntityRef

protected String getEntityRef(int ch)
Overrides:
getEntityRef in interface BaseMarkupSerializer

processingInstructionIO

public void processingInstructionIO(String target,
                                    String code)
            throws IOException
Overrides:
processingInstructionIO in interface BaseMarkupSerializer

serializeElement

protected void serializeElement(Element elem)
            throws IOException
Called to serialize a DOM element. Equivalent to calling startElement, endElement and serializing everything inbetween, but better optimized.
Overrides:
serializeElement in interface BaseMarkupSerializer

serializeNode

protected void serializeNode(Node node)
            throws IOException
Serialize the DOM node. This method is unique to the Text serializer.
Overrides:
serializeNode in interface BaseMarkupSerializer
Parameters:
node - The node to serialize

setOutputFormat

public void setOutputFormat(OutputFormat format)
Specified by:
setOutputFormat in interface Serializer
Overrides:
setOutputFormat in interface BaseMarkupSerializer

startDocument

protected void startDocument(String rootTagName)
            throws IOException
Called to serialize the document's DOCTYPE by the root element.

This method will check if it has not been called before (BaseMarkupSerializer._started), will serialize the document type declaration, and will serialize all pre-root comments and PIs that were accumulated in the document (see TextSerializer). Pre-root will be serialized even if this is not the first root element of the document.


startElement

public void startElement(String tagName,
                         AttributeList attrs)
            throws SAXException

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String rawName,
                         Attributes attrs)
            throws SAXException

Copyright © 1999-2007 The Apache Software Foundation. All Rights Reserved.