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  
24  /**
25   * Content handler decorator that forwards the received SAX events to two
26   * underlying content handlers.
27   */
28  public class TeeContentHandler extends ContentHandlerDecorator {
29  
30      private final ContentHandler branch;
31  
32      public TeeContentHandler(ContentHandler handler, ContentHandler branch) {
33          super(handler);
34          this.branch = branch;
35      }
36  
37      public void startPrefixMapping(String prefix, String uri)
38              throws SAXException {
39          super.startPrefixMapping(prefix, uri);
40          branch.startPrefixMapping(prefix, uri);
41      }
42  
43      public void endPrefixMapping(String prefix) throws SAXException {
44          super.endPrefixMapping(prefix);
45          branch.endPrefixMapping(prefix);
46      }
47  
48      public void processingInstruction(String target, String data)
49              throws SAXException {
50          super.processingInstruction(target, data);
51          branch.processingInstruction(target, data);
52      }
53  
54      public void setDocumentLocator(Locator locator) {
55          super.setDocumentLocator(locator);
56          branch.setDocumentLocator(locator);
57      }
58  
59      public void startDocument() throws SAXException {
60          super.startDocument();
61          branch.startDocument();
62      }
63  
64      public void endDocument() throws SAXException {
65          super.endDocument();
66          branch.endDocument();
67      }
68  
69      public void startElement(String uri, String localName, String name,
70              Attributes atts) throws SAXException {
71          super.startElement(uri, localName, name, atts);
72          branch.startElement(uri, localName, name, atts);
73      }
74  
75      public void endElement(String uri, String localName, String name)
76              throws SAXException {
77          super.endElement(uri, localName, name);
78          branch.endElement(uri, localName, name);
79      }
80  
81      public void characters(char[] ch, int start, int length)
82              throws SAXException {
83          super.characters(ch, start, length);
84          branch.characters(ch, start, length);
85      }
86  
87      public void ignorableWhitespace(char[] ch, int start, int length)
88              throws SAXException {
89          super.ignorableWhitespace(ch, start, length);
90          branch.ignorableWhitespace(ch, start, length);
91      }
92  
93      public void skippedEntity(String name) throws SAXException {
94          super.skippedEntity(name);
95          branch.skippedEntity(name);
96      }
97  
98  }