org.apache.xml.serializer

## Class ToSAXHandler

- java.lang.Object
- - org.apache.xml.serializer.SerializerBase
  - - org.apache.xml.serializer.ToSAXHandler

- All Implemented Interfaces:
    DOMSerializer, ExtendedContentHandler, ExtendedLexicalHandler, SerializationHandler, Serializer, ContentHandler, DTDHandler, ErrorHandler, DeclHandler, 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.
  Usage:
    **For internal use only**

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `CDATA_CONTINUE` To insert ]]> in a CDATA section by ending the last CDATA section with ]] and starting the next CDATA section with >
    `static java.lang.String` | `CDATA_DELIMITER_CLOSE` The constant "]]>"
    `static java.lang.String` | `CDATA_DELIMITER_OPEN`
    `static java.lang.String` | `DEFAULT_SAX_SERIALIZER`
    `static java.lang.String` | `EMPTYSTRING`
    `static java.lang.String` | `ENTITY_AMP`
    `static java.lang.String` | `ENTITY_CRLF`
    `static java.lang.String` | `ENTITY_GT`
    `static java.lang.String` | `ENTITY_LT`
    `static java.lang.String` | `ENTITY_QUOT`
    `static java.lang.String` | `XML_PREFIX`
    `static java.lang.String` | `XMLNS_PREFIX`
    `static java.lang.String` | `XMLNS_URI`
    `static java.lang.String` | `XMLVERSION10`
    `static java.lang.String` | `XMLVERSION11` Define the XML version.

    - ### Fields inherited from class org.apache.xml.serializer.SerializerBase

      `PKG_NAME, PKG_PATH`

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

      `HTML_ATTREMPTY, HTML_ATTRURL, NO_BAD_CHARS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ToSAXHandler()`
    `ToSAXHandler(ContentHandler hdlr, LexicalHandler lex, java.lang.String encoding)`
    `ToSAXHandler(ContentHandler handler, java.lang.String encoding)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addUniqueAttribute(java.lang.String qName, java.lang.String value, int flags)` Add a unique attribute
    `void` | `characters(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.
    `void` | `comment(java.lang.String comment)` Receive notification of a comment.
    `void` | `error(SAXParseException exc)` Receive notification of a recoverable error.
    `void` | `fatalError(SAXParseException exc)` Receive notification of a non-recoverable error.
    `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.
    `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).
    `void` | `setCdataSectionElements(java.util.Vector URI_and_localNames)` Does nothing.
    `void` | `setContentHandler(ContentHandler _saxHandler)` Sets the SAX ContentHandler.
    `void` | `setLexHandler(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.
    `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, 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(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, fireEndEntity, getDoctypePublic, getDoctypeSystem, getEncoding, getIndent, getIndentAmount, getMediaType, getNamespaceMappings, getNamespaceURI, getNamespaceURIFromPrefix, getOmitXMLDeclaration, getOutputProperty, getOutputPropertyDefault, getOutputPropertyNonDefault, getPrefix, getStandalone, getTransformer, getVersion, namespaceAfterStartElement, notationDecl, setDoctype, setDoctypePublic, setDoctypeSystem, setDocumentLocator, setDTDEntityExpansion, setEncoding, setIndent, setIndentAmount, setMediaType, setNamespaceMappings, setOmitXMLDeclaration, setOutputProperty, setOutputPropertyDefault, setSourceLocator, setStandalone, setTransformer, setVersion, startDocument, unparsedEntityDecl`

    - ### Methods inherited from class java.lang.Object

      `equals, 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

    - #### CDATA_CONTINUE

          public static final java.lang.String 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

          public static final java.lang.String CDATA_DELIMITER_CLOSE

      The constant "]]>"
      See Also:
        Constant Field Values

    - #### CDATA_DELIMITER_OPEN

          public static final java.lang.String CDATA_DELIMITER_OPEN

      See Also:
        Constant Field Values

    - #### EMPTYSTRING

          public static final java.lang.String EMPTYSTRING

      See Also:
        Constant Field Values

    - #### ENTITY_AMP

          public static final java.lang.String ENTITY_AMP

      See Also:
        Constant Field Values

    - #### ENTITY_CRLF

          public static final java.lang.String ENTITY_CRLF

      See Also:
        Constant Field Values

    - #### ENTITY_GT

          public static final java.lang.String ENTITY_GT

      See Also:
        Constant Field Values

    - #### ENTITY_LT

          public static final java.lang.String ENTITY_LT

      See Also:
        Constant Field Values

    - #### ENTITY_QUOT

          public static final java.lang.String ENTITY_QUOT

      See Also:
        Constant Field Values

    - #### XML_PREFIX

          public static final java.lang.String XML_PREFIX

      See Also:
        Constant Field Values

    - #### XMLNS_PREFIX

          public static final java.lang.String XMLNS_PREFIX

      See Also:
        Constant Field Values

    - #### XMLNS_URI

          public static final java.lang.String XMLNS_URI

      See Also:
        Constant Field Values

    - #### DEFAULT_SAX_SERIALIZER

          public static final java.lang.String DEFAULT_SAX_SERIALIZER

    - #### XMLVERSION11

          public static final java.lang.String XMLVERSION11

      Define the XML version.
      See Also:
        Constant Field Values

    - #### XMLVERSION10

          public static final java.lang.String XMLVERSION10

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ToSAXHandler

          public ToSAXHandler()

    - #### ToSAXHandler

          public ToSAXHandler(ContentHandler hdlr,
                      LexicalHandler lex,
                      java.lang.String encoding)

    - #### ToSAXHandler

          public ToSAXHandler(ContentHandler handler,
                      java.lang.String encoding)

  - ### Method Detail

    - #### startDTD

          public void startDTD(java.lang.String arg0,
                      java.lang.String arg1,
                      java.lang.String arg2)
                        throws SAXException

      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

          public void characters(java.lang.String characters)
                          throws SAXException

      Receive notification of character data.
      Parameters:
        `characters` - The string of characters to process.
      Throws:
        `SAXException`
      See Also:
        `ExtendedContentHandler.characters(String)`

    - #### comment

          public void comment(java.lang.String comment)
                       throws 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:
        `SAXException`
      See Also:
        `ExtendedLexicalHandler.comment(String)`

    - #### processingInstruction

          public void processingInstruction(java.lang.String target,
                                   java.lang.String data)
                                     throws SAXException

      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 target
        `data` - 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)`

    - #### startElement

          public void startElement(java.lang.String arg0,
                          java.lang.String arg1,
                          java.lang.String arg2,
                          Attributes arg3)
                            throws 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.
      Parameters:
        `arg0` - the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed
        `arg1` - the local name (without prefix), or the empty string if Namespace processing is not being performed
        `arg2` - the qualified name (with prefix), or the empty string if qualified names are not available
        `arg3` - 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

          public void setLexHandler(LexicalHandler _lexHandler)

      Sets the LexicalHandler.
      Parameters:
        `_lexHandler` - The LexicalHandler to set

    - #### setContentHandler

          public void setContentHandler(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

    - #### flushPending

          public void flushPending()
                            throws 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:
        `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 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:
        `SAXException`
      See Also:
        `ExtendedContentHandler.startElement(String, String, String)`

    - #### startElement

          public void startElement(java.lang.String qName)
                            throws SAXException

      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

          public void characters(Node node)
                          throws 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:
        `SAXException`

    - #### fatalError

          public void fatalError(SAXParseException exc)
                          throws SAXException

      Description copied from interface: `ErrorHandler`
      Receive 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:
        `fatalError` in interface `ErrorHandler`
      Overrides:
        `fatalError` in class `SerializerBase`
      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

          public void error(SAXParseException exc)
                     throws SAXException

      Description copied from interface: `ErrorHandler`
      Receive 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:
        `error` in interface `ErrorHandler`
      Overrides:
        `error` in class `SerializerBase`
      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

          public void warning(SAXParseException exc)
                       throws SAXException

      Description copied from interface: `ErrorHandler`
      Receive 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:
        `warning` in interface `ErrorHandler`
      Overrides:
        `warning` in class `SerializerBase`
      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:
        `reset` in interface `Serializer`
      Overrides:
        `reset` in class `SerializerBase`
      Returns:
        true if the class was successfuly reset.
      See Also:
        `Serializer.reset()`

    - #### addUniqueAttribute

          public void addUniqueAttribute(java.lang.String qName,
                                java.lang.String value,
                                int flags)
                                  throws SAXException

      Add a unique attribute
      Parameters:
        `qName` - the fully qualified attribute name.
        `value` - the attribute value
        `flags` - a bitwise flag
      Throws:
        `SAXException`

Copyright © 2014 Apache XML Project. All Rights Reserved.