Skip to content
Related Articles

Related Articles

ContentHandlerDecorator Class in Java

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 03 Dec, 2021

ContentHandlerDecorator class is a component of the Java package org.apache.tika.sax, ContentHandlerDecorator is the base class for the ContentHandler interface. ContentHandlerDecorator simply delegates all SAX event calls to an underlying decorated handler instance. All the child classes of ContentHandlerDecorator can provide extra decoration by overriding one or more of the SAX event methods.

Syntax:

public class ContentHandlerDecorator extends org.xml.sax.helpers.DefaultHandler

Constructors:

1. ContentHandlerDecorator(): Initialize a new instance of ContentHandlerDecorator class. This decorator forwards incoming SAX events to the dummy content handler.

ContentHandlerDecorator c = new ContentHandlerDecorator();

Note : c is the new instance of ContentHandlerDecorator class.

2. ContentHandlerDecortator(ContentHandler handler): Parameterized constructor of ContentHandlerDecorator class that creates a new instance for the given SAX event handler.

ContentHandlerDecorator c = new ContentHandlerDecorator(handler);

Note: Handler is SAX event handler to be decorated.

Methods of 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

Interfaces Implemented by ContentHandlerDecorator

  1. org.xml.sax.ContentHandler – ContentHandlerDecorator class implements ContentHandler interface. ContentHandler interface is the main interface that most SAX applications implement. ContentHandler interface is used to receive notification of the logical content of a document.
  2. org.xml.sax.DTDHandler – ContentHandlerDecorator class implements DTHHandler interface. DTDHandler interface is used to receive notification of basic DTD-related events.
  3. org.xml.sax.EntityResolver –  ContentHandlerDecorator class implements EntityResolver interface. The EntityResolver interface is used for resolving entities.
  4. org.xml.sax.ErrorHandler – ContentHandlerDecorator class implements ErrorHandler interface. ErrorHandler interface is used for SAX error handlers.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!