Package org.apache.cocoon.xml.sax
Class SAXBuffer
- java.lang.Object
-
- org.apache.cocoon.xml.sax.SAXBuffer
-
- All Implemented Interfaces:
Serializable
,ContentHandler
,LexicalHandler
public class SAXBuffer extends Object implements ContentHandler, LexicalHandler, Serializable
A class that can record SAX events and replay them later.Compared to the old Cocoon.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
andLexicalHandler
are supported, the only exception is that the setDocumentLocator event is not recorded.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description 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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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<org.apache.cocoon.xml.sax.SAXBuffer.SaxBit>
getBits()
void
ignorableWhitespace(char[] ch, int start, int length)
boolean
isEmpty()
void
processingInstruction(String target, String data)
void
recycle()
Clear this buffervoid
saxBuffer(SAXBuffer xml)
Add a another buffervoid
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()
-
-
-
Method Detail
-
skippedEntity
public void skippedEntity(String name) throws SAXException
- Specified by:
skippedEntity
in interfaceContentHandler
- Throws:
SAXException
-
setDocumentLocator
public void setDocumentLocator(Locator locator)
- Specified by:
setDocumentLocator
in interfaceContentHandler
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Throws:
SAXException
-
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
- Specified by:
processingInstruction
in interfaceContentHandler
- Throws:
SAXException
-
startDocument
public void startDocument() throws SAXException
- Specified by:
startDocument
in interfaceContentHandler
- Throws:
SAXException
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
- Specified by:
startElement
in interfaceContentHandler
- Throws:
SAXException
-
endPrefixMapping
public void endPrefixMapping(String prefix) throws SAXException
- Specified by:
endPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
characters
public void characters(char[] ch, int start, int length) throws SAXException
- Specified by:
characters
in interfaceContentHandler
- Throws:
SAXException
-
endElement
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
- Specified by:
endElement
in interfaceContentHandler
- Throws:
SAXException
-
endDocument
public void endDocument() throws SAXException
- Specified by:
endDocument
in interfaceContentHandler
- Throws:
SAXException
-
startPrefixMapping
public void startPrefixMapping(String prefix, String uri) throws SAXException
- Specified by:
startPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
endCDATA
public void endCDATA() throws SAXException
- Specified by:
endCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
comment
public void comment(char[] ch, int start, int length) throws SAXException
- Specified by:
comment
in interfaceLexicalHandler
- Throws:
SAXException
-
startEntity
public void startEntity(String name) throws SAXException
- Specified by:
startEntity
in interfaceLexicalHandler
- Throws:
SAXException
-
endDTD
public void endDTD() throws SAXException
- Specified by:
endDTD
in interfaceLexicalHandler
- Throws:
SAXException
-
startDTD
public void startDTD(String name, String publicId, String systemId) throws SAXException
- Specified by:
startDTD
in interfaceLexicalHandler
- Throws:
SAXException
-
startCDATA
public void startCDATA() throws SAXException
- Specified by:
startCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
endEntity
public void endEntity(String name) throws SAXException
- Specified by:
endEntity
in interfaceLexicalHandler
- Throws:
SAXException
-
saxBuffer
public void saxBuffer(SAXBuffer xml)
Add a another buffer
-
isEmpty
public boolean isEmpty()
- Returns:
- true if buffer is empty
-
getBits
public List<org.apache.cocoon.xml.sax.SAXBuffer.SaxBit> 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.- Throws:
SAXException
-
toString
public String toString()
-
recycle
public void recycle()
Clear this buffer
-
dump
public void dump(Writer writer) throws IOException
Dump buffer contents into the provided writer.- Throws:
IOException
-
-