org.apache.xml.serializer
Class ToSAXHandler

java.lang.Object
  extended by org.apache.xml.serializer.SerializerBase
      extended by org.apache.xml.serializer.ToSAXHandler
All Implemented Interfaces:
DOMSerializer, ExtendedContentHandler, ExtendedLexicalHandler, SerializationHandler, Serializer, SerializerConstants, XSLOutputAttributes, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.ErrorHandler, org.xml.sax.ext.DeclHandler, org.xml.sax.ext.LexicalHandler
Direct Known Subclasses:
ToHTMLSAXHandler, ToTextSAXHandler, ToXMLSAXHandler

public abstract class ToSAXHandler
extends SerializerBase

This class is used to provide a base behavior to be inherited by other To...SAXHandler serializers. This class is not a public API.


Field Summary
protected  org.xml.sax.ext.LexicalHandler m_lexHandler
          Underlying LexicalHandler.
protected  org.xml.sax.ContentHandler m_saxHandler
          Underlying SAX handler.
private  boolean m_shouldGenerateNSAttribute
          A startPrefixMapping() call on a ToSAXHandler will pass that call on to the wrapped ContentHandler, but should we also mirror these calls with matching attributes, if so this field is true.
protected  TransformStateSetter m_state
          If this is true, then the content handler wrapped by this serializer implements the TransformState interface which will give the content handler access to the state of the transform.
 
Fields inherited from class org.apache.xml.serializer.SerializerBase
m_attrBuff, m_attributes, m_CdataElems, m_cdataTagOpen, m_charsBuff, m_docIsEmpty, m_doctypePublic, m_doctypeSystem, m_doIndent, m_elemContext, m_indentAmount, m_inEntityRef, m_inExternalDTD, m_mediatype, m_needToCallStartDocument, m_needToOutputDocTypeDecl, m_prefixMap, m_shouldNotWriteXMLHeader, m_sourceLocator, m_standaloneWasSpecified, m_StringOfCDATASections, m_tracer, m_version, m_writer, PKG_NAME, PKG_PATH
 
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
CDATA_CONTINUE, CDATA_DELIMITER_CLOSE, CDATA_DELIMITER_OPEN, DEFAULT_SAX_SERIALIZER, EMPTYSTRING, ENTITY_AMP, ENTITY_CRLF, ENTITY_GT, ENTITY_LT, ENTITY_QUOT, XML_PREFIX, XMLNS_PREFIX, XMLNS_URI, XMLVERSION10, XMLVERSION11
 
Constructor Summary
ToSAXHandler()
           
ToSAXHandler(org.xml.sax.ContentHandler hdlr, org.xml.sax.ext.LexicalHandler lex, java.lang.String encoding)
           
ToSAXHandler(org.xml.sax.ContentHandler handler, java.lang.String encoding)
           
 
Method Summary
 void addUniqueAttribute(java.lang.String qName, java.lang.String value, int flags)
          Add a unique attribute
 void characters(org.w3c.dom.Node node)
          This method gets the node's value as a String and uses that String as if it were an input character notification.
 void characters(java.lang.String characters)
          Receive notification of character data.
protected  void closeCDATA()
           
protected  void closeStartTag()
           
 void comment(java.lang.String comment)
          Receive notification of a comment.
 void error(org.xml.sax.SAXParseException exc)
           
 void fatalError(org.xml.sax.SAXParseException exc)
           
 void flushPending()
          This method flushes any pending events, which can be startDocument() closing the opening tag of an element, or closing an open CDATA section.
(package private)  boolean getShouldOutputNSAttr()
          Returns true if namespace declarations from calls such as startPrefixMapping("prefix1","uri1") should also be mirrored with self generated additional attributes of elements that declare the namespace, for example the attribute xmlns:prefix1="uri1"
 void processingInstruction(java.lang.String target, java.lang.String data)
          Do nothing as this is an abstract class.
 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).
private  void resetToSAXHandler()
          Reset all of the fields owned by ToSAXHandler class
 void setCdataSectionElements(java.util.Vector URI_and_localNames)
          Does nothing.
 void setContentHandler(org.xml.sax.ContentHandler _saxHandler)
          Sets the SAX ContentHandler.
 void setLexHandler(org.xml.sax.ext.LexicalHandler _lexHandler)
          Sets the LexicalHandler.
 void setShouldOutputNSAttr(boolean doOutputNSAttr)
          Set whether or not namespace declarations (e.g.
 void setTransformState(TransformStateSetter ts)
          Pass in a reference to a TransformState object, which can be used during SAX ContentHandler events to obtain information about he state of the transformation.
protected  void startDocumentInternal()
          Pass callback to the SAX Handler
 void startDTD(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2)
          Do nothing.
 void startElement(java.lang.String qName)
          An element starts, but attributes are not fully known yet.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Receives notification that an element starts, but attributes are not fully known yet.
 void startElement(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2, org.xml.sax.Attributes arg3)
          Receive notification of the beginning of an element, although this is a SAX method additional namespace or attribute information can occur before or after this call, that is associated with this element.
 void warning(org.xml.sax.SAXParseException exc)
           
 
Methods inherited from class org.apache.xml.serializer.SerializerBase
addAttribute, addAttribute, addAttribute, addAttributeAlways, addAttributes, addXSLAttribute, asContentHandler, asDOM3Serializer, asDOMSerializer, close, documentIsEmpty, endEntity, entityReference, fireCDATAEvent, fireCharEvent, fireCommentEvent, fireEndDoc, fireEndElem, fireEndEntity, fireEntityReference, fireEscapingEvent, fireStartDoc, fireStartElem, fireStartEntity, getDoctypePublic, getDoctypeSystem, getEncoding, getFirstCharLocName, getIndent, getIndentAmount, getLocalName, getMediaType, getNamespaceMappings, getNamespaceURI, getNamespaceURIFromPrefix, getOmitXMLDeclaration, getOutputPropDefaultKeys, getOutputProperty, getOutputPropertyDefault, getOutputPropertyNonDefault, getOutputPropKeys, getPrefix, getPrefixPart, getStandalone, getTransformer, getVersion, initCDATA, initCdataElems, inTemporaryOutputState, isCdataSection, namespaceAfterStartElement, notationDecl, patchName, setDoctype, setDoctypePublic, setDoctypeSystem, setDocumentLocator, setDTDEntityExpansion, setEncoding, setIndent, setIndentAmount, setMediaType, setNamespaceMappings, setOmitXMLDeclaration, setOutputProperty, setOutputPropertyDefault, setProp, setSourceLocator, setStandalone, setStandaloneInternal, setTransformer, setVersion, startDocument, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.xml.serializer.SerializationHandler
serialize, setEscaping
 
Methods inherited from interface org.apache.xml.serializer.ExtendedContentHandler
endElement, startPrefixMapping
 
Methods inherited from interface org.xml.sax.ContentHandler
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, skippedEntity, startPrefixMapping
 
Methods inherited from interface org.xml.sax.ext.LexicalHandler
comment, endCDATA, endDTD, startCDATA, startEntity
 
Methods inherited from interface org.xml.sax.ext.DeclHandler
attributeDecl, elementDecl, externalEntityDecl, internalEntityDecl
 
Methods inherited from interface org.apache.xml.serializer.Serializer
getOutputFormat, getOutputStream, getWriter, setOutputFormat, setOutputStream, setWriter
 

Field Detail

m_saxHandler

protected org.xml.sax.ContentHandler m_saxHandler
Underlying SAX handler. Taken from XSLTC


m_lexHandler

protected org.xml.sax.ext.LexicalHandler m_lexHandler
Underlying LexicalHandler. Taken from XSLTC


m_shouldGenerateNSAttribute

private boolean m_shouldGenerateNSAttribute
A startPrefixMapping() call on a ToSAXHandler will pass that call on to the wrapped ContentHandler, but should we also mirror these calls with matching attributes, if so this field is true. For example if this field is true then a call such as startPrefixMapping("prefix1","uri1") will also cause the additional internally generated attribute xmlns:prefix1="uri1" to be effectively added to the attributes passed to the wrapped ContentHandler.


m_state

protected TransformStateSetter m_state
If this is true, then the content handler wrapped by this serializer implements the TransformState interface which will give the content handler access to the state of the transform.

Constructor Detail

ToSAXHandler

public ToSAXHandler()

ToSAXHandler

public ToSAXHandler(org.xml.sax.ContentHandler hdlr,
                    org.xml.sax.ext.LexicalHandler lex,
                    java.lang.String encoding)

ToSAXHandler

public ToSAXHandler(org.xml.sax.ContentHandler handler,
                    java.lang.String encoding)
Method Detail

startDocumentInternal

protected void startDocumentInternal()
                              throws org.xml.sax.SAXException
Pass callback to the SAX Handler

Overrides:
startDocumentInternal in class SerializerBase
Throws:
org.xml.sax.SAXException

startDTD

public void startDTD(java.lang.String arg0,
                     java.lang.String arg1,
                     java.lang.String arg2)
              throws org.xml.sax.SAXException
Do nothing.

Throws:
org.xml.sax.SAXException
See Also:
LexicalHandler.startDTD(String, String, String)

characters

public void characters(java.lang.String characters)
                throws org.xml.sax.SAXException
Receive notification of character data.

Parameters:
characters - The string of characters to process.
Throws:
org.xml.sax.SAXException
See Also:
ExtendedContentHandler.characters(String)

comment

public void comment(java.lang.String comment)
             throws org.xml.sax.SAXException
Receive notification of a comment.

Specified by:
comment in interface ExtendedLexicalHandler
Overrides:
comment in class SerializerBase
Parameters:
comment - the comment, but unlike the SAX comment() method this method takes a String rather than a character array.
Throws:
org.xml.sax.SAXException
See Also:
ExtendedLexicalHandler.comment(String)

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Do nothing as this is an abstract class. All subclasses will need to define their behavior if it is different.

Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.processingInstruction(String, String)

closeStartTag

protected void closeStartTag()
                      throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

closeCDATA

protected void closeCDATA()
                   throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String arg0,
                         java.lang.String arg1,
                         java.lang.String arg2,
                         org.xml.sax.Attributes arg3)
                  throws org.xml.sax.SAXException
Receive notification of the beginning of an element, although this is a SAX method additional namespace or attribute information can occur before or after this call, that is associated with this element.

Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
org.xml.sax.SAXException
See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes), ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String), AttributeList, ContentHandler.startElement(String,String,String,Attributes)

setLexHandler

public void setLexHandler(org.xml.sax.ext.LexicalHandler _lexHandler)
Sets the LexicalHandler.

Parameters:
_lexHandler - The LexicalHandler to set

setContentHandler

public void setContentHandler(org.xml.sax.ContentHandler _saxHandler)
Sets the SAX ContentHandler.

Parameters:
_saxHandler - The ContentHandler to set
See Also:
Serializer.asContentHandler(), ToSAXHandler

setCdataSectionElements

public void setCdataSectionElements(java.util.Vector URI_and_localNames)
Does nothing. The setting of CDATA section elements has an impact on stream serializers.

Parameters:
URI_and_localNames - pairs of namespace URI and local names that identify elements whose text elements are to be output as CDATA sections. The namespace of the local element must be the given URI to match. The qName is not given because the prefix does not matter, only the namespace URI to which that prefix would map matters, so the prefix itself is not relevant in specifying which elements have their text to be output as CDATA sections.
See Also:
XSLOutputAttributes.setCdataSectionElements(java.util.Vector)

setShouldOutputNSAttr

public void setShouldOutputNSAttr(boolean doOutputNSAttr)
Set whether or not namespace declarations (e.g. xmlns:foo) should appear as attributes of elements

Parameters:
doOutputNSAttr - whether or not namespace declarations should appear as attributes

getShouldOutputNSAttr

boolean getShouldOutputNSAttr()
Returns true if namespace declarations from calls such as startPrefixMapping("prefix1","uri1") should also be mirrored with self generated additional attributes of elements that declare the namespace, for example the attribute xmlns:prefix1="uri1"


flushPending

public void flushPending()
                  throws org.xml.sax.SAXException
This method flushes any pending events, which can be startDocument() closing the opening tag of an element, or closing an open CDATA section.

Throws:
org.xml.sax.SAXException

setTransformState

public void setTransformState(TransformStateSetter ts)
Pass in a reference to a TransformState object, which can be used during SAX ContentHandler events to obtain information about he state of the transformation. This method will be called before each startDocument event.

Parameters:
ts - A reference to a TransformState object

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName)
                  throws org.xml.sax.SAXException
Receives notification that an element starts, but attributes are not fully known yet.

Parameters:
uri - the URI of the namespace of the element (optional)
localName - the element name, but without prefix (optional)
qName - the element name, with prefix, if any (required)
Throws:
org.xml.sax.SAXException
See Also:
ExtendedContentHandler.startElement(String, String, String)

startElement

public void startElement(java.lang.String qName)
                  throws org.xml.sax.SAXException
An element starts, but attributes are not fully known yet.

Parameters:
qName - the element name, with prefix (if any).
Throws:
org.xml.sax.SAXException
See Also:
ExtendedContentHandler.startElement(String)

characters

public void characters(org.w3c.dom.Node node)
                throws org.xml.sax.SAXException
This method gets the node's value as a String and uses that String as if it were an input character notification.

Specified by:
characters in interface ExtendedContentHandler
Overrides:
characters in class SerializerBase
Parameters:
node - the Node to serialize
Throws:
org.xml.sax.SAXException

fatalError

public void fatalError(org.xml.sax.SAXParseException exc)
                throws org.xml.sax.SAXException
Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Overrides:
fatalError in class SerializerBase
Throws:
org.xml.sax.SAXException
See Also:
ErrorHandler.fatalError(SAXParseException)

error

public void error(org.xml.sax.SAXParseException exc)
           throws org.xml.sax.SAXException
Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class SerializerBase
Throws:
org.xml.sax.SAXException
See Also:
ErrorHandler.error(SAXParseException)

warning

public void warning(org.xml.sax.SAXParseException exc)
             throws org.xml.sax.SAXException
Specified by:
warning in interface org.xml.sax.ErrorHandler
Overrides:
warning in class SerializerBase
Throws:
org.xml.sax.SAXException
See Also:
ErrorHandler.warning(SAXParseException)

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 class SerializerBase
Returns:
true if the class was successfuly reset.
See Also:
Serializer.reset()

resetToSAXHandler

private void resetToSAXHandler()
Reset all of the fields owned by ToSAXHandler class


addUniqueAttribute

public void addUniqueAttribute(java.lang.String qName,
                               java.lang.String value,
                               int flags)
                        throws org.xml.sax.SAXException
Add a unique attribute

Parameters:
qName - the fully qualified attribute name.
value - the attribute value
flags - a bitwise flag
Throws:
org.xml.sax.SAXException