📜  Java中的 ContentHandlerDecorator 类

📅  最后修改于: 2022-05-13 01:55:26.102000             🧑  作者: Mango

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();

2. ContentHandlerDecortator(ContentHandler handler): ContentHandlerDecorator 类的参数化构造函数,它为给定的 SAX 事件处理程序创建一个新实例。

ContentHandlerDecorator c = new ContentHandlerDecorator(handler);

ContentHandlerDecorator 的方法

S.NOMethod                                Description                                                               Return Type           
1setContentHandler(ContentHandler handler)setContentHandler(ContentHandler handler) method is used to set the content handler.void
2handleException(SAXException exception)handleException method handles all the exceptions which will be thrown by methods of ContentHandlerDecorator class.void
3characters(char[] ch, int start, int length) The characters method is used to receive notification of character data inside an element.void
4endDocument()endDocument method is used to receive notification of the end of the document.void
5toString() toString method is used to return a string representation of the object.String
6endElement(String uri, String localName, String name) endElement method is used to receive notification of the end of an element.void
7endPrefixMapping(String prefix)endPrefixMapping method is used to receive notification of the end of a Namespace mapping.void
8ignorableWhitespace(char[] ch, int start, int length) ignorableWhitespace method is used to receive notification of ignorable whitespace in element content.void
9processingInstruction(String target, String data) processingInstruction method is used to receive notification of a processing instruction.void
10setDocumentLocator(Locator locator) setDocumentLocator method is used to receive a Locator object for document events.void
11skippedEntity(String name) skippedEntity method is used to receive notification of a skipped entity.void
12startDocument() startDocument method is used to receive notification of the beginning of the document.void
13startElement(String uri, String localName, String name, Attributes atts) startElement method is used to receive notification of the start of an element.void
14startPrefixMapping(String prefix, String uri) startPrefixMapping method is used to receive notification of the start of a Namespace mapping.void

ContentHandlerDecorator 实现的接口

  1. org.xml.sax.ContentHandler – ContentHandlerDecorator 类实现 ContentHandler 接口。 ContentHandler 接口是大多数 SAX 应用程序实现的主要接口。 ContentHandler 接口用于接收文档逻辑内容的通知。
  2. org.xml.sax.DTDHandler – ContentHandlerDecorator 类实现 DTHHandler 接口。 DTDHandler 接口用于接收基本 DTD 相关事件的通知。
  3. org.xml.sax.EntityResolver – ContentHandlerDecorator 类实现 EntityResolver 接口。 EntityResolver 接口用于解析实体。
  4. org.xml.sax.ErrorHandler – ContentHandlerDecorator 类实现 ErrorHandler 接口。 ErrorHandler 接口用于 SAX 错误处理程序。