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)
Deprecated.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 void
characters(char[] ch, int start, int length)
Writes the given characters to the given character stream.void
endDocument()
Flushes the character stream so that no characters are forgotten in internal buffers.void
endElement(String uri, String localName, String qName)
void
ignorableWhitespace(char[] ch, int start, int length)
Writes the given ignorable characters to the given character stream.void
startElement(String uri, String localName, String qName, Attributes atts)
String
toString()
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)
Deprecated.Creates a content handler that writes character events to the given output stream using the platform default encoding.- Parameters:
stream
- output stream
-
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 SAXException
Writes the given characters to the given character stream.- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Throws:
SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
Writes the given ignorable characters to the given character stream. The default implementation simply forwards the call to thecharacters(char[], int, int)
method.- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Overrides:
ignorableWhitespace
in classDefaultHandler
- Throws:
SAXException
-
endDocument
public void endDocument() throws SAXException
Flushes the character stream so that no characters are forgotten in internal buffers.- Specified by:
endDocument
in interfaceContentHandler
- Overrides:
endDocument
in 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:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
-
endElement
public void endElement(String uri, String localName, String qName) throws SAXException
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in 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 aStringWriter
to the other constructor.
-
-