KickJava   Java API By Example, From Geeks To Geeks.

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


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

57
58  /**
59  * User: Moti Tal
60  * Date: Feb 20, 2005
61  * Time: 2:49:41 PM
62  *
63  * Fire SAX events for multiple destinations.
64  */

65 public class MultiplexerContentHandler implements EntityResolver, ContentHandler, DTDHandler, ErrorHandler, LexicalHandler JavaDoc, DeclHandler JavaDoc, Serializable JavaDoc {
66     private ArrayList JavaDoc m_handlers = new ArrayList JavaDoc();
67
68     public MultiplexerContentHandler add(ContentHandler i_handler) {
69         m_handlers.add(org.mr.core.util.xml.sax.FilterContentHandler.ensureFullHandler(i_handler));
70         return this;
71     }
72
73     public void setDocumentLocator(Locator i_locator) {
74         Iterator JavaDoc iter = m_handlers.iterator();
75         while (iter.hasNext()) {
76             ((ContentHandler) iter.next()).setDocumentLocator(i_locator);
77         }
78     }
79
80     public void startDocument() throws SAXException {
81         Iterator JavaDoc iter = m_handlers.iterator();
82         while (iter.hasNext()) {
83             ((ContentHandler) iter.next()).startDocument();
84         }
85     }
86
87     public void endDocument() throws SAXException {
88         Iterator JavaDoc iter = m_handlers.iterator();
89         while (iter.hasNext()) {
90             ((ContentHandler) iter.next()).endDocument();
91         }
92     }
93
94     public void startPrefixMapping(String JavaDoc s, String JavaDoc s1) throws SAXException {
95         Iterator JavaDoc iter = m_handlers.iterator();
96         while (iter.hasNext()) {
97             ((ContentHandler) iter.next()).startPrefixMapping(s, s1);
98         }
99     }
100
101     public void endPrefixMapping(String JavaDoc s) throws SAXException {
102         Iterator JavaDoc iter = m_handlers.iterator();
103         while (iter.hasNext()) {
104             ((ContentHandler) iter.next()).endPrefixMapping(s);
105         }
106     }
107
108     public void startElement(String JavaDoc s, String JavaDoc s1, String JavaDoc s2, Attributes i_attributes) throws SAXException {
109         Iterator JavaDoc iter = m_handlers.iterator();
110         while (iter.hasNext()) {
111             ((ContentHandler) iter.next()).startElement(s, s1, s2, i_attributes);
112         }
113     }
114
115     public void endElement(String JavaDoc s, String JavaDoc s1, String JavaDoc s2) throws SAXException {
116         Iterator JavaDoc iter = m_handlers.iterator();
117         while (iter.hasNext()) {
118             ((ContentHandler) iter.next()).endElement(s, s1, s2);
119         }
120     }
121
122     public void characters(char[] i_chars, int i, int i1) throws SAXException {
123         Iterator JavaDoc iter = m_handlers.iterator();
124         while (iter.hasNext()) {
125             ((ContentHandler) iter.next()).characters(i_chars, i, i1);
126         }
127     }
128
129     public void ignorableWhitespace(char[] i_chars, int i, int i1) throws SAXException {
130         Iterator JavaDoc iter = m_handlers.iterator();
131         while (iter.hasNext()) {
132             ((ContentHandler) iter.next()).ignorableWhitespace(i_chars, i, i1);
133         }
134     }
135
136     public void processingInstruction(String JavaDoc s, String JavaDoc s1) throws SAXException {
137         Iterator JavaDoc iter = m_handlers.iterator();
138         while (iter.hasNext()) {
139             ((ContentHandler) iter.next()).processingInstruction(s, s1);
140         }
141     }
142
143     public void skippedEntity(String JavaDoc s) throws SAXException {
144         Iterator JavaDoc iter = m_handlers.iterator();
145         while (iter.hasNext()) {
146             ((ContentHandler) iter.next()).skippedEntity(s);
147         }
148     }
149
150     public InputSource resolveEntity(String JavaDoc s, String JavaDoc s1) throws SAXException, IOException JavaDoc {
151         Iterator JavaDoc iter = m_handlers.iterator();
152         InputSource source = null;
153         while (iter.hasNext() && source == null) {
154             source = ((EntityResolver) iter.next()).resolveEntity(s, s1);
155         }
156         return source;
157     }
158
159     public void notationDecl(String JavaDoc s, String JavaDoc s1, String JavaDoc s2) throws SAXException {
160         Iterator JavaDoc iter = m_handlers.iterator();
161         while (iter.hasNext()) {
162             ((DTDHandler) iter.next()).notationDecl(s, s1, s2);
163         }
164     }
165
166     public void unparsedEntityDecl(String JavaDoc s, String JavaDoc s1, String JavaDoc s2, String JavaDoc s3) throws SAXException {
167         Iterator JavaDoc iter = m_handlers.iterator();
168         while (iter.hasNext()) {
169             ((DTDHandler) iter.next()).unparsedEntityDecl(s, s1, s2, s3);
170         }
171     }
172
173     public void error(SAXParseException e) throws SAXException {
174         Iterator JavaDoc iter = m_handlers.iterator();
175         while (iter.hasNext()) {
176             ((ErrorHandler) iter.next()).error(e);
177         }
178     }
179
180     public void fatalError(SAXParseException e) throws SAXException {
181         Iterator JavaDoc iter = m_handlers.iterator();
182         while (iter.hasNext()) {
183             ((ErrorHandler) iter.next()).fatalError(e);
184         }
185     }
186
187     public void warning(SAXParseException e) throws SAXException {
188         Iterator JavaDoc iter = m_handlers.iterator();
189         while (iter.hasNext()) {
190             ((ErrorHandler) iter.next()).warning(e);
191         }
192     }
193
194     public void startDTD(String JavaDoc s, String JavaDoc s1, String JavaDoc s2) throws SAXException {
195         Iterator JavaDoc iter = m_handlers.iterator();
196         while (iter.hasNext()) {
197             ((LexicalHandler JavaDoc) iter.next()).startDTD(s, s1, s2);
198         }
199     }
200
201     public void endDTD() throws SAXException {
202         Iterator JavaDoc iter = m_handlers.iterator();
203         while (iter.hasNext()) {
204             ((LexicalHandler JavaDoc) iter.next()).endDTD();
205         }
206     }
207
208     public void startEntity(String JavaDoc s) throws SAXException {
209         Iterator JavaDoc iter = m_handlers.iterator();
210         while (iter.hasNext()) {
211             ((LexicalHandler JavaDoc) iter.next()).startEntity(s);
212         }
213     }
214
215     public void endEntity(String JavaDoc s) throws SAXException {
216         Iterator JavaDoc iter = m_handlers.iterator();
217         while (iter.hasNext()) {
218             ((LexicalHandler JavaDoc) iter.next()).endEntity(s);
219         }
220     }
221
222     public void startCDATA() throws SAXException {
223         Iterator JavaDoc iter = m_handlers.iterator();
224         while (iter.hasNext()) {
225             ((LexicalHandler JavaDoc) iter.next()).startCDATA();
226         }
227     }
228
229     public void endCDATA() throws SAXException {
230         Iterator JavaDoc iter = m_handlers.iterator();
231         while (iter.hasNext()) {
232             ((LexicalHandler JavaDoc) iter.next()).endCDATA();
233         }
234     }
235
236     public void comment(char[] i_chars, int i, int i1) throws SAXException {
237         Iterator JavaDoc iter = m_handlers.iterator();
238         while (iter.hasNext()) {
239             ((LexicalHandler JavaDoc) iter.next()).comment(i_chars, i, i1);
240         }
241     }
242
243     public void elementDecl(String JavaDoc s, String JavaDoc s1) throws SAXException {
244         Iterator JavaDoc iter = m_handlers.iterator();
245         while (iter.hasNext()) {
246             ((DeclHandler JavaDoc) iter.next()).elementDecl(s, s1);
247         }
248     }
249
250     public void attributeDecl(String JavaDoc s, String JavaDoc s1, String JavaDoc s2, String JavaDoc s3, String JavaDoc s4) throws SAXException {
251         Iterator JavaDoc iter = m_handlers.iterator();
252         while (iter.hasNext()) {
253             ((DeclHandler JavaDoc) iter.next()).attributeDecl(s, s1, s2, s3, s4);
254         }
255     }
256
257     public void internalEntityDecl(String JavaDoc s, String JavaDoc s1) throws SAXException {
258         Iterator JavaDoc iter = m_handlers.iterator();
259         while (iter.hasNext()) {
260             ((DeclHandler JavaDoc) iter.next()).internalEntityDecl(s, s1);
261         }
262     }
263
264     public void externalEntityDecl(String JavaDoc s, String JavaDoc s1, String JavaDoc s2) throws SAXException {
265         Iterator JavaDoc iter = m_handlers.iterator();
266         while (iter.hasNext()) {
267             ((DeclHandler JavaDoc) iter.next()).externalEntityDecl(s, s1, s2);
268         }
269     }
270 }
271
Popular Tags