Class ToSAXHandler
- All Implemented Interfaces:
DOMSerializer,ExtendedContentHandler,ExtendedLexicalHandler,SerializationHandler,Serializer,ContentHandler,DTDHandler,ErrorHandler,DeclHandler,LexicalHandler
- Direct Known Subclasses:
ToTextSAXHandler,ToXMLSAXHandler
public abstract class ToSAXHandler extends SerializerBase
-
Field Summary
Fields Modifier and Type Field Description static StringCDATA_CONTINUETo insert ]]> in a CDATA section by ending the last CDATA section with ]] and starting the next CDATA section with >static StringCDATA_DELIMITER_CLOSEThe constant "]]>"static StringCDATA_DELIMITER_OPENstatic StringDEFAULT_SAX_SERIALIZERstatic StringEMPTYSTRINGstatic StringENTITY_AMPstatic StringENTITY_CRLFstatic StringENTITY_GTstatic StringENTITY_LTstatic StringENTITY_QUOTprotected LexicalHandlerm_lexHandlerUnderlying LexicalHandler.protected ContentHandlerm_saxHandlerUnderlying SAX handler.protected TransformStateSetterm_stateIf 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.static StringXML_PREFIXstatic StringXMLNS_PREFIXstatic StringXMLNS_URIstatic StringXMLVERSION10static StringXMLVERSION11Define the XML version.Fields inherited from class org.apache.xml.serializer.SerializerBase
m_attrBuff, m_attributes, m_CdataElems, m_cdataTagOpen, m_charsBuff, m_doctypePublic, m_doctypeSystem, m_doIndent, m_elemContext, m_indentAmount, m_inEntityRef, m_inExternalDTD, m_mediatype, m_needToCallStartDocument, m_prefixMap, m_shouldNotWriteXMLHeader, m_sourceLocator, m_standaloneWasSpecified, m_StringOfCDATASections, m_tracer, m_version, m_writer, PKG_NAME, PKG_PATHFields inherited from interface org.apache.xml.serializer.ExtendedContentHandler
HTML_ATTREMPTY, HTML_ATTRURL, NO_BAD_CHARS -
Constructor Summary
Constructors Constructor Description ToSAXHandler()ToSAXHandler(ContentHandler handler, String encoding)ToSAXHandler(ContentHandler hdlr, LexicalHandler lex, String encoding) -
Method Summary
Modifier and Type Method Description voidaddUniqueAttribute(String qName, String value, int flags)Add a unique attributevoidcharacters(String characters)Receive notification of character data.voidcharacters(Node node)This method gets the node's value as a String and uses that String as if it were an input character notification.protected voidcloseCDATA()protected voidcloseStartTag()voidcomment(String comment)Receive notification of a comment.voiderror(SAXParseException exc)Receive notification of a recoverable error.voidfatalError(SAXParseException exc)Receive notification of a non-recoverable error.voidflushPending()This method flushes any pending events, which can be startDocument() closing the opening tag of an element, or closing an open CDATA section.voidprocessingInstruction(String target, String data)Do nothing as this is an abstract class.booleanreset()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).voidsetCdataSectionElements(Vector URI_and_localNames)Does nothing.voidsetContentHandler(ContentHandler _saxHandler)Sets the SAX ContentHandler.voidsetLexHandler(LexicalHandler _lexHandler)Sets the LexicalHandler.voidsetShouldOutputNSAttr(boolean doOutputNSAttr)Set whether or not namespace declarations (e.g.voidsetTransformState(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 voidstartDocumentInternal()Pass callback to the SAX HandlervoidstartDTD(String arg0, String arg1, String arg2)Do nothing.voidstartElement(String qName)An element starts, but attributes are not fully known yet.voidstartElement(String uri, String localName, String qName)Receives notification that an element starts, but attributes are not fully known yet.voidstartElement(String arg0, String arg1, String arg2, 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.voidwarning(SAXParseException exc)Receive notification of a warning.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, getIndent, getIndentAmount, getLocalName, getMediaType, getNamespaceMappings, getNamespaceURI, getNamespaceURIFromPrefix, getOmitXMLDeclaration, getOutputProperty, getOutputPropertyDefault, getOutputPropertyNonDefault, getPrefix, getPrefixPart, getStandalone, getTransformer, getVersion, initCDATA, isCdataSection, namespaceAfterStartElement, notationDecl, patchName, setDoctype, setDoctypePublic, setDoctypeSystem, setDocumentLocator, setDTDEntityExpansion, setEncoding, setIndent, setIndentAmount, setMediaType, setNamespaceMappings, setOmitXMLDeclaration, setOutputProperty, setOutputPropertyDefault, setSourceLocator, setStandalone, setStandaloneInternal, setTransformer, setVersion, startDocument, unparsedEntityDeclMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.xml.sax.ContentHandler
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, skippedEntity, startPrefixMappingMethods inherited from interface org.xml.sax.ext.DeclHandler
attributeDecl, elementDecl, externalEntityDecl, internalEntityDeclMethods inherited from interface org.apache.xml.serializer.ExtendedContentHandler
endElement, startPrefixMappingMethods inherited from interface org.xml.sax.ext.LexicalHandler
comment, endCDATA, endDTD, startCDATA, startEntityMethods inherited from interface org.apache.xml.serializer.SerializationHandler
serialize, setEscapingMethods inherited from interface org.apache.xml.serializer.Serializer
getOutputFormat, getOutputStream, getWriter, setOutputFormat, setOutputStream, setWriter
-
Field Details
-
m_saxHandler
Underlying SAX handler. Taken from XSLTC -
m_lexHandler
Underlying LexicalHandler. Taken from XSLTC -
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. -
CDATA_CONTINUE
To insert ]]> in a CDATA section by ending the last CDATA section with ]] and starting the next CDATA section with >- See Also:
- Constant Field Values
-
CDATA_DELIMITER_CLOSE
The constant "]]>"- See Also:
- Constant Field Values
-
CDATA_DELIMITER_OPEN
- See Also:
- Constant Field Values
-
EMPTYSTRING
- See Also:
- Constant Field Values
-
ENTITY_AMP
- See Also:
- Constant Field Values
-
ENTITY_CRLF
- See Also:
- Constant Field Values
-
ENTITY_GT
- See Also:
- Constant Field Values
-
ENTITY_LT
- See Also:
- Constant Field Values
-
ENTITY_QUOT
- See Also:
- Constant Field Values
-
XML_PREFIX
- See Also:
- Constant Field Values
-
XMLNS_PREFIX
- See Also:
- Constant Field Values
-
XMLNS_URI
- See Also:
- Constant Field Values
-
DEFAULT_SAX_SERIALIZER
-
XMLVERSION11
Define the XML version.- See Also:
- Constant Field Values
-
XMLVERSION10
- See Also:
- Constant Field Values
-
-
Constructor Details
-
ToSAXHandler
public ToSAXHandler() -
ToSAXHandler
-
ToSAXHandler
-
-
Method Details
-
startDocumentInternal
Pass callback to the SAX Handler- Overrides:
startDocumentInternalin classSerializerBase- Throws:
SAXException
-
startDTD
Do nothing.- Parameters:
arg0- The document type name.arg1- The declared public identifier for the external DTD subset, or null if none was declared.arg2- 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.)- Throws:
SAXException- The application may raise an exception.- See Also:
LexicalHandler.startDTD(String, String, String)
-
characters
Receive notification of character data.- Parameters:
characters- The string of characters to process.- Throws:
SAXException- See Also:
ExtendedContentHandler.characters(String)
-
comment
Receive notification of a comment.- Specified by:
commentin interfaceExtendedLexicalHandler- Overrides:
commentin classSerializerBase- Parameters:
comment- the comment, but unlike the SAX comment() method this method takes a String rather than a character array.- Throws:
SAXException- See Also:
ExtendedLexicalHandler.comment(String)
-
processingInstruction
Do nothing as this is an abstract class. All subclasses will need to define their behavior if it is different.- Parameters:
target- the processing instruction targetdata- the processing instruction data, or null if none was supplied. The data does not include any whitespace separating it from the target- Throws:
SAXException- any SAX exception, possibly wrapping another exception- See Also:
ContentHandler.processingInstruction(String, String)
-
closeStartTag
- Throws:
SAXException
-
closeCDATA
- Throws:
SAXException
-
startElement
public void startElement(String arg0, String arg1, String arg2, Attributes arg3) throws SAXExceptionReceive 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.- Parameters:
arg0- the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performedarg1- the local name (without prefix), or the empty string if Namespace processing is not being performedarg2- the qualified name (with prefix), or the empty string if qualified names are not availablearg3- the attributes attached to the element. If there are no attributes, it shall be an empty Attributes object. The value of this object after startElement returns is undefined- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.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
Sets the LexicalHandler.- Parameters:
_lexHandler- The LexicalHandler to set
-
setContentHandler
Sets the SAX ContentHandler.- Parameters:
_saxHandler- The ContentHandler to set- See Also:
Serializer.asContentHandler(),ToSAXHandler
-
setCdataSectionElements
Does nothing. The setting of CDATA section elements has an impact on stream serializers.- 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
-
flushPending
This method flushes any pending events, which can be startDocument() closing the opening tag of an element, or closing an open CDATA section.- Throws:
SAXException
-
setTransformState
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
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:
SAXException- See Also:
ExtendedContentHandler.startElement(String, String, String)
-
startElement
An element starts, but attributes are not fully known yet.- Parameters:
qName- the element name, with prefix (if any).- Throws:
SAXException- See Also:
ExtendedContentHandler.startElement(String)
-
characters
This method gets the node's value as a String and uses that String as if it were an input character notification.- Specified by:
charactersin interfaceExtendedContentHandler- Overrides:
charactersin classSerializerBase- Parameters:
node- the Node to serialize- Throws:
SAXException
-
fatalError
Description copied from interface:ErrorHandlerReceive notification of a non-recoverable error.There is an apparent contradiction between the documentation for this method and the documentation for
ContentHandler.endDocument(). Until this ambiguity is resolved in a future major release, clients should make no assumptions about whether endDocument() will or will not be invoked when the parser has reported a fatalError() or thrown an exception.This corresponds to the definition of "fatal error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a parser would use this callback to report the violation of a well-formedness constraint.
The application must assume that the document is unusable after the parser has invoked this method, and should continue (if at all) only for the sake of collecting additional error messages: in fact, SAX parsers are free to stop reporting any other events once this method has been invoked.
- Specified by:
fatalErrorin interfaceErrorHandler- Overrides:
fatalErrorin classSerializerBase- Parameters:
exc- The error information encapsulated in a SAX parse exception.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
ErrorHandler.fatalError(SAXParseException)
-
error
Description copied from interface:ErrorHandlerReceive notification of a recoverable error.This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action.
The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML recommendation does not require it to do so.
Filters may use this method to report other, non-XML errors as well.
- Specified by:
errorin interfaceErrorHandler- Overrides:
errorin classSerializerBase- Parameters:
exc- The error information encapsulated in a SAX parse exception.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
ErrorHandler.error(SAXParseException)
-
warning
Description copied from interface:ErrorHandlerReceive notification of a warning.SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML recommendation. The default behaviour is to take no action.
The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.
Filters may use this method to report other, non-XML warnings as well.
- Specified by:
warningin interfaceErrorHandler- Overrides:
warningin classSerializerBase- Parameters:
exc- The warning information encapsulated in a SAX parse exception.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- 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:
resetin interfaceSerializer- Overrides:
resetin classSerializerBase- Returns:
- true if the class was successfuly reset.
- See Also:
Serializer.reset()
-
addUniqueAttribute
Add a unique attribute- Parameters:
qName- the fully qualified attribute name.value- the attribute valueflags- a bitwise flag- Throws:
SAXException
-