KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > core > util > xml > sax > FilterContentHandler


1 package org.mr.core.util.xml.sax;
2
3 import org.xml.sax.*;
4 import org.xml.sax.ext.DeclHandler JavaDoc;
5 import org.xml.sax.ext.LexicalHandler JavaDoc;
6
7 import java.io.IOException JavaDoc;
8 import java.io.Serializable JavaDoc;
9
10 /*
11  * Copyright 2002 by
12  * <a HREF="http://www.coridan.com">Coridan</a>
13  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
14  *
15  * The contents of this file are subject to the Mozilla Public License Version
16  * 1.1 (the "License"); you may not use this file except in compliance with the
17  * License. You may obtain a copy of the License at
18  * http://www.mozilla.org/MPL/
19  *
20  * Software distributed under the License is distributed on an "AS IS" basis,
21  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
22  * for the specific language governing rights and limitations under the
23  * License.
24  *
25  * The Original Code is "MantaRay" (TM).
26  *
27  * The Initial Developer of the Original Code is Coridan.
28  * Portions created by the Initial Developer are Copyright (C) 2006
29  * Coridan Inc. All Rights Reserved.
30  *
31  * Contributor(s): all the names of the contributors are added in the source
32  * code where applicable.
33  *
34  * Alternatively, the contents of this file may be used under the terms of the
35  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
36  * provisions of LGPL are applicable instead of those above. If you wish to
37  * allow use of your version of this file only under the terms of the LGPL
38  * License and not to allow others to use your version of this file under
39  * the MPL, indicate your decision by deleting the provisions above and
40  * replace them with the notice and other provisions required by the LGPL.
41  * If you do not delete the provisions above, a recipient may use your version
42  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
43  
44  *
45  * This library is free software; you can redistribute it and/or modify it
46  * under the terms of the MPL as stated above or under the terms of the GNU
47  * Lesser General Public License as published by the Free Software Foundation;
48  * either version 2.1 of the License, or any later version.
49  *
50  * This library is distributed in the hope that it will be useful, but WITHOUT
51  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
52  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
53  * License for more details.
54  */

55
56  /**
57  * User: Moti Tal
58  * Date: Feb 20, 2005
59  * Time: 2:51:32 PM
60  *
61  * This class implements all the regular and...
62  */

63 public class FilterContentHandler
64         implements ContentHandler, EntityResolver, DTDHandler, ErrorHandler, LexicalHandler JavaDoc, DeclHandler JavaDoc, Serializable JavaDoc {
65
66     private static final SinkContentHandler SINK_HANDLER = new SinkContentHandler();
67
68     private final ContentHandler m_handler;
69     private final DTDHandler m_dtdHandler;
70     private final ErrorHandler m_errorHandler;
71     private final EntityResolver m_entityResolver;
72     private final LexicalHandler JavaDoc m_lexicalHandler;
73     private final DeclHandler JavaDoc m_declHandler;
74
75     /**
76      * Make sure the handler implements all SAX interfaces. If not wrap it on a FilterContentHandler
77      * @param i_handler a ContentHandler
78      * @return a ContentHandler that also implements {@link EntityResolver}, {@link DTDHandler},
79      * {@link ErrorHandler}, {@link LexicalHandler} and {@link DeclHandler}.
80      */

81     public static ContentHandler ensureFullHandler(ContentHandler i_handler) {
82         if (i_handler instanceof DTDHandler && i_handler instanceof ErrorHandler &&
83                 i_handler instanceof EntityResolver && i_handler instanceof LexicalHandler JavaDoc &&
84                 i_handler instanceof DeclHandler JavaDoc) {
85             return i_handler;
86         }
87         return new FilterContentHandler(i_handler);
88     }
89
90     public ContentHandler getContentHandler() {
91         return m_handler;
92     }
93
94     public FilterContentHandler(ContentHandler i_handler) {
95         m_handler = i_handler;
96         m_dtdHandler = (i_handler instanceof DTDHandler)? (DTDHandler)i_handler : SINK_HANDLER;
97         m_errorHandler = (i_handler instanceof ErrorHandler)? (ErrorHandler)i_handler : SINK_HANDLER;
98         m_entityResolver = (i_handler instanceof EntityResolver)? (EntityResolver)i_handler : SINK_HANDLER;
99         m_lexicalHandler = (i_handler instanceof LexicalHandler JavaDoc)? (LexicalHandler JavaDoc)i_handler : SINK_HANDLER;
100         m_declHandler = (i_handler instanceof DeclHandler JavaDoc)? (DeclHandler JavaDoc)i_handler : SINK_HANDLER;
101     }
102
103     public void setDocumentLocator(Locator i_locator) {
104         m_handler.setDocumentLocator(i_locator);
105     }
106
107     public void startDocument() throws SAXException {
108         m_handler.startDocument();
109     }
110
111     public void endDocument() throws SAXException {
112         m_handler.endDocument();
113     }
114
115     public void startPrefixMapping(String JavaDoc i_prefix, String JavaDoc i_uri) throws SAXException {
116         m_handler.startPrefixMapping(i_prefix, i_uri);
117     }
118
119     public void endPrefixMapping(String JavaDoc i_prefix) throws SAXException {
120         m_handler.endPrefixMapping(i_prefix);
121     }
122
123     public void startElement(String JavaDoc i_namespaceURI, String JavaDoc i_localName, String JavaDoc i_qName, Attributes i_atts) throws SAXException {
124         m_handler.startElement(i_namespaceURI, i_localName, i_qName, i_atts);
125     }
126
127     public void endElement(String JavaDoc i_namespaceURI, String JavaDoc i_localName, String JavaDoc i_qName) throws SAXException {
128         m_handler.endElement(i_namespaceURI, i_localName, i_qName);
129     }
130
131     public void ignorableWhitespace(char[] i_chars, int i_start, int i_length) throws SAXException {
132         m_handler.ignorableWhitespace(i_chars, i_start, i_length);
133     }
134
135     public void processingInstruction(String JavaDoc i_target, String JavaDoc i_data) throws SAXException {
136         m_handler.processingInstruction(i_target, i_data);
137     }
138
139     public void skippedEntity(String JavaDoc i_name) throws SAXException {
140         m_handler.skippedEntity(i_name);
141     }
142
143     public void characters(char[] i_chars, int i_start, int i_length) throws SAXException {
144         m_handler.characters(i_chars, i_start, i_length);
145     }
146
147     public void notationDecl(String JavaDoc s, String JavaDoc s1, String JavaDoc s2) throws SAXException {
148         m_dtdHandler.notationDecl(s, s1, s2);
149     }
150
151     public void unparsedEntityDecl(String JavaDoc s, String JavaDoc s1, String JavaDoc s2, String JavaDoc s3) throws SAXException {
152         m_dtdHandler.unparsedEntityDecl(s, s1, s2, s3);
153     }
154
155     public void warning(SAXParseException e) throws SAXException {
156         m_errorHandler.warning(e);
157     }
158
159     public void error(SAXParseException e) throws SAXException {
160         m_errorHandler.error(e);
161     }
162
163     public void fatalError(SAXParseException e) throws SAXException {
164         m_errorHandler.fatalError(e);
165     }
166
167     public InputSource resolveEntity(String JavaDoc s, String JavaDoc s1) throws SAXException, IOException JavaDoc {
168         return m_entityResolver.resolveEntity(s, s1);
169     }
170
171     public void startDTD(String JavaDoc s, String JavaDoc s1, String JavaDoc s2) throws SAXException {
172         m_lexicalHandler.startDTD(s, s1, s2);
173     }
174
175     public void endDTD() throws SAXException {
176         m_lexicalHandler.endDTD();
177     }
178
179     public void startEntity(String JavaDoc s) throws SAXException {
180         m_lexicalHandler.startEntity(s);
181     }
182
183     public void endEntity(String JavaDoc s) throws SAXException {
184         m_lexicalHandler.endEntity(s);
185     }
186
187     public void startCDATA() throws SAXException {
188         m_lexicalHandler.startCDATA();
189     }
190
191     public void endCDATA() throws SAXException {
192         m_lexicalHandler.endCDATA();
193     }
194
195     public void comment(char[] i_chars, int i, int i1) throws SAXException {
196         m_lexicalHandler.comment(i_chars, i, i1);
197     }
198
199     public void elementDecl(String JavaDoc s, String JavaDoc s1) throws SAXException {
200         m_declHandler.elementDecl(s, s1);
201     }
202
203     public void attributeDecl(String JavaDoc s, String JavaDoc s1, String JavaDoc s2, String JavaDoc s3, String JavaDoc s4) throws SAXException {
204         m_declHandler.attributeDecl(s, s1, s2, s3, s4);
205     }
206
207     public void internalEntityDecl(String JavaDoc s, String JavaDoc s1) throws SAXException {
208         m_declHandler.internalEntityDecl(s, s1);
209     }
210
211     public void externalEntityDecl(String JavaDoc s, String JavaDoc s1, String JavaDoc s2) throws SAXException {
212         m_declHandler.externalEntityDecl(s, s1, s2);
213     }
214 }
215
Popular Tags