net.sf.fikin.xml.sax
Class BufferingPipe

java.lang.Object
  extended by net.sf.fikin.xml.sax.PipeHandler
      extended by net.sf.fikin.xml.sax.BufferingPipe
All Implemented Interfaces:
SAXHandler, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.ErrorHandler, org.xml.sax.ext.LexicalHandler

public class BufferingPipe
extends PipeHandler

SAX Pipe with ability to buffer SAX events into BufferingPipe(Object) object.

This is a genuine pipe element piping incoming SAX events to the assigned handler object. But it allow for a temporary diverting of the events into a BufferHandler object.

One can think of it as XML sub-tree splitter. When bufferInto(BufferHandler) is called it diverts the following XML sub-tree into the buffer and then resumes sending to the original handler (specified during construction time BufferingPipe(Object). It counts all start-end element events and keeps track of the element's depth in order to do that.

When bufferInto(BufferHandler) is called, it will remember current element's depth and pipe's hanlders and will replace them with given buffer. All consequent events will be forwarded to the buffer.

When events related to the inner XML elements are all received it will restore original pipe's hanlders automatically and continue forwarding events to them. created on Aug 17, 2006

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

Field Summary
protected  BufferHandler buffer
          buffering object
protected  int elementDepth
          currently parsed element depth
protected  boolean inBufferMode
          flag which if true this pipe is in buffering mode
protected  int markedDepth
          elements depth when buffering occured
 
Constructor Summary
BufferingPipe()
           
BufferingPipe(java.lang.Object handler)
          Construct a pipe forwarding all events to given handler
 
Method Summary
 void bufferInto(BufferHandler buffer)
          buffer all following events into given buffer.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          decreate nested elements counter and delegate to piped object
protected  void exitBufferingMode()
          exit buffering mode.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
          increate nested elements counter and delegate to piped object
 
Methods inherited from class net.sf.fikin.xml.sax.PipeHandler
characters, characters, comment, comment, endCDATA, endDocument, endDTD, endEntity, endPrefixMapping, error, fatalError, getContentHandler, getDocumentLocator, getDTDHandler, getErrorHandler, getLexicalHandler, ignorableWhitespace, ignorableWhitespace, notationDecl, processingInstruction, setContentHandler, setDocumentLocator, setDTDHandler, setErrorHandler, setHandler, setLexicalHandler, skippedEntity, startCDATA, startDocument, startDTD, startEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inBufferMode

protected boolean inBufferMode
flag which if true this pipe is in buffering mode


markedDepth

protected int markedDepth
elements depth when buffering occured


elementDepth

protected int elementDepth
currently parsed element depth


buffer

protected BufferHandler buffer
buffering object

Constructor Detail

BufferingPipe

public BufferingPipe()

BufferingPipe

public BufferingPipe(java.lang.Object handler)
Construct a pipe forwarding all events to given handler

Parameters:
handler - is an object implementing any or all of the following interfaces: DTDHandler, ContentHandler, ErrorHandler, LexicalHandler
Method Detail

bufferInto

public void bufferInto(BufferHandler buffer)
buffer all following events into given buffer. takes into account nested structure of the XML document by conting start-end element depth. when this method is called it will buffer all inner element events and then restore original pipe's hanlder automatically.

Parameters:
buffer -

exitBufferingMode

protected void exitBufferingMode()
exit buffering mode. restore orignal pipe hanlder


startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
increate nested elements counter and delegate to piped object

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class PipeHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
decreate nested elements counter and delegate to piped object

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class PipeHandler
Throws:
org.xml.sax.SAXException


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