org.apache.xml.serializer

Class ToXMLSAXHandler

Implemented Interfaces:
ContentHandler, DeclHandler, DOM2DTM.CharacterNodeHandler, DOMSerializer, ErrorHandler, ExtendedContentHandler, ExtendedLexicalHandler, LexicalHandler, SerializationHandler, Serializer, SerializerConstants, XSLOutputAttributes

public class ToXMLSAXHandler
extends ToSAXHandler

This class receives notification of SAX-like events, and with gathered information over these calls it will invoke the equivalent SAX methods on a handler, the ultimate output is known to be XML.

Authors:
minchau
Santiago Pericas-Geertsen
G. Todd Miller

Fields inherited from interface org.apache.xml.serializer.ExtendedContentHandler

HTML_ATTREMPTY, HTML_ATTRURL, NO_BAD_CHARS

Fields inherited from interface org.apache.xml.serializer.SerializerConstants

BEGCDATA, CDATA_CONTINUE, CDATA_DELIMITER_CLOSE, CDATA_DELIMITER_OPEN, CNTCDATA, DEFAULT_SAX_SERIALIZER, EMPTYSTRING, ENDCDATA, ENTITY_AMP, ENTITY_CRLF, ENTITY_GT, ENTITY_LT, ENTITY_QUOT, XMLNS_PREFIX, XMLNS_URI, XML_PREFIX

Constructor Summary

ToXMLSAXHandler()
ToXMLSAXHandler(ContentHandler handler, String encoding)
ToXMLSAXHandler(ContentHandler handler, LexicalHandler lex, String encoding)

Method Summary

void
addAttribute(String uri, String localName, String rawName, String type, String value)
Adds the given attribute to the set of attributes, and also makes sure that the needed prefix/uri mapping is declared, but only if there is a currently open element.
void
attributeDecl(String arg0, String arg1, String arg2, String arg3, String arg4)
void
characters(String chars)
void
characters(char[] ch, int off, int len)
void
closeCDATA()
Closes ane open cdata tag, and unlike the this.endCDATA() method (from the LexicalHandler) interface, this "internal" method will send the endCDATA() call to the wrapped handler.
void
comment(char[] arg0, int arg1, int arg2)
void
elementDecl(String arg0, String arg1)
void
endCDATA()
void
endDTD()
void
endDocument()
Receives notification of the end of the document.
void
endElement(String elemName)
void
endElement(String namespaceURI, String localName, String qName)
void
endPrefixMapping(String prefix)
void
externalEntityDecl(String arg0, String arg1, String arg2)
Properties
getOutputFormat()
OutputStream
getOutputStream()
Writer
getWriter()
void
ignorableWhitespace(char[] arg0, int arg1, int arg2)
void
indent(int n)
Do nothing for SAX.
void
internalEntityDecl(String arg0, String arg1)
void
namespaceAfterStartElement(String prefix, String uri)
Send a namespace declaration in the output document.
void
processingInstruction(String target, String data)
boolean
reset()
Try's to reset the super class and reset this class for re-use, so that you don't need to create a new serializer (mostly for performance reasons).
void
serialize(Node node)
void
setDocumentLocator(Locator arg0)
boolean
setEscaping(boolean escape)
void
setOutputFormat(Properties format)
void
setOutputStream(OutputStream output)
void
setWriter(Writer writer)
void
skippedEntity(String arg0)
void
startCDATA()
Report the start of a CDATA section.
void
startElement(String elementName)
An element starts, but attributes are not fully known yet.
void
startElement(String elementNamespaceURI, String elementLocalName, String elementName)
Start an element in the output document.
void
startElement(String namespaceURI, String localName, String name, Attributes atts)
void
startEntity(String arg0)
void
startPrefixMapping(String prefix, String uri)
boolean
startPrefixMapping(String prefix, String uri, boolean shouldFlush)
Remember the prefix/uri mapping at the current nested element depth.

Methods inherited from class org.apache.xml.serializer.ToSAXHandler

addUniqueAttribute, characters, characters, comment, error, fatalError, flushPending, processingInstruction, reset, setCdataSectionElements, setContentHandler, setLexHandler, setShouldOutputNSAttr, setTransformState, startDTD, startElement, startElement, startElement, warning

Methods inherited from class org.apache.xml.serializer.SerializerBase

addAttribute, addAttribute, addAttributeAlways, addAttributes, asContentHandler, asDOMSerializer, characters, close, comment, endEntity, entityReference, error, fatalError, fireEndEntity, getDoctypePublic, getDoctypeSystem, getEncoding, getIndent, getIndentAmount, getMediaType, getNamespaceMappings, getNamespaceURI, getNamespaceURIFromPrefix, getOmitXMLDeclaration, getPrefix, getStandalone, getTransformer, getVersion, namespaceAfterStartElement, reset, setDoctype, setDoctypePublic, setDoctypeSystem, setDocumentLocator, setEncoding, setIndent, setIndentAmount, setMediaType, setNamespaceMappings, setOmitXMLDeclaration, setSourceLocator, setStandalone, setTransformer, setVersion, startDocument, warning

Constructor Details

ToXMLSAXHandler

public ToXMLSAXHandler()


ToXMLSAXHandler

public ToXMLSAXHandler(ContentHandler handler,
                       String encoding)


ToXMLSAXHandler

public ToXMLSAXHandler(ContentHandler handler,
                       LexicalHandler lex,
                       String encoding)

Method Details

addAttribute

public void addAttribute(String uri,
                         String localName,
                         String rawName,
                         String type,
                         String value)
            throws SAXException
Adds the given attribute to the set of attributes, and also makes sure that the needed prefix/uri mapping is declared, but only if there is a currently open element.
Specified by:
addAttribute in interface ExtendedContentHandler
Overrides:
addAttribute in interface SerializerBase

Parameters:
uri - the URI of the attribute
localName - the local name of the attribute
rawName - the qualified name of the attribute
type - the type of the attribute (probably CDATA)
value - the value of the attribute

See Also:
ExtendedContentHandler.addAttribute(String,String,String,String,String)


attributeDecl

public void attributeDecl(String arg0,
                          String arg1,
                          String arg2,
                          String arg3,
                          String arg4)
            throws SAXException
Specified by:
attributeDecl in interface DeclHandler

See Also:
DeclHandler.attributeDecl(String,String,String,String,String)


characters

public void characters(String chars)
            throws SAXException
Specified by:
characters in interface ExtendedContentHandler
Overrides:
characters in interface ToSAXHandler

See Also:
ExtendedContentHandler.characters(String)


characters

public void characters(char[] ch,
                       int off,
                       int len)
            throws SAXException


closeCDATA

public void closeCDATA()
            throws SAXException
Closes ane open cdata tag, and unlike the this.endCDATA() method (from the LexicalHandler) interface, this "internal" method will send the endCDATA() call to the wrapped handler.


comment

public void comment(char[] arg0,
                    int arg1,
                    int arg2)
            throws SAXException

See Also:
org.xml.sax.ext.LexicalHandler.comment(char[], int, int)


elementDecl

public void elementDecl(String arg0,
                        String arg1)
            throws SAXException
Specified by:
elementDecl in interface DeclHandler

See Also:
DeclHandler.elementDecl(String,String)


endCDATA

public void endCDATA()
            throws SAXException
Specified by:
endCDATA in interface LexicalHandler

See Also:
LexicalHandler.endCDATA()


endDTD

public void endDTD()
            throws SAXException
Specified by:
endDTD in interface LexicalHandler

See Also:
LexicalHandler.endDTD()


endDocument

public void endDocument()
            throws SAXException
Receives notification of the end of the document.
Specified by:
endDocument in interface ContentHandler

See Also:
ContentHandler.endDocument()


endElement

public void endElement(String elemName)
            throws SAXException
Specified by:
endElement in interface ExtendedContentHandler

See Also:
ExtendedContentHandler.endElement(String)


endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
            throws SAXException
Specified by:
endElement in interface ContentHandler

See Also:
ContentHandler.endElement(String,String,String)


endPrefixMapping

public void endPrefixMapping(String prefix)
            throws SAXException
Specified by:
endPrefixMapping in interface ContentHandler

See Also:
ContentHandler.endPrefixMapping(String)


externalEntityDecl

public void externalEntityDecl(String arg0,
                               String arg1,
                               String arg2)
            throws SAXException
Specified by:
externalEntityDecl in interface DeclHandler

See Also:
DeclHandler.externalEntityDecl(String,String,String)


getOutputFormat

public Properties getOutputFormat()
Specified by:
getOutputFormat in interface Serializer

See Also:
Serializer.getOutputFormat()


getOutputStream

public OutputStream getOutputStream()
Specified by:
getOutputStream in interface Serializer

See Also:
Serializer.getOutputStream()


getWriter

public Writer getWriter()
Specified by:
getWriter in interface Serializer

See Also:
Serializer.getWriter()


ignorableWhitespace

public void ignorableWhitespace(char[] arg0,
                                int arg1,
                                int arg2)
            throws SAXException

See Also:
org.xml.sax.ContentHandler.ignorableWhitespace(char[], int, int)


indent

public void indent(int n)
            throws SAXException
Do nothing for SAX.


internalEntityDecl

public void internalEntityDecl(String arg0,
                               String arg1)
            throws SAXException
Specified by:
internalEntityDecl in interface DeclHandler

See Also:
DeclHandler.internalEntityDecl(String,String)


namespaceAfterStartElement

public void namespaceAfterStartElement(String prefix,
                                       String uri)
            throws SAXException
Send a namespace declaration in the output document. The namespace declaration will not be include if the namespace is already in scope with the same prefix.
Specified by:
namespaceAfterStartElement in interface ExtendedContentHandler
Overrides:
namespaceAfterStartElement in interface SerializerBase


processingInstruction

public void processingInstruction(String target,
                                  String data)
            throws SAXException
Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in interface ToSAXHandler

See Also:
Send a processing instruction to the output document


reset

public boolean reset()
Try's to reset the super class and reset this class for re-use, so that you don't need to create a new serializer (mostly for performance reasons).
Specified by:
reset in interface Serializer
Overrides:
reset in interface ToSAXHandler

Returns:
true if the class was successfuly reset.

See Also:
Serializer.reset()


serialize

public void serialize(Node node)
            throws IOException
Specified by:
serialize in interface SerializationHandler
serialize in interface DOMSerializer

See Also:
DOMSerializer.serialize(Node)


setDocumentLocator

public void setDocumentLocator(Locator arg0)
Specified by:
setDocumentLocator in interface ContentHandler
Overrides:
setDocumentLocator in interface SerializerBase

See Also:
ContentHandler.setDocumentLocator(Locator)


setEscaping

public boolean setEscaping(boolean escape)
            throws SAXException
Specified by:
setEscaping in interface SerializationHandler

See Also:
SerializationHandler.setEscaping(boolean)


setOutputFormat

public void setOutputFormat(Properties format)
Specified by:
setOutputFormat in interface Serializer

See Also:
Serializer.setOutputFormat(Properties)


setOutputStream

public void setOutputStream(OutputStream output)
Specified by:
setOutputStream in interface Serializer

See Also:
Serializer.setOutputStream(OutputStream)


setWriter

public void setWriter(Writer writer)
Specified by:
setWriter in interface Serializer

See Also:
Serializer.setWriter(Writer)


skippedEntity

public void skippedEntity(String arg0)
            throws SAXException
Specified by:
skippedEntity in interface ContentHandler

See Also:
ContentHandler.skippedEntity(String)


startCDATA

public void startCDATA()
            throws SAXException
Report the start of a CDATA section.

The contents of the CDATA section will be reported through the regular characters event; this event is intended only to report the boundary.

Specified by:
startCDATA in interface LexicalHandler

Throws:
SAXException - The application may raise an exception.

See Also:
LexicalHandler.endCDATA()


startElement

public void startElement(String elementName)
            throws SAXException
An element starts, but attributes are not fully known yet.
Specified by:
startElement in interface ExtendedContentHandler
Overrides:
startElement in interface ToSAXHandler

Parameters:
elementName - the element name, with prefix (if any).

See Also:
ExtendedContentHandler.startElement(String)


startElement

public void startElement(String elementNamespaceURI,
                         String elementLocalName,
                         String elementName)
            throws SAXException
Start an element in the output document. This might be an XML element (data type) or a CDATA section.
Specified by:
startElement in interface ExtendedContentHandler
Overrides:
startElement in interface ToSAXHandler


startElement

public void startElement(String namespaceURI,
                         String localName,
                         String name,
                         Attributes atts)
            throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in interface ToSAXHandler

See Also:
ContentHandler.startElement(String,String,String,Attributes)


startEntity

public void startEntity(String arg0)
            throws SAXException
Specified by:
startEntity in interface LexicalHandler

See Also:
LexicalHandler.startEntity(String)


startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
            throws SAXException
Specified by:
startPrefixMapping in interface ContentHandler

Parameters:
prefix - The prefix that maps to the URI
uri - The URI for the namespace

See Also:
ContentHandler.startPrefixMapping(String,String)


startPrefixMapping

public boolean startPrefixMapping(String prefix,
                                  String uri,
                                  boolean shouldFlush)
            throws SAXException
Remember the prefix/uri mapping at the current nested element depth.
Specified by:
startPrefixMapping in interface ExtendedContentHandler

Parameters:
prefix - The prefix that maps to the URI
uri - The URI for the namespace
shouldFlush - a flag indicating if the mapping applies to the current element or an up coming child (not used).

See Also:
ContentHandler.startPrefixMapping(String,String)


Copyright B) 2004 Apache XML Project. All Rights Reserved.