com.aliasi.xml
Class GroupCharactersFilter

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

public class GroupCharactersFilter
extends SAXFilterHandler

Provides a SAX filter that groups sequential calls to characters(char[],int,int) into a single call with all of the content concatenated. A flag may be supplied at construction time that will cause all character content that is all whitespace, as defined by Strings.allWhitespace(char[],int,int) to be ignored.

Since:
LingPipe1.0
Version:
1.0
Author:
Bob Carpenter

Field Summary
 
Fields inherited from class com.aliasi.xml.SAXFilterHandler
mHandler
 
Fields inherited from class com.aliasi.xml.SimpleElementHandler
CDATA_ATTS_TYPE, EMPTY_ATTS, NO_OP_DEFAULT_HANDLER
 
Constructor Summary
GroupCharactersFilter(DefaultHandler handler)
          Construct a character grouping filter that delegates events to the specified handler.
GroupCharactersFilter(DefaultHandler handler, boolean removeWhitespace)
          Construct a character grouping filter without a specified handler to which to delegate events.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Adds the characters to the character accumulator.
 void endDocument()
          End the document, delegating the call to the contained handler, after calling characters(char[],int,int) on any accumulated characters.
 void endElement(String namespaceURI, String localName, String qName)
          Ends the specified element, delegating the SAX event to the contained handler, after calling characters(char[],int,int) to handle any accumulated characters.
 void startDocument()
          Start the document, delegating the call to the contained handler.
 void startElement(String namespaceURI, String localName, String qName, Attributes atts)
          Start the specified element, delegating the SAX event to the contained handler, after calling characters(char[],int,int) to handle any accumulated characters.
 
Methods inherited from class com.aliasi.xml.SAXFilterHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, setHandler, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class com.aliasi.xml.SimpleElementHandler
addSimpleAttribute, characters, characters, characters, characters, createAttributes, createAttributes, createAttributes, createAttributes, createAttributes, createAttributes, endSimpleElement, endSimpleElement, startEndSimpleElement, startEndSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GroupCharactersFilter

public GroupCharactersFilter(DefaultHandler handler)
Construct a character grouping filter that delegates events to the specified handler. The handler may be reset with SAXFilterHandler.setHandler(DefaultHandler).

Parameters:
handler - Handler to which events are delegated.

GroupCharactersFilter

public GroupCharactersFilter(DefaultHandler handler,
                             boolean removeWhitespace)
Construct a character grouping filter without a specified handler to which to delegate events. Set the handler with SAXFilterHandler.setHandler(DefaultHandler).

Method Detail

startDocument

public void startDocument()
                   throws SAXException
Start the document, delegating the call to the contained handler.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class SAXFilterHandler
Throws:
SAXException - If there is an exception raised by the contained handler.

endDocument

public void endDocument()
                 throws SAXException
End the document, delegating the call to the contained handler, after calling characters(char[],int,int) on any accumulated characters.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class SAXFilterHandler
Throws:
SAXException - If there is an exception raised by the contained handler.

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Start the specified element, delegating the SAX event to the contained handler, after calling characters(char[],int,int) to handle any accumulated characters.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class SAXFilterHandler
Parameters:
namespaceURI - The URI of the namespace for this element.
localName - The local name (without prefix) for this element.
qName - The qualified name (with prefix, if any) for this element.
atts - The attributes for this element.
Throws:
SAXException - If there is an exception raised by the contained handler.

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
                throws SAXException
Ends the specified element, delegating the SAX event to the contained handler, after calling characters(char[],int,int) to handle any accumulated characters.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class SAXFilterHandler
Parameters:
namespaceURI - The URI of the namespace for this element.
localName - The local name (without prefix) for this element.
qName - The qualified name (with prefix, if any) for this element.
Throws:
SAXException - If there is an exception raised by the contained handler.

characters

public final void characters(char[] ch,
                             int start,
                             int length)
                      throws SAXException
Adds the characters to the character accumulator.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class SAXFilterHandler
Parameters:
ch - Array of characters to add to accumulator.
start - First character to accumulate.
length - Number of characters to accumulate.
Throws:
SAXException - if the contained hanlder throws a SAX exception.