KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > util > DelegatingContentHandler


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
18 /* $Id$ */
19
20 package org.apache.fop.util;
21
22 import java.io.IOException JavaDoc;
23
24 import org.xml.sax.Attributes JavaDoc;
25 import org.xml.sax.ContentHandler JavaDoc;
26 import org.xml.sax.DTDHandler JavaDoc;
27 import org.xml.sax.EntityResolver JavaDoc;
28 import org.xml.sax.ErrorHandler JavaDoc;
29 import org.xml.sax.InputSource JavaDoc;
30 import org.xml.sax.Locator JavaDoc;
31 import org.xml.sax.SAXException JavaDoc;
32 import org.xml.sax.SAXParseException JavaDoc;
33 import org.xml.sax.ext.LexicalHandler JavaDoc;
34
35 /**
36  * SAX 2 Event Handler which simply delegates all calls to another ContentHandler. Subclasses can
37  * do additional processing. This class is the passive counterpart to XMLFilterImpl.
38  * <p>
39  * The ContentHandler is the only instance that is required. All others (DTDHandler,
40  * EntityResolver, LexicalHandler and ErrorHandler) may be ignored.
41  *
42  */

43 public class DelegatingContentHandler
44         implements EntityResolver JavaDoc, DTDHandler JavaDoc, ContentHandler JavaDoc, LexicalHandler JavaDoc, ErrorHandler JavaDoc {
45
46     private ContentHandler JavaDoc delegate;
47     private EntityResolver JavaDoc entityResolver;
48     private DTDHandler JavaDoc dtdHandler;
49     private LexicalHandler JavaDoc lexicalHandler;
50     private ErrorHandler JavaDoc errorHandler;
51     
52     /**
53      * Main constructor.
54      */

55     public DelegatingContentHandler() {
56         //nop
57
}
58
59     /**
60      * @return the delegate that all ContentHandler events are forwarded to
61      */

62     public ContentHandler JavaDoc getDelegateContentHandler() {
63         return this.delegate;
64     }
65     
66     /**
67      * Sets the delegate ContentHandler that all events are forwarded to.
68      * @param handler the delegate instance
69      */

70     public void setDelegateContentHandler(ContentHandler JavaDoc handler) {
71         this.delegate = handler;
72     }
73     
74     /**
75      * Sets the delegate EntityResolver.
76      * @param resolver the delegate instance
77      */

78     public void setDelegateEntityResolver(EntityResolver JavaDoc resolver) {
79         this.entityResolver = resolver;
80     }
81     
82     /**
83      * Sets the delegate DTDHandler.
84      * @param handler the delegate instance
85      */

86     public void setDelegateDTDHandler(DTDHandler JavaDoc handler) {
87         this.dtdHandler = handler;
88     }
89     
90     /**
91      * Sets the delegate LexicalHandler.
92      * @param handler the delegate instance
93      */

94     public void setDelegateLexicalHandler(LexicalHandler JavaDoc handler) {
95         this.lexicalHandler = handler;
96     }
97     
98     /**
99      * Sets the delegate ErrorHandler.
100      * @param handler the delegate instance
101      */

102     public void setDelegateErrorHandler(ErrorHandler JavaDoc handler) {
103         this.errorHandler = handler;
104     }
105     
106     // ==== EntityResolver
107

108     /**
109      * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
110      */

111     public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId) throws SAXException JavaDoc, IOException JavaDoc {
112         if (entityResolver != null) {
113             return entityResolver.resolveEntity(publicId, systemId);
114         } else {
115             return null;
116         }
117     }
118
119     // ==== DTDHandler
120

121     /**
122      * @see org.xml.sax.DTDHandler#notationDecl(java.lang.String, java.lang.String, java.lang.String)
123      */

124     public void notationDecl(String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId) throws SAXException JavaDoc {
125         if (dtdHandler != null) {
126             dtdHandler.notationDecl(name, publicId, systemId);
127         }
128     }
129
130     /**
131      * @see org.xml.sax.DTDHandler#unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
132      */

133     public void unparsedEntityDecl(String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId,
134             String JavaDoc notationName) throws SAXException JavaDoc {
135         if (dtdHandler != null) {
136             dtdHandler.unparsedEntityDecl(name, publicId, systemId, notationName);
137         }
138     }
139
140     // ==== ContentHandler
141

142     /**
143      * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
144      */

145     public void setDocumentLocator(Locator JavaDoc locator) {
146         delegate.setDocumentLocator(locator);
147     }
148
149     /**
150      * @see org.xml.sax.ContentHandler#startDocument()
151      */

152     public void startDocument() throws SAXException JavaDoc {
153         delegate.startDocument();
154     }
155
156     /**
157      * @see org.xml.sax.ContentHandler#endDocument()
158      */

159     public void endDocument() throws SAXException JavaDoc {
160         delegate.endDocument();
161     }
162
163     /**
164      * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
165      */

166     public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri) throws SAXException JavaDoc {
167         delegate.startPrefixMapping(prefix, uri);
168     }
169
170     /**
171      * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
172      */

173     public void endPrefixMapping(String JavaDoc prefix) throws SAXException JavaDoc {
174         delegate.endPrefixMapping(prefix);
175     }
176
177     /**
178      * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
179      */

180     public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName,
181                 Attributes JavaDoc atts) throws SAXException JavaDoc {
182         delegate.startElement(uri, localName, qName, atts);
183     }
184
185     /**
186      * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
187      */

188     public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName) throws SAXException JavaDoc {
189         delegate.endElement(uri, localName, qName);
190     }
191
192     /**
193      * @see org.xml.sax.ContentHandler#characters(char[], int, int)
194      */

195     public void characters(char[] ch, int start, int length) throws SAXException JavaDoc {
196         delegate.characters(ch, start, length);
197     }
198
199     /**
200      * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
201      */

202     public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException JavaDoc {
203         delegate.ignorableWhitespace(ch, start, length);
204     }
205
206     /**
207      * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
208      */

209     public void processingInstruction(String JavaDoc target, String JavaDoc data) throws SAXException JavaDoc {
210         delegate.processingInstruction(target, data);
211     }
212
213     /**
214      * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
215      */

216     public void skippedEntity(String JavaDoc name) throws SAXException JavaDoc {
217         delegate.skippedEntity(name);
218     }
219
220     // ==== LexicalHandler
221

222     /**
223      * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String)
224      */

225     public void startDTD(String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId) throws SAXException JavaDoc {
226         if (lexicalHandler != null) {
227             lexicalHandler.startDTD(name, publicId, systemId);
228         }
229         
230     }
231
232     /**
233      * @see org.xml.sax.ext.LexicalHandler#endDTD()
234      */

235     public void endDTD() throws SAXException JavaDoc {
236         if (lexicalHandler != null) {
237             lexicalHandler.endDTD();
238         }
239     }
240
241     /**
242      * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String)
243      */

244     public void startEntity(String JavaDoc name) throws SAXException JavaDoc {
245         if (lexicalHandler != null) {
246             lexicalHandler.startEntity(name);
247         }
248     }
249
250     /**
251      * @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String)
252      */

253     public void endEntity(String JavaDoc name) throws SAXException JavaDoc {
254         if (lexicalHandler != null) {
255             lexicalHandler.endEntity(name);
256         }
257     }
258
259     /**
260      * @see org.xml.sax.ext.LexicalHandler#startCDATA()
261      */

262     public void startCDATA() throws SAXException JavaDoc {
263         if (lexicalHandler != null) {
264             lexicalHandler.startCDATA();
265         }
266     }
267
268     /**
269      * @see org.xml.sax.ext.LexicalHandler#endCDATA()
270      */

271     public void endCDATA() throws SAXException JavaDoc {
272         if (lexicalHandler != null) {
273             lexicalHandler.endCDATA();
274         }
275     }
276
277     /**
278      * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int)
279      */

280     public void comment(char[] ch, int start, int length) throws SAXException JavaDoc {
281         if (lexicalHandler != null) {
282             lexicalHandler.comment(ch, start, length);
283         }
284     }
285     
286     // ==== ErrorHandler
287

288     /**
289      * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
290      */

291     public void warning(SAXParseException JavaDoc exception) throws SAXException JavaDoc {
292         if (errorHandler != null) {
293             errorHandler.warning(exception);
294         }
295     }
296
297     /**
298      * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
299      */

300     public void error(SAXParseException JavaDoc exception) throws SAXException JavaDoc {
301         if (errorHandler != null) {
302             errorHandler.error(exception);
303         }
304     }
305
306     /**
307      * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
308      */

309     public void fatalError(SAXParseException JavaDoc exception) throws SAXException JavaDoc {
310         if (errorHandler != null) {
311             errorHandler.fatalError(exception);
312         }
313     }
314
315 }
316
Popular Tags