net.sf.fikin.xml.sax
Class CompletingBufferHandler

java.lang.Object
  extended by net.sf.fikin.xml.sax.BufferHandler
      extended by net.sf.fikin.xml.sax.CompletingBufferHandler
All Implemented Interfaces:
SAXHandler, SAXHandlerAndResolver, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.ext.LexicalHandler

public class CompletingBufferHandler
extends BufferHandler

This is a BufferHandler.BufferHandler() but ability to "interpolate" all missing end-tags.

Upon call to emmitComplete(ContentHandler) it will emmit all events buffered so far and then "generate" end-events for all still so far not-matched start-element events.

Typical schenario is when there is a long running XML-outputting process but one would like to have a valid XML document (for consequent processing) in meantime.

Example:

      // start XML processing
      CompletingBufferHandler buf = new CompletingBufferHandler();
      XMLReader reader = XMLReaderFactory.createXMLReader()
      reader.setContentHandler( buf );
      reader.setDTDHandler( buf );
      reader.setEntityResolver( buf );
      reader.parse( input );
      
      // in separate thread (or still in main ome)
      // do periodically:
      buf.emmitComplete( someOutput );
      ...
 
created on Oct 17, 2006

Since:
Version:
$Revision: 1.3 $
Author:
fiykov

Constructor Summary
CompletingBufferHandler()
           
 
Method Summary
 void emmitComplete(org.xml.sax.ContentHandler handler)
          Emmit buffered SAX events.
 void endDocument()
          mark that input is over
 
Methods inherited from class net.sf.fikin.xml.sax.BufferHandler
characters, characters, clear, comment, comment, emmit, endCDATA, endDTD, endElement, endEntity, endPrefixMapping, error, fatalError, getBuffer, ignorableWhitespace, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startCDATA, startDocument, startDTD, startElement, startEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompletingBufferHandler

public CompletingBufferHandler()
Method Detail

emmitComplete

public void emmitComplete(org.xml.sax.ContentHandler handler)
                   throws org.xml.sax.SAXException,
                          java.io.IOException
Emmit buffered SAX events.

All events will be emmited in the receiving order and only difference is that all character array methods (such as character and whitespace) are backed by String-objects.

All missing endElement events (matching each startElement event) will be generated on fly.

This way the emmited event flow will always provide with well formed xml document.

Parameters:
handler - receiving SAX events. This object is supposed to implement any or all of ContentHandler, ErrorHandler, DTDHandler or LexicalHandler interfaces. This method will emmit events only to supported by the handler methods.
Throws:
org.xml.sax.SAXException
java.io.IOException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
mark that input is over

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class BufferHandler
Throws:
org.xml.sax.SAXException


Copyright © 2003-2007 Nikolay Fiykov. All Rights Reserved.