com.aliasi.xml
Class TextAccumulatorHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by com.aliasi.xml.TextAccumulatorHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class TextAccumulatorHandler
extends DefaultHandler

A TextAccumulatorHandler simply accumulates all text content events into a single string buffer. The buffer is reset with each start document event, but is never freed entirely from memory.

Since:
LingPipe2.0
Version:
3.6
Author:
Bob Carpenter

Constructor Summary
TextAccumulatorHandler()
          Construct a text accumulator handler.
TextAccumulatorHandler(int minBufLength)
          Construct a text accumulator handler with the specified initial buffer length.
 
Method Summary
 void characters(char[] cs, int start, int length)
          Adds the specified character slice to the string buffer.
 String getText()
          Returns the text thus far accumulated.
 void reset()
          Resets the underlying string buffer to the empty state by assigning it to a new buffer of the specified minimum length.
 void startDocument()
          Resets the string buffer.
 String toString()
          A convenience implementation returning the same value as getText(), namely the text thus far accumulated.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endElement, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startElement, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextAccumulatorHandler

public TextAccumulatorHandler()
Construct a text accumulator handler.


TextAccumulatorHandler

public TextAccumulatorHandler(int minBufLength)
Construct a text accumulator handler with the specified initial buffer length.

Parameters:
minBufLength - Minimum buffer length to assign to string buffer.
Method Detail

reset

public void reset()
Resets the underlying string buffer to the empty state by assigning it to a new buffer of the specified minimum length.


startDocument

public void startDocument()
Resets the string buffer.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DefaultHandler

characters

public void characters(char[] cs,
                       int start,
                       int length)
Adds the specified character slice to the string buffer.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Parameters:
cs - Characters underlying slice.
start - Index of first character in slice.
length - Number of characters in slice.

getText

public String getText()
Returns the text thus far accumulated.

Returns:
The text thus far accumulated.

toString

public String toString()
A convenience implementation returning the same value as getText(), namely the text thus far accumulated.

Overrides:
toString in class Object
Returns:
The text thus far accumulated.