Class TransformerHandlerImpl

  • All Implemented Interfaces:
    javax.xml.transform.sax.TransformerHandler, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.ext.LexicalHandler

    public class TransformerHandlerImpl
    extends ReceivingContentHandler
    implements javax.xml.transform.sax.TransformerHandler
    TransformerHandlerImpl implements the javax.xml.transform.sax.TransformerHandler interface. It acts as a ContentHandler and LexicalHandler which receives a stream of SAX events representing an input document, and performs a transformation treating this SAX stream as the source document of the transformation.

    The TransformerHandler is written on the assumption that it is receiving events from a parser configured with http://xml.org/sax/features/namespaces set to true and http://xml.org/sax/features/namespace-prefixes set to false. The TransformerHandler has no control over the feature settings of the sender of the events (which is not even necessarily an XMLReader), and if the events do not follow this pattern then the class may fail in unpredictable ways.

    • Constructor Detail

      • TransformerHandlerImpl

        protected TransformerHandlerImpl​(TransformerImpl transformer)
        Create a TransformerHandlerImpl and initialise variables. The constructor is protected, because the Filter should be created using newTransformerHandler() in the SAXTransformerFactory class
        Parameters:
        transformer - the Controller to be used
    • Method Detail

      • startDocument

        public void startDocument()
                           throws org.xml.sax.SAXException
        Start of a new document. The TransformerHandler is not serially reusable, so this method must only be called once.
        Specified by:
        startDocument in interface org.xml.sax.ContentHandler
        Overrides:
        startDocument in class ReceivingContentHandler
        Throws:
        org.xml.sax.SAXException - only if an overriding subclass throws this exception
        java.lang.UnsupportedOperationException - if an attempt is made to reuse the TransformerHandler by calling startDocument() more than once.
      • getTransformer

        public javax.xml.transform.Transformer getTransformer()
        Get the Transformer used for this transformation
        Specified by:
        getTransformer in interface javax.xml.transform.sax.TransformerHandler
      • setSystemId

        public void setSystemId​(java.lang.String url)
        Set the SystemId of the document. Note that in reporting location information, Saxon gives priority to the system Id reported by the SAX Parser in the Locator passed to the ReceivingContentHandler.setDocumentLocator(org.xml.sax.Locator) method. The SystemId passed to this method is used as the base URI for resolving relative references.
        Specified by:
        setSystemId in interface javax.xml.transform.sax.TransformerHandler
        Parameters:
        url - the systemId of the source document
      • setResult

        public void setResult​(javax.xml.transform.Result result)
        Set the Result associated with this TransformerHandler to be used for the transformation.
        Specified by:
        setResult in interface javax.xml.transform.sax.TransformerHandler
        Parameters:
        result - A Result instance, should not be null.
        Throws:
        java.lang.IllegalArgumentException - if result is invalid for some reason.
      • getResult

        public javax.xml.transform.Result getResult()
        Get the output destination of the transformation
        Returns:
        the output destination
      • endDocument

        public void endDocument()
                         throws org.xml.sax.SAXException
        Override the behaviour of endDocument() in ReceivingContentHandler, so that it fires off the transformation of the constructed document
        Specified by:
        endDocument in interface org.xml.sax.ContentHandler
        Overrides:
        endDocument in class ReceivingContentHandler
        Throws:
        org.xml.sax.SAXException