org.apache.cocoon.xml
Class SaxBuffer

java.lang.Object
  extended by org.apache.cocoon.xml.AbstractSAXFragment
      extended by org.apache.cocoon.xml.SaxBuffer
All Implemented Interfaces:
Serializable, Poolable, Recyclable, XMLFragment, XMLConsumer, XMLizable, ContentHandler, LexicalHandler
Direct Known Subclasses:
ParamSaxBuffer

public class SaxBuffer
extends AbstractSAXFragment
implements XMLConsumer, Recyclable, Serializable

A class that can record SAX events and replay them later.

Compared to XMLByteStreamCompiler, this class is many times faster at sending out the recorded SAX events since it doesn't need to convert between byte and char representations etc. On the other hand, its data structure is more complex then a simple byte array, making XMLByteStreamCompiler better in case the recorded SAX should be stored long-term.

Use this class if you need to frequently generate smaller amounts of SAX events, or replay a set of recorded start events immediately.

Both ContentHandler and LexicalHandler are supported, the only exception is that the setDocumentLocator event is not recorded.

Version:
CVS $Id: SaxBuffer.html 1304258 2012-03-23 10:09:27Z ilgrosso $
See Also:
Serialized Form

Nested Class Summary
static class SaxBuffer.Characters
           
static class SaxBuffer.Comment
           
static class SaxBuffer.EndCDATA
           
static class SaxBuffer.EndDocument
           
static class SaxBuffer.EndDTD
           
static class SaxBuffer.EndElement
           
static class SaxBuffer.EndEntity
           
static class SaxBuffer.EndPrefixMapping
           
static class SaxBuffer.IgnorableWhitespace
           
static class SaxBuffer.PI
           
static class SaxBuffer.SkippedEntity
           
static class SaxBuffer.StartCDATA
           
static class SaxBuffer.StartDocument
           
static class SaxBuffer.StartDTD
           
static class SaxBuffer.StartElement
           
static class SaxBuffer.StartEntity
           
static class SaxBuffer.StartPrefixMapping
           
static class SaxBuffer.XMLizableBit
           
 
Field Summary
protected  List saxbits
          Stores list of SaxBit objects.
 
Constructor Summary
SaxBuffer()
          Creates empty SaxBuffer
SaxBuffer(List bits)
          Creates SaxBuffer based on the provided bits list.
SaxBuffer(SaxBuffer saxBuffer)
          Creates copy of another SaxBuffer
 
Method Summary
protected  void addBit(org.apache.cocoon.xml.SaxBuffer.SaxBit bit)
          Adds a SaxBit to the bits list
protected  Iterator bits()
          Iterates through the bits list
 void characters(char[] ch, int start, int length)
           
 void comment(char[] ch, int start, int length)
           
 void dump(Writer writer)
          Dump buffer contents into the provided writer.
 void endCDATA()
           
 void endDocument()
           
 void endDTD()
           
 void endElement(String namespaceURI, String localName, String qName)
           
 void endEntity(String name)
           
 void endPrefixMapping(String prefix)
           
 List getBits()
           
 void ignorableWhitespace(char[] ch, int start, int length)
           
 boolean isEmpty()
           
 void processingInstruction(String target, String data)
           
 void recycle()
          Clear this buffer
 void setDocumentLocator(Locator locator)
           
 void skippedEntity(String name)
           
 void startCDATA()
           
 void startDocument()
           
 void startDTD(String name, String publicId, String systemId)
           
 void startElement(String namespaceURI, String localName, String qName, Attributes atts)
           
 void startEntity(String name)
           
 void startPrefixMapping(String prefix, String uri)
           
 void toSAX(ContentHandler contentHandler)
          Stream this buffer into the provided content handler.
 String toString()
           
 void xmlizable(XMLizable xml)
          Add a bit containing XMLizable object
 
Methods inherited from class org.apache.cocoon.xml.AbstractSAXFragment
toDOM
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

saxbits

protected List saxbits
Stores list of SaxBit objects.

Constructor Detail

SaxBuffer

public SaxBuffer()
Creates empty SaxBuffer


SaxBuffer

public SaxBuffer(List bits)
Creates SaxBuffer based on the provided bits list.


SaxBuffer

public SaxBuffer(SaxBuffer saxBuffer)
Creates copy of another SaxBuffer

Method Detail

skippedEntity

public void skippedEntity(String name)
                   throws SAXException
Specified by:
skippedEntity in interface ContentHandler
Throws:
SAXException

setDocumentLocator

public void setDocumentLocator(Locator locator)
Specified by:
setDocumentLocator in interface ContentHandler

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Specified by:
ignorableWhitespace in interface ContentHandler
Throws:
SAXException

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Specified by:
processingInstruction in interface ContentHandler
Throws:
SAXException

startDocument

public void startDocument()
                   throws SAXException
Specified by:
startDocument in interface ContentHandler
Throws:
SAXException

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Throws:
SAXException

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
Specified by:
endPrefixMapping in interface ContentHandler
Throws:
SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Specified by:
characters in interface ContentHandler
Throws:
SAXException

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
Specified by:
endDocument in interface ContentHandler
Throws:
SAXException

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Specified by:
startPrefixMapping in interface ContentHandler
Throws:
SAXException

endCDATA

public void endCDATA()
              throws SAXException
Specified by:
endCDATA in interface LexicalHandler
Throws:
SAXException

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
Specified by:
comment in interface LexicalHandler
Throws:
SAXException

startEntity

public void startEntity(String name)
                 throws SAXException
Specified by:
startEntity in interface LexicalHandler
Throws:
SAXException

endDTD

public void endDTD()
            throws SAXException
Specified by:
endDTD in interface LexicalHandler
Throws:
SAXException

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
              throws SAXException
Specified by:
startDTD in interface LexicalHandler
Throws:
SAXException

startCDATA

public void startCDATA()
                throws SAXException
Specified by:
startCDATA in interface LexicalHandler
Throws:
SAXException

endEntity

public void endEntity(String name)
               throws SAXException
Specified by:
endEntity in interface LexicalHandler
Throws:
SAXException

xmlizable

public void xmlizable(XMLizable xml)
Add a bit containing XMLizable object


isEmpty

public boolean isEmpty()
Returns:
true if buffer is empty

getBits

public List getBits()
Returns:
unmodifiable list of SAX bits

toSAX

public void toSAX(ContentHandler contentHandler)
           throws SAXException
Stream this buffer into the provided content handler. If contentHandler object implements LexicalHandler, it will get lexical events as well.

Specified by:
toSAX in interface XMLizable
Throws:
SAXException

toString

public String toString()
Overrides:
toString in class Object
Returns:
String value of the buffer

recycle

public void recycle()
Clear this buffer

Specified by:
recycle in interface Recyclable

dump

public void dump(Writer writer)
          throws IOException
Dump buffer contents into the provided writer.

Throws:
IOException

addBit

protected final void addBit(org.apache.cocoon.xml.SaxBuffer.SaxBit bit)
Adds a SaxBit to the bits list


bits

protected final Iterator bits()
Iterates through the bits list



Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.