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
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
ConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionvoid
characters
(char[] ch, int start, int length) Writes the given characters to the given character stream.void
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) 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 Details
-
ToTextContentHandler
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 Details
-
characters
Writes the given characters to the given character stream.- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Throws:
SAXException
-
ignorableWhitespace
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
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:
-
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
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Throws:
SAXException
-
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.
-