1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
27
28
29
30
31 public class ContentHandlerDecorator extends DefaultHandler {
32
33
34
35
36 private final ContentHandler handler;
37
38
39
40
41
42
43 public ContentHandlerDecorator(ContentHandler handler) {
44 this.handler = handler;
45 }
46
47 @Override
48 public void startPrefixMapping(String prefix, String uri)
49 throws SAXException {
50 try {
51 handler.startPrefixMapping(prefix, uri);
52 } catch (SAXException e) {
53 handleException(e);
54 }
55 }
56
57 @Override
58 public void endPrefixMapping(String prefix) throws SAXException {
59 try {
60 handler.endPrefixMapping(prefix);
61 } catch (SAXException e) {
62 handleException(e);
63 }
64 }
65
66 @Override
67 public void processingInstruction(String target, String data)
68 throws SAXException {
69 try {
70 handler.processingInstruction(target, data);
71 } catch (SAXException e) {
72 handleException(e);
73 }
74 }
75
76 @Override
77 public void setDocumentLocator(Locator locator) {
78 handler.setDocumentLocator(locator);
79 }
80
81 @Override
82 public void startDocument() throws SAXException {
83 try {
84 handler.startDocument();
85 } catch (SAXException e) {
86 handleException(e);
87 }
88 }
89
90 @Override
91 public void endDocument() throws SAXException {
92 try {
93 handler.endDocument();
94 } catch (SAXException e) {
95 handleException(e);
96 }
97 }
98
99 @Override
100 public void startElement(
101 String uri, String localName, String name, Attributes atts)
102 throws SAXException {
103 try {
104 handler.startElement(uri, localName, name, atts);
105 } catch (SAXException e) {
106 handleException(e);
107 }
108 }
109
110 @Override
111 public void endElement(String uri, String localName, String name)
112 throws SAXException {
113 try {
114 handler.endElement(uri, localName, name);
115 } catch (SAXException e) {
116 handleException(e);
117 }
118 }
119
120 @Override
121 public void characters(char[] ch, int start, int length)
122 throws SAXException {
123 try {
124 handler.characters(ch, start, length);
125 } catch (SAXException e) {
126 handleException(e);
127 }
128 }
129
130 @Override
131 public void ignorableWhitespace(char[] ch, int start, int length)
132 throws SAXException {
133 try {
134 handler.ignorableWhitespace(ch, start, length);
135 } catch (SAXException e) {
136 handleException(e);
137 }
138 }
139
140 @Override
141 public void skippedEntity(String name) throws SAXException {
142 try {
143 handler.skippedEntity(name);
144 } catch (SAXException e) {
145 handleException(e);
146 }
147 }
148
149 @Override
150 public String toString() {
151 return handler.toString();
152 }
153
154
155
156
157
158
159
160
161
162
163 protected void handleException(SAXException exception) throws SAXException {
164 throw exception;
165 }
166
167 }