Java中的 ContentHandlerDecorator 类
ContentHandlerDecorator类是Java包org.apache.tika.sax的一个组件,ContentHandlerDecorator是ContentHandler接口的基类。 ContentHandlerDecorator 只是将所有 SAX 事件调用委托给底层装饰处理程序实例。 ContentHandlerDecorator 的所有子类都可以通过覆盖一个或多个 SAX 事件方法来提供额外的装饰。
句法:
public class ContentHandlerDecorator extends org.xml.sax.helpers.DefaultHandler
构造函数:
1、ContentHandlerDecorator():初始化一个ContentHandlerDecorator类的新实例。此装饰器将传入的 SAX 事件转发给虚拟内容处理程序。
ContentHandlerDecorator c = new ContentHandlerDecorator();
Note : c is the new instance of ContentHandlerDecorator class.
2. ContentHandlerDecortator(ContentHandler handler): ContentHandlerDecorator 类的参数化构造函数,它为给定的 SAX 事件处理程序创建一个新实例。
ContentHandlerDecorator c = new ContentHandlerDecorator(handler);
Note: Handler is SAX event handler to be decorated.
ContentHandlerDecorator 的方法
S.NO | Method | Description | Return Type |
---|---|---|---|
1 | setContentHandler(ContentHandler handler) | setContentHandler(ContentHandler handler) method is used to set the content handler. | void |
2 | handleException(SAXException exception) | handleException method handles all the exceptions which will be thrown by methods of ContentHandlerDecorator class. | void |
3 | characters(char[] ch, int start, int length) | The characters method is used to receive notification of character data inside an element. | void |
4 | endDocument() | endDocument method is used to receive notification of the end of the document. | void |
5 | toString() | toString method is used to return a string representation of the object. | String |
6 | endElement(String uri, String localName, String name) | endElement method is used to receive notification of the end of an element. | void |
7 | endPrefixMapping(String prefix) | endPrefixMapping method is used to receive notification of the end of a Namespace mapping. | void |
8 | ignorableWhitespace(char[] ch, int start, int length) | ignorableWhitespace method is used to receive notification of ignorable whitespace in element content. | void |
9 | processingInstruction(String target, String data) | processingInstruction method is used to receive notification of a processing instruction. | void |
10 | setDocumentLocator(Locator locator) | setDocumentLocator method is used to receive a Locator object for document events. | void |
11 | skippedEntity(String name) | skippedEntity method is used to receive notification of a skipped entity. | void |
12 | startDocument() | startDocument method is used to receive notification of the beginning of the document. | void |
13 | startElement(String uri, String localName, String name, Attributes atts) | startElement method is used to receive notification of the start of an element. | void |
14 | startPrefixMapping(String prefix, String uri) | startPrefixMapping method is used to receive notification of the start of a Namespace mapping. | void |
ContentHandlerDecorator 实现的接口
- org.xml.sax.ContentHandler – ContentHandlerDecorator 类实现 ContentHandler 接口。 ContentHandler 接口是大多数 SAX 应用程序实现的主要接口。 ContentHandler 接口用于接收文档逻辑内容的通知。
- org.xml.sax.DTDHandler – ContentHandlerDecorator 类实现 DTHHandler 接口。 DTDHandler 接口用于接收基本 DTD 相关事件的通知。
- org.xml.sax.EntityResolver – ContentHandlerDecorator 类实现 EntityResolver 接口。 EntityResolver 接口用于解析实体。
- org.xml.sax.ErrorHandler – ContentHandlerDecorator 类实现 ErrorHandler 接口。 ErrorHandler 接口用于 SAX 错误处理程序。