Package org.apache.tika.sax
Class ToTextContentHandler
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.apache.tika.sax.ToTextContentHandler
-
- All Implemented Interfaces:
ContentHandler,DTDHandler,EntityResolver,ErrorHandler
- Direct Known Subclasses:
ToXMLContentHandler
public class ToTextContentHandler extends DefaultHandler
SAX event handler that writes all character content out to a character stream. No escaping or other transformations are made on the character content.As of Tika 1.20, this handler ignores content within <script> and <style> tags.
- Since:
- Apache Tika 0.10
-
-
Constructor Summary
Constructors Constructor Description ToTextContentHandler()Creates a content handler that writes character events to an internal string buffer.ToTextContentHandler(OutputStream stream, String encoding)Creates a content handler that writes character events to the given output stream using the given encoding.ToTextContentHandler(Writer writer)Creates a content handler that writes character events to the given writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcharacters(char[] ch, int start, int length)Writes the given characters to the given character stream.voidendDocument()Flushes the character stream so that no characters are forgotten in internal buffers.voidendElement(String uri, String localName, String qName)voidignorableWhitespace(char[] ch, int start, int length)Writes the given ignorable characters to the given character stream.voidstartElement(String uri, String localName, String qName, Attributes atts)StringtoString()Returns the contents of the internal string buffer where all the received characters have been collected.-
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
-
-
-
-
Constructor Detail
-
ToTextContentHandler
public ToTextContentHandler(Writer writer)
Creates a content handler that writes character events to the given writer.- Parameters:
writer- writer
-
ToTextContentHandler
public ToTextContentHandler(OutputStream stream, String encoding) throws UnsupportedEncodingException
Creates a content handler that writes character events to the given output stream using the given encoding.- Parameters:
stream- output streamencoding- output encoding- Throws:
UnsupportedEncodingException- if the encoding is unsupported
-
ToTextContentHandler
public ToTextContentHandler()
Creates a content handler that writes character events to an internal string buffer. Use thetoString()method to access the collected character content.
-
-
Method Detail
-
characters
public void characters(char[] ch, int start, int length) throws SAXExceptionWrites the given characters to the given character stream.- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler- Throws:
SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXExceptionWrites the given ignorable characters to the given character stream. The default implementation simply forwards the call to thecharacters(char[], int, int)method.- Specified by:
ignorableWhitespacein interfaceContentHandler- Overrides:
ignorableWhitespacein classDefaultHandler- Throws:
SAXException
-
endDocument
public void endDocument() throws SAXExceptionFlushes the character stream so that no characters are forgotten in internal buffers.- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classDefaultHandler- Throws:
SAXException- if the stream can not be flushed- See Also:
- TIKA-179
-
startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
- Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- Throws:
SAXException
-
endElement
public void endElement(String uri, String localName, String qName) throws SAXException
- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXException
-
toString
public String toString()
Returns the contents of the internal string buffer where all the received characters have been collected. Only works when this object was constructed using the empty default constructor or by passing aStringWriterto the other constructor.
-
-