View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.tika.sax;
18  
19  import org.xml.sax.Attributes;
20  import org.xml.sax.ContentHandler;
21  import org.xml.sax.Locator;
22  import org.xml.sax.SAXException;
23  import org.xml.sax.helpers.DefaultHandler;
24  
25  /**
26   * Decorator base class for the {@link ContentHandler} interface. This class
27   * simply delegates all SAX events calls to an underlying decorated handler
28   * instance. Subclasses can provide extra decoration by overriding one or more
29   * of the SAX event methods.
30   */
31  public class ContentHandlerDecorator extends DefaultHandler {
32  
33      /**
34       * Decorated SAX event handler.
35       */
36      private final ContentHandler handler;
37  
38      /**
39       * Creates a decorator for the given SAX event handler.
40       *
41       * @param handler SAX event handler to be decorated
42       */
43      public ContentHandlerDecorator(ContentHandler handler) {
44          this.handler = handler;
45      }
46  
47      public void startPrefixMapping(String prefix, String uri)
48              throws SAXException {
49          handler.startPrefixMapping(prefix, uri);
50      }
51  
52      public void endPrefixMapping(String prefix) throws SAXException {
53          handler.endPrefixMapping(prefix);
54      }
55  
56      public void processingInstruction(String target, String data)
57              throws SAXException {
58          handler.processingInstruction(target, data);
59      }
60  
61      public void setDocumentLocator(Locator locator) {
62          handler.setDocumentLocator(locator);
63      }
64  
65      public void startDocument() throws SAXException {
66          handler.startDocument();
67      }
68  
69      public void endDocument() throws SAXException {
70          handler.endDocument();
71      }
72  
73      public void startElement(String uri, String localName, String name,
74              Attributes atts) throws SAXException {
75          handler.startElement(uri, localName, name, atts);
76      }
77  
78      public void endElement(String uri, String localName, String name)
79              throws SAXException {
80          handler.endElement(uri, localName, name);
81      }
82  
83      public void characters(char[] ch, int start, int length)
84              throws SAXException {
85          handler.characters(ch, start, length);
86      }
87  
88      public void ignorableWhitespace(char[] ch, int start, int length)
89              throws SAXException {
90          handler.ignorableWhitespace(ch, start, length);
91      }
92  
93      public void skippedEntity(String name) throws SAXException {
94          handler.skippedEntity(name);
95      }
96  
97      public String toString() {
98          return handler.toString();
99      }
100 
101 }